safesocket: make test use testing.T correctly.

Signed-off-by: David Anderson <dave@natulte.net>
pull/31/head
David Anderson 5 years ago
parent e59605595e
commit 39bc24cb96

@ -10,54 +10,60 @@ import (
) )
func TestBasics(t *testing.T) { func TestBasics(t *testing.T) {
fmt.Printf("listening2...\n")
l, port, err := Listen("COOKIE", "Tailscale", "test", 0) l, port, err := Listen("COOKIE", "Tailscale", "test", 0)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
fmt.Printf("listened.\n")
errs := make(chan error, 2)
go func() { go func() {
fmt.Printf("accepting...\n")
s, err := l.Accept() s, err := l.Accept()
if err != nil { if err != nil {
t.Fatal(err) errs <- err
return
} }
fmt.Printf("accepted.\n")
l.Close() l.Close()
s.Write([]byte("hello")) s.Write([]byte("hello"))
fmt.Printf("server wrote.\n")
b := make([]byte, 1024) b := make([]byte, 1024)
n, err := s.Read(b) n, err := s.Read(b)
if err != nil { if err != nil {
t.Fatal(err) errs <- err
return
} }
fmt.Printf("server read %d bytes.\n", n) fmt.Printf("server read %d bytes.\n", n)
if string(b[:n]) != "world" { 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() s.Close()
errs <- nil
}() }()
fmt.Printf("connecting...\n") go func() {
c, err := Connect("COOKIE", "Tailscale", "test", port) c, err := Connect("COOKIE", "Tailscale", "test", port)
if err != nil { if err != nil {
t.Fatal(err) errs <- err
return
} }
fmt.Printf("connected.\n")
c.Write([]byte("world")) c.Write([]byte("world"))
fmt.Printf("client wrote.\n")
b := make([]byte, 1024) b := make([]byte, 1024)
n, err := c.Read(b) n, err := c.Read(b)
if err != nil { if err != nil {
t.Fatal(err) errs <- err
return
} }
fmt.Printf("client read %d bytes.\n", n)
if string(b[:n]) != "hello" { if string(b[:n]) != "hello" {
t.Fatalf("got %#v, expected %#v\n", string(b[:n]), "hello") errs <- fmt.Errorf("got %#v, expected %#v\n", string(b[:n]), "hello")
} }
c.Close() c.Close()
errs <- nil
}()
for i := 0; i < 2; i++ {
if err := <-errs; err != nil {
t.Fatal(err)
}
}
} }

Loading…
Cancel
Save