mirror of
https://github.com/tailscale/tailscale.git
synced 2024-12-01 14:05:39 +00:00
safesocket: make test use testing.T correctly.
Signed-off-by: David Anderson <dave@natulte.net>
This commit is contained in:
parent
e59605595e
commit
39bc24cb96
@ -10,54 +10,60 @@
|
||||
)
|
||||
|
||||
func TestBasics(t *testing.T) {
|
||||
fmt.Printf("listening2...\n")
|
||||
l, port, err := Listen("COOKIE", "Tailscale", "test", 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fmt.Printf("listened.\n")
|
||||
|
||||
errs := make(chan error, 2)
|
||||
|
||||
go func() {
|
||||
fmt.Printf("accepting...\n")
|
||||
s, err := l.Accept()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
errs <- err
|
||||
return
|
||||
}
|
||||
fmt.Printf("accepted.\n")
|
||||
l.Close()
|
||||
s.Write([]byte("hello"))
|
||||
fmt.Printf("server wrote.\n")
|
||||
|
||||
b := make([]byte, 1024)
|
||||
n, err := s.Read(b)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
errs <- err
|
||||
return
|
||||
}
|
||||
fmt.Printf("server read %d bytes.\n", n)
|
||||
if string(b[:n]) != "world" {
|
||||
t.Fatalf("got %#v, expected %#v\n", string(b[:n]), "world")
|
||||
errs <- fmt.Errorf("got %#v, expected %#v\n", string(b[:n]), "world")
|
||||
return
|
||||
}
|
||||
s.Close()
|
||||
errs <- nil
|
||||
}()
|
||||
|
||||
fmt.Printf("connecting...\n")
|
||||
go func() {
|
||||
c, err := Connect("COOKIE", "Tailscale", "test", port)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
errs <- err
|
||||
return
|
||||
}
|
||||
fmt.Printf("connected.\n")
|
||||
c.Write([]byte("world"))
|
||||
fmt.Printf("client wrote.\n")
|
||||
|
||||
b := make([]byte, 1024)
|
||||
n, err := c.Read(b)
|
||||
if err != nil {
|
||||
errs <- err
|
||||
return
|
||||
}
|
||||
if string(b[:n]) != "hello" {
|
||||
errs <- fmt.Errorf("got %#v, expected %#v\n", string(b[:n]), "hello")
|
||||
}
|
||||
c.Close()
|
||||
errs <- nil
|
||||
}()
|
||||
|
||||
for i := 0; i < 2; i++ {
|
||||
if err := <-errs; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fmt.Printf("client read %d bytes.\n", n)
|
||||
if string(b[:n]) != "hello" {
|
||||
t.Fatalf("got %#v, expected %#v\n", string(b[:n]), "hello")
|
||||
}
|
||||
|
||||
c.Close()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user