Skip to content

Commit

Permalink
Prevent panic in tests whose queries fail
Browse files Browse the repository at this point in the history
Some tests were ignoring errors and proceeding to inspect query
results, causing failure via panic. Instead, fail these tests via more
explicit assertions.
  • Loading branch information
seh committed Jan 26, 2017
1 parent 6e72b26 commit f1f7c88
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions tests/net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ func TestConnectionCreation(t *testing.T) {
e := fargo.NewConnFromConfig(cfg)
apps, err := e.GetApps()
So(err, ShouldBeNil)
So(len(apps["EUREKA"].Instances), ShouldEqual, 2)
app := apps["EUREKA"]
So(app, ShouldNotBeNil)
So(len(app.Instances), ShouldEqual, 2)
})
}

Expand All @@ -101,15 +103,18 @@ func TestGetApps(t *testing.T) {
for _, j := range []bool{false, true} {
e.UseJson = j
Convey("Pull applications", t, func() {
a, err := e.GetApps()
apps, err := e.GetApps()
So(err, ShouldBeNil)
So(len(a["EUREKA"].Instances), ShouldEqual, 2)
app := apps["EUREKA"]
So(app, ShouldNotBeNil)
So(len(app.Instances), ShouldEqual, 2)
})
Convey("Pull single application", t, func() {
a, err := e.GetApp("EUREKA")
app, err := e.GetApp("EUREKA")
So(err, ShouldBeNil)
So(len(a.Instances), ShouldEqual, 2)
for _, ins := range a.Instances {
So(app, ShouldNotBeNil)
So(len(app.Instances), ShouldEqual, 2)
for _, ins := range app.Instances {
So(ins.IPAddr, ShouldBeIn, []string{"172.17.0.2", "172.17.0.3"})
}
})
Expand Down Expand Up @@ -165,7 +170,7 @@ func TestGetSingleInstanceByVIPAddress(t *testing.T) {
So(instances, ShouldHaveLength, 1)
Convey("And selecting instances with status UP should provide none", func() {
// Ensure that we tolerate a nil option safely.
instances, err := e.GetInstancesByVIPAddress(vipAddress, fargo.ThatAreUp, nil)
instances, err := e.GetInstancesByVIPAddress(vipAddress, false, fargo.ThatAreUp, nil)
So(err, ShouldBeNil)
So(instances, ShouldBeEmpty)
})
Expand Down Expand Up @@ -199,7 +204,7 @@ func TestGetMultipleInstancesByVIPAddress(t *testing.T) {
Convey("requesting the instances by that VIP address should provide them", func() {
time.Sleep(cacheDelay)
vipAddress := "app"
instances, err := e.GetInstancesByVIPAddress(vipAddress)
instances, err := e.GetInstancesByVIPAddress(vipAddress, false)
So(err, ShouldBeNil)
So(instances, ShouldHaveLength, 2)
for _, ins := range instances {
Expand Down

0 comments on commit f1f7c88

Please sign in to comment.