Skip to content

Commit

Permalink
ignore order of excluded checks in http body response
Browse files Browse the repository at this point in the history
  • Loading branch information
ajatprabha committed Aug 7, 2023
1 parent 4828029 commit 01acda7
Showing 1 changed file with 33 additions and 15 deletions.
48 changes: 33 additions & 15 deletions xpod/probe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"net/http"
"net/http/httptest"
"regexp"
"strings"
"testing"

Expand All @@ -21,18 +22,22 @@ func TestProbeHandler_serveHealth(t *testing.T) {
verbose bool
excluded []string
logDelegate func(*testing.T, *mock.Mock)
want string
want func(*testing.T, string)
}{
{
name: "NoHealthCheckNonVerbose",
want: "ok",
want: func(t *testing.T, got string) {
assert.Equal(t, "ok", got)
},
},
{
name: "NoHealthCheckVerbose",
verbose: true,
want: `[+]ping ok
want: func(t *testing.T, got string) {
assert.Equal(t, `[+]ping ok
healthz check passed
`,
`, got)
},
},
{
name: "FailingHealthCheckWithHiddenReason",
Expand All @@ -51,8 +56,10 @@ healthz check passed
assert.Equal(t, "redis", argsMap["failed_checks"])
})
},
want: `[-]redis failed: reason hidden
`,
want: func(t *testing.T, got string) {
assert.Equal(t, `[-]redis failed: reason hidden
`, got)
},
},
{
name: "FailingHealthCheckWithReason",
Expand All @@ -64,9 +71,11 @@ healthz check passed
},
ShowErrReasons: true,
},
want: `[-]redis failed:
want: func(t *testing.T, got string) {
assert.Equal(t, `[-]redis failed:
reason: redis-connect-error
`,
`, got)
},
},
{
name: "FailingHealthCheckExcluded",
Expand All @@ -79,7 +88,7 @@ healthz check passed
},
},
excluded: []string{"redis"},
want: "ok",
want: func(t *testing.T, got string) { assert.Equal(t, "ok", got) },
},
{
name: "FailingHealthCheckWithExtraExcludes",
Expand All @@ -106,11 +115,20 @@ healthz check passed
assert.Equal(t, "no matches", argsMap["reason"])
})
},
want: `[+]ping ok
[+]redis excluded: ok
warn: some health checks cannot be excluded: no matches for "foo", "bar", "baz"
healthz check passed
`,
want: func(t *testing.T, got string) {
assert.True(t, strings.Contains(got, `[+]ping ok`))
assert.True(t, strings.Contains(got, `[+]redis excluded: ok`))

re := regexp.MustCompile(`warn: some health checks cannot be excluded: no matches for (.*)`)
assert.True(t, re.MatchString(got))

excludedLine := re.FindStringSubmatch(got)[1]
assert.ElementsMatch(t, []string{"foo", "bar", "baz"}, slice.Map(
strings.Split(excludedLine, ", "), func(s string) string {
return strings.Trim(s, `"`)
},
))
},
},
}

Expand Down Expand Up @@ -146,7 +164,7 @@ healthz check passed
assert.NoError(t, err)
assert.NoError(t, rc.Close())

assert.Equal(t, tt.want, string(b))
tt.want(t, string(b))

ld.AssertExpectations(t)
})
Expand Down

0 comments on commit 01acda7

Please sign in to comment.