Merge pull request #534 from mattmoyer/deflake-categories-test-rate-limiting

Deflake TestGetPinnipedCategory.
This commit is contained in:
Matt Moyer 2021-03-30 13:46:55 -07:00 committed by GitHub
commit d4baeff94e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -55,6 +55,21 @@ func runTestKubectlCommand(t *testing.T, args ...string) (string, string) {
} }
return stdOut.String(), stdErr.String() return stdOut.String(), stdErr.String()
} }
func requireCleanKubectlStderr(t *testing.T, stderr string) {
// Every line must be empty or contain a known, innocuous warning.
for _, line := range strings.Split(stderr, "\n") {
if strings.TrimSpace(line) == "" {
continue
}
if strings.Contains(line, "Throttling request took") {
continue
}
require.Failf(t, "unexpected kubectl stderr", "kubectl produced unexpected stderr output:\n%s\n\n", stderr)
return
}
}
func TestGetPinnipedCategory(t *testing.T) { func TestGetPinnipedCategory(t *testing.T) {
env := library.IntegrationEnv(t) env := library.IntegrationEnv(t)
dotSuffix := "." + env.APIGroupSuffix dotSuffix := "." + env.APIGroupSuffix
@ -62,7 +77,7 @@ func TestGetPinnipedCategory(t *testing.T) {
t.Run("category, no special params", func(t *testing.T) { t.Run("category, no special params", func(t *testing.T) {
t.Parallel() t.Parallel()
stdout, stderr := runTestKubectlCommand(t, "get", "pinniped", "-A") stdout, stderr := runTestKubectlCommand(t, "get", "pinniped", "-A")
require.Empty(t, stderr) requireCleanKubectlStderr(t, stderr)
require.NotContains(t, stdout, "MethodNotAllowed") require.NotContains(t, stdout, "MethodNotAllowed")
require.Contains(t, stdout, dotSuffix) require.Contains(t, stdout, dotSuffix)
}) })
@ -101,7 +116,7 @@ func TestGetPinnipedCategory(t *testing.T) {
require.NotContains(t, stdout, "MethodNotAllowed") require.NotContains(t, stdout, "MethodNotAllowed")
require.Contains(t, stdout, `{"kind":"TokenCredentialRequestList","apiVersion":"login.concierge`+ require.Contains(t, stdout, `{"kind":"TokenCredentialRequestList","apiVersion":"login.concierge`+
dotSuffix+`/v1alpha1","metadata":{"resourceVersion":"0"},"items":[]}`) dotSuffix+`/v1alpha1","metadata":{"resourceVersion":"0"},"items":[]}`)
require.Empty(t, stderr) requireCleanKubectlStderr(t, stderr)
}) })
t.Run("raw request to see body, whoami", func(t *testing.T) { t.Run("raw request to see body, whoami", func(t *testing.T) {
@ -110,6 +125,6 @@ func TestGetPinnipedCategory(t *testing.T) {
require.NotContains(t, stdout, "MethodNotAllowed") require.NotContains(t, stdout, "MethodNotAllowed")
require.Contains(t, stdout, `{"kind":"WhoAmIRequestList","apiVersion":"identity.concierge`+ require.Contains(t, stdout, `{"kind":"WhoAmIRequestList","apiVersion":"identity.concierge`+
dotSuffix+`/v1alpha1","metadata":{"resourceVersion":"0"},"items":[]}`) dotSuffix+`/v1alpha1","metadata":{"resourceVersion":"0"},"items":[]}`)
require.Empty(t, stderr) requireCleanKubectlStderr(t, stderr)
}) })
} }