Skip to content

Commit

Permalink
Refactor URLS/hosts test
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewvc committed May 6, 2020
1 parent 76a24d7 commit de89675
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions heartbeat/monitors/active/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,22 +237,31 @@ var downStatuses = []int{
}

func TestUpStatuses(t *testing.T) {
for _, status := range upStatuses {
status := status
t.Run(fmt.Sprintf("Test OK HTTP status %d", status), func(t *testing.T) {
server, event := checkServer(t, hbtest.HelloWorldHandler(status), false)
for _, useURLs := range []bool{true, false} {
for _, status := range upStatuses {
status := status

testslike.Test(
t,
lookslike.Strict(lookslike.Compose(
hbtest.BaseChecks("127.0.0.1", "up", "http"),
hbtest.RespondingTCPChecks(),
hbtest.SummaryChecks(1, 0),
respondingHTTPChecks(server.URL, status),
)),
event.Fields,
)
})
field := "hosts"
if useURLs {
field = "urls"
}

testName := fmt.Sprintf("Test OK HTTP status %d using %s config field", status, field)
t.Run(testName, func(t *testing.T) {
server, event := checkServer(t, hbtest.HelloWorldHandler(status), useURLs)

testslike.Test(
t,
lookslike.Strict(lookslike.Compose(
hbtest.BaseChecks("127.0.0.1", "up", "http"),
hbtest.RespondingTCPChecks(),
hbtest.SummaryChecks(1, 0),
respondingHTTPChecks(server.URL, status),
)),
event.Fields,
)
})
}
}
}

Expand Down

0 comments on commit de89675

Please sign in to comment.