Skip to content

Commit

Permalink
Add extra test for weave client.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwilkie committed Feb 5, 2016
1 parent b758d56 commit 394d3d0
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions common/weave/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,47 @@ func TestPS(t *testing.T) {
t.Fatal(test.Diff(entries, want))
}
}

func TestExpose(t *testing.T) {
oldExecCmd := exec.Command
defer func() { exec.Command = oldExecCmd }()

psCalled := false
exec.Command = func(name string, args ...string) exec.Cmd {
if args[0] == "expose" {
t.Fatal("Expose not expected")
return nil
} else {
psCalled = true
return testExec.NewMockCmdString(fmt.Sprintf("%s %s %s/24\n", mockContainerID, mockContainerMAC, mockContainerIP))
}
}

client := weave.NewClient("")
if err := client.Expose(); err != nil {
t.Fatal(err)
}

if !psCalled {
t.Fatal("Expected a call to weave ps")
}

psCalled, exposeCalled := false, false
exec.Command = func(name string, args ...string) exec.Cmd {
if args[0] == "expose" {
exposeCalled = true
return testExec.NewMockCmdString("")
} else {
psCalled = true
return testExec.NewMockCmdString("")
}
}

if err := client.Expose(); err != nil {
t.Fatal(err)
}

if !psCalled || !exposeCalled {
t.Fatal("Expected a call to weave ps & expose")
}
}

0 comments on commit 394d3d0

Please sign in to comment.