diff options
-rw-r--r-- | cmd_pid_test.go | 25 | ||||
-rw-r--r-- | cmd_ping_test.go | 23 | ||||
-rw-r--r-- | goctl_test.go | 20 |
3 files changed, 48 insertions, 20 deletions
diff --git a/cmd_pid_test.go b/cmd_pid_test.go new file mode 100644 index 0000000..681b116 --- /dev/null +++ b/cmd_pid_test.go @@ -0,0 +1,25 @@ +package goctl + +import ( + "strconv" + "testing" +) + +func TestPID(t *testing.T) { + gc := start(t) + defer gc.Stop() + + c := dial(t) + defer c.Close() + + buf := []byte("pid") + Write(c, buf) + + buf, err := Read(c) + if err != nil { + t.Fatalf("Couldn't read from socket: %s.", err) + } + if _, err = strconv.Atoi(string(buf)); err != nil { + t.Errorf("Requesting PID: got non-integer: '%s'.", string(buf)) + } +} diff --git a/cmd_ping_test.go b/cmd_ping_test.go new file mode 100644 index 0000000..89a08c7 --- /dev/null +++ b/cmd_ping_test.go @@ -0,0 +1,23 @@ +package goctl + +import "testing" + +func TestPing(t *testing.T) { + gc := start(t) + defer gc.Stop() + + c := dial(t) + defer c.Close() + + buf := []byte("ping") + Write(c, buf) + + buf, err := Read(c) + if err != nil { + t.Fatalf("Couldn't read from socket: %s.", err) + } + s := string(buf) + if s != "pong" { + t.Errorf("Sending ping: got '%s', expected 'pong'.", s) + } +} diff --git a/goctl_test.go b/goctl_test.go index 7e30f7e..dce75e7 100644 --- a/goctl_test.go +++ b/goctl_test.go @@ -55,26 +55,6 @@ func dial(t testing.TB) net.Conn { return c } -func TestPing(t *testing.T) { - gc := start(t) - defer gc.Stop() - - c := dial(t) - defer c.Close() - - buf := []byte("ping") - Write(c, buf) - - buf, err := Read(c) - if err != nil { - t.Fatalf("Couldn't read from socket: %s.", err) - } - s := string(buf) - if s != "pong" { - t.Errorf("Sending ping: got '%s', expected 'pong'.", s) - } -} - func TestAlreadyRunning(t *testing.T) { gc := start(t) defer gc.Stop() |