Skip to content

Commit

Permalink
test(daemon): working daemon tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Jun 4, 2016
1 parent 24e7c9b commit 3f764a6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
3 changes: 0 additions & 3 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ func (d *Daemon) ListServers(request interface{}, reply *PactListResponse) error
var servers []*PactMockServer

for port, s := range d.pactMockSvcManager.List() {
fmt.Println("Listing!")
servers = append(servers, &PactMockServer{
Pid: s.Process.Pid,
Port: port,
Expand All @@ -133,8 +132,6 @@ func (d *Daemon) ListServers(request interface{}, reply *PactListResponse) error
Servers: servers,
}

fmt.Println(reply)

return nil
}

Expand Down
50 changes: 33 additions & 17 deletions daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ func fakeExecCommand(command string, success bool, args ...string) *exec.Cmd {
}

func TestHelperProcess(t *testing.T) {
fmt.Fprintln(os.Stdout, "HELLLlloooo")
<-time.After(30 * time.Second)
if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" {
return
}
<-time.After(30 * time.Second)

// some code here to check arguments perhaps?
// Fail :(
Expand Down Expand Up @@ -68,7 +67,7 @@ func TestNewDaemon(t *testing.T) {
var daemon interface{}
daemon, _ = createMockedDaemon()

if _, ok := daemon.(Daemon); !ok {
if _, ok := daemon.(*Daemon); !ok {
t.Fatalf("must be a Daemon")
}
}
Expand Down Expand Up @@ -135,16 +134,23 @@ func TestListServers(t *testing.T) {
}

func TestStopServer(t *testing.T) {
daemon := &Daemon{}
daemon, manager := createMockedDaemon()
var cmd *exec.Cmd
var res PactMockServer

req := PactMockServer{Pid: 1234}
res := PactMockServer{}
err := daemon.StopServer(&req, &res)
for _, s := range manager.List() {
cmd = s
}
request := PactMockServer{
Pid: cmd.Process.Pid,
}

err := daemon.StopServer(&request, &res)
if err != nil {
t.Fatalf("Error: %v", err)
}

if res.Pid != 0 {
if res.Pid != cmd.Process.Pid {
t.Fatalf("Expected PID to be 0 but got: %d", res.Pid)
}

Expand All @@ -153,23 +159,33 @@ func TestStopServer(t *testing.T) {
}
}

func TestStartServer_Fail(t *testing.T) {

}
func TestPublish(t *testing.T) {
daemon := &Daemon{}
req := PublishRequest{}
var res PactResponse
err := daemon.Publish(&req, &res)
if err != nil {
t.Fatalf("Error: %v", err)
}

func TestVerification(t *testing.T) {
if res.ExitCode != 0 {
t.Fatalf("Expected exit code to be 0 but got: %d", res.ExitCode)
}

if res.Message != "Success" {
t.Fatalf("Expected message to be 'Success' but got: %s", res.Message)
}
}

func TestVerification_Fail(t *testing.T) {
func TestPublish_Fail(t *testing.T) {

}

func TestPublish(t *testing.T) {
func TestVerification(t *testing.T) {
daemon := &Daemon{}
req := PublishRequest{}
req := VerifyRequest{}
var res PactResponse
err := daemon.Publish(&req, &res)
err := daemon.Verify(&req, &res)
if err != nil {
t.Fatalf("Error: %v", err)
}
Expand All @@ -183,7 +199,7 @@ func TestPublish(t *testing.T) {
}
}

func TestPublish_Fail(t *testing.T) {
func TestVerification_Fail(t *testing.T) {

}

Expand Down

0 comments on commit 3f764a6

Please sign in to comment.