diff --git a/auth_test.go b/auth_test.go index d4cf083..6da1b7c 100644 --- a/auth_test.go +++ b/auth_test.go @@ -43,8 +43,15 @@ func TestAuthIPAllow(t *testing.T) { t.Error(err) } - client.SendFrame([]byte("Hello"), 1) - client.SendFrame([]byte("World"), 0) + err = client.SendFrame([]byte("Hello"), 1) + if err != nil { + t.Error(err) + } + + err = client.SendFrame([]byte("World"), 0) + if err != nil { + t.Error(err) + } poller, err := NewPoller(server) if err != nil { @@ -78,13 +85,27 @@ func TestAuthPlain(t *testing.T) { } defer func() { - os.Remove("./password_test.txt") + err = os.Remove("./password_test.txt") + if err != nil { + t.Error(err) + } }() w := bufio.NewWriter(pwfile) - w.Write([]byte("admin=Password\n")) - w.Flush() - pwfile.Close() + _, err = w.Write([]byte("admin=Password\n")) + if err != nil { + t.Error(err) + } + + err = w.Flush() + if err != nil { + t.Error(err) + } + + err = pwfile.Close() + if err != nil { + t.Error(err) + } auth := NewAuth() defer auth.Destroy() @@ -125,8 +146,15 @@ func TestAuthPlain(t *testing.T) { t.Error(err) } - goodClient.SendFrame([]byte("Hello"), 1) - goodClient.SendFrame([]byte("World"), 0) + err = goodClient.SendFrame([]byte("Hello"), 1) + if err != nil { + t.Error(err) + } + + err = goodClient.SendFrame([]byte("World"), 0) + if err != nil { + t.Error(err) + } poller, err := NewPoller(server) if err != nil { @@ -157,8 +185,15 @@ func TestAuthPlain(t *testing.T) { t.Error(err) } - badClient.SendFrame([]byte("Hello"), 1) - badClient.SendFrame([]byte("World"), 0) + err = badClient.SendFrame([]byte("Hello"), 1) + if err != nil { + t.Error(err) + } + + err = badClient.SendFrame([]byte("World"), 0) + if err != nil { + t.Error(err) + } s = poller.Wait(200) if s != nil { @@ -203,7 +238,10 @@ func TestAuthCurveAllowAny(t *testing.T) { badClient := NewSock(Push) defer badClient.Destroy() - auth.Curve(CurveAllowAny) + err = auth.Curve(CurveAllowAny) + if err != nil { + t.Error(err) + } port, err := server.Bind("tcp://127.0.0.1:*") if err != nil { @@ -220,8 +258,15 @@ func TestAuthCurveAllowAny(t *testing.T) { t.Error(err) } - goodClient.SendFrame([]byte("Hello"), 1) - goodClient.SendFrame([]byte("World"), 0) + err = goodClient.SendFrame([]byte("Hello"), 1) + if err != nil { + t.Error(err) + } + + err = goodClient.SendFrame([]byte("World"), 0) + if err != nil { + t.Error(err) + } poller, err := NewPoller(server) if err != nil { @@ -247,8 +292,15 @@ func TestAuthCurveAllowAny(t *testing.T) { t.Errorf("want %#v, have %#v", want, have) } - badClient.SendFrame([]byte("Hello"), 1) - badClient.SendFrame([]byte("Bad World"), 0) + err = badClient.SendFrame([]byte("Hello"), 1) + if err != nil { + t.Error(err) + } + + err = badClient.SendFrame([]byte("Bad World"), 0) + if err != nil { + t.Error(err) + } s = poller.Wait(200) if s != nil { @@ -287,7 +339,10 @@ func TestAuthCurveAllowCertificate(t *testing.T) { goodClientCert.Apply(goodClient) certfile := path.Join("testauth", "goodClient.txt") - goodClientCert.SavePublic(certfile) + err = goodClientCert.SavePublic(certfile) + if err != nil { + t.Error(err) + } badClient := NewSock(Push, SockSetCurveServerkey(serverKey)) defer badClient.Destroy() @@ -315,7 +370,10 @@ func TestAuthCurveAllowCertificate(t *testing.T) { t.Error(err) } - goodClient.SendFrame([]byte("Hello, Good World!"), 0) + err = goodClient.SendFrame([]byte("Hello, Good World!"), 0) + if err != nil { + t.Error(err) + } poller, err := NewPoller(server) if err != nil { @@ -337,14 +395,20 @@ func TestAuthCurveAllowCertificate(t *testing.T) { t.Errorf("want '%#v', have '%#v'", want, have) } - badClient.SendFrame([]byte("Hello, Bad World"), 0) + err = badClient.SendFrame([]byte("Hello, Bad World"), 0) + if err != nil { + t.Error(err) + } s = poller.Wait(200) if s != nil { t.Errorf("want '%#v', have '%#v", nil, s) } - os.RemoveAll(testpath) + err = os.RemoveAll(testpath) + if err != nil { + t.Error(err) + } } func ExampleAuth() { @@ -355,15 +419,29 @@ func ExampleAuth() { // create a client certificate and save it clientCert := NewCert() defer clientCert.Destroy() - clientCert.SavePublic("client_cert") - defer func() { os.Remove("client_cert") }() + err := clientCert.SavePublic("client_cert") + if err != nil { + panic(err) + } + + defer func() { + err := os.Remove("client_cert") + if err != nil { + if err != nil { + panic(err) + } + } + }() // create an auth service auth := NewAuth() defer auth.Destroy() // tell the auth service the client cert is allowed - auth.Curve("client_cert") + err = auth.Curve("client_cert") + if err != nil { + panic(err) + } // create a server socket and set it to // use the "global" auth domain @@ -377,7 +455,10 @@ func ExampleAuth() { server.SetOption(SockSetCurveServer(1)) // bind our server to an endpoint - server.Bind("tcp://*:9898") + _, err = server.Bind("tcp://*:9898") + if err != nil { + panic(err) + } // create a client socket client := NewSock(Pull) @@ -393,5 +474,8 @@ func ExampleAuth() { client.SetOption(SockSetCurveServerkey(serverCert.PublicText())) // connect - client.Connect("tcp://127.0.0.1:9898") + err = client.Connect("tcp://127.0.0.1:9898") + if err != nil { + panic(err) + } } diff --git a/beacon_test.go b/beacon_test.go index 168cd41..cd3696f 100644 --- a/beacon_test.go +++ b/beacon_test.go @@ -41,7 +41,10 @@ func TestBeacon(t *testing.T) { t.Error(err) } - speaker.Publish("HI", 100) + err = speaker.Publish("HI", 100) + if err != nil { + t.Error(err) + } msg := listener.Recv(500) if len(msg) == 2 { @@ -61,6 +64,11 @@ func ExampleBeacon() { if err != nil { panic(err) } + fmt.Printf("started beacon on: %s", address) - beacon.Publish("HI", 100) + + err = beacon.Publish("HI", 100) + if err != nil { + panic(err) + } } diff --git a/cert_test.go b/cert_test.go index a78b7c6..d12a4d9 100644 --- a/cert_test.go +++ b/cert_test.go @@ -46,7 +46,11 @@ func TestCert(t *testing.T) { cert.Print() } - cert.Save("./test_cert") + err := cert.Save("./test_cert") + if err != nil { + t.Error(err) + } + loaded, err := NewCertFromFile("./test_cert") if err != nil { t.Error(err) @@ -61,8 +65,15 @@ func TestCert(t *testing.T) { loaded.Print() } - os.Remove("./test_cert") - os.Remove("./test_cert_secret") + err = os.Remove("./test_cert") + if err != nil { + t.Error(err) + } + + err = os.Remove("./test_cert_secret") + if err != nil { + t.Error(err) + } } func TestNewCertFromFile(t *testing.T) { diff --git a/certstore_test.go b/certstore_test.go index 460b879..82760d8 100644 --- a/certstore_test.go +++ b/certstore_test.go @@ -7,7 +7,10 @@ import ( func TestCertStore(t *testing.T) { testDir := ".test_zcertstore" - os.Mkdir(testDir, 0777) + err := os.Mkdir(testDir, 0777) + if err != nil { + t.Error(err) + } certstore := NewCertStore(testDir) defer certstore.Destroy() @@ -24,7 +27,12 @@ func TestCertStore(t *testing.T) { client1 := NewCert() client1.SetMeta("name", "Brian") client1Key := client1.PublicText() - client1.Save(testDir + "/mycert.txt") + + err = client1.Save(testDir + "/mycert.txt") + if err != nil { + t.Error(err) + } + client1.Destroy() client1Loaded := certstore.Lookup(client1Key) @@ -52,7 +60,7 @@ func TestCertStore(t *testing.T) { t.Errorf("want %#v, have %#v", want, have) } - err := os.RemoveAll(testDir) + err = os.RemoveAll(testDir) if err != nil { t.Fatal(err) } diff --git a/proxy_test.go b/proxy_test.go index 923ee27..1b85ae4 100644 --- a/proxy_test.go +++ b/proxy_test.go @@ -57,8 +57,15 @@ func TestProxy(t *testing.T) { defer tap.Destroy() // send some messages and check they arrived - faucet.SendFrame([]byte("Hello"), FlagNone) - faucet.SendFrame([]byte("World"), FlagNone) + err = faucet.SendFrame([]byte("Hello"), FlagNone) + if err != nil { + t.Error(err) + } + + err = faucet.SendFrame([]byte("World"), FlagNone) + if err != nil { + t.Error(err) + } // check the tap b, f, err := tap.RecvFrame() @@ -118,7 +125,10 @@ func TestProxy(t *testing.T) { t.Error(err) } - faucet.SendFrame([]byte("Belated Hello"), FlagNone) + err = faucet.SendFrame([]byte("Belated Hello"), FlagNone) + if err != nil { + t.Error(err) + } if want, have := false, sink.Pollin(); want != have { t.Errorf("want %#v, have %#v", want, have) diff --git a/sock_test.go b/sock_test.go index 5206191..86b287a 100644 --- a/sock_test.go +++ b/sock_test.go @@ -116,7 +116,11 @@ func TestSendMessage(t *testing.T) { t.Error(err) } - pushSock.SendMessage([][]byte{[]byte("Hello")}) + err = pushSock.SendMessage([][]byte{[]byte("Hello")}) + if err != nil { + t.Error(err) + } + msg, err := pullSock.RecvMessage() if err != nil { t.Error(err) @@ -131,7 +135,11 @@ func TestSendMessage(t *testing.T) { t.Error(err) } - pushSock.SendMessage([][]byte{[]byte("World")}) + err = pushSock.SendMessage([][]byte{[]byte("World")}) + if err != nil { + t.Error(err) + } + msg, err = pullSock.RecvMessageNoWait() if err != nil { t.Error(err) @@ -894,7 +902,10 @@ func ExampleSock_output() { defer router.Destroy() // send hello message - dealer.SendFrame([]byte("Hello"), FlagNone) + err = dealer.SendFrame([]byte("Hello"), FlagNone) + if err != nil { + panic(err) + } // receive hello message request, err := router.RecvMessage()