From 03ff35d6a0e57caf6ecbc736b80e7b39044779af Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 4 May 2013 13:31:07 -0700 Subject: [PATCH] Server tests --- packer/rpc/server_test.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 packer/rpc/server_test.go diff --git a/packer/rpc/server_test.go b/packer/rpc/server_test.go new file mode 100644 index 000000000..4b65f5bd6 --- /dev/null +++ b/packer/rpc/server_test.go @@ -0,0 +1,39 @@ +package rpc + +import ( + "cgl.tideland.biz/asserts" + "net/rpc" + "testing" +) + +func TestServer_Address_PanicIfNotStarted(t *testing.T) { + assert := asserts.NewTestingAsserts(t, true) + + defer func() { + p := recover() + assert.NotNil(p, "should panic") + assert.Equal(p.(string), "Server not listening.", "right panic") + }() + + NewServer().Address() +} + +func TestServer_Start(t *testing.T) { + assert := asserts.NewTestingAsserts(t, true) + + s := NewServer() + + // Verify it can start + err := s.Start() + assert.Nil(err, "should start without err") + addr := s.Address() + + // Verify we can connect to it! + _, err = rpc.Dial("tcp", addr) + assert.Nil(err, "should be able to connect to RPC") + + // Verify it stops + s.Stop() + _, err = rpc.Dial("tcp", addr) + assert.NotNil(err, "should NOT be able to connect to RPC") +}