test/integration: protect from NPE and follow doc conventions

Signed-off-by: Andrew Keesler <akeesler@vmware.com>
This commit is contained in:
Andrew Keesler 2020-11-02 11:42:46 -05:00
parent 5bbfc35d27
commit fb3c5749e8
No known key found for this signature in database
GPG Key ID: 27CE0444346F9413
2 changed files with 7 additions and 4 deletions

View File

@ -54,6 +54,7 @@ func TestSuccessfulCredentialRequest(t *testing.T) {
return response.Status.Credential != nil return response.Status.Credential != nil
} }
assert.Eventually(t, successfulResponse, 10*time.Second, 500*time.Millisecond) assert.Eventually(t, successfulResponse, 10*time.Second, 500*time.Millisecond)
require.NotNil(t, response)
require.NotNil(t, response.Status.Credential) require.NotNil(t, response.Status.Credential)
require.Empty(t, response.Status.Message) require.Empty(t, response.Status.Message)
require.Empty(t, response.Spec) require.Empty(t, response.Spec)

View File

@ -26,7 +26,7 @@ const (
accessRetryTimeout = 10 * time.Second accessRetryTimeout = 10 * time.Second
) )
// accessAsUserTest runs a generic test in which a clientUnderTest operating with username // AccessAsUserTest runs a generic test in which a clientUnderTest operating with username
// testUsername tries to auth to the kube API (i.e., list namespaces). // testUsername tries to auth to the kube API (i.e., list namespaces).
// //
// Use this function if you want to simply validate that a user can auth to the kube API after // Use this function if you want to simply validate that a user can auth to the kube API after
@ -49,6 +49,7 @@ func AccessAsUserTest(
} }
assert.Eventually(t, canListNamespaces, accessRetryTimeout, accessRetryInterval) assert.Eventually(t, canListNamespaces, accessRetryTimeout, accessRetryInterval)
require.NoError(t, err) // prints out the error and stops the test in case of failure require.NoError(t, err) // prints out the error and stops the test in case of failure
require.NotNil(t, listNamespaceResponse)
require.NotEmpty(t, listNamespaceResponse.Items) require.NotEmpty(t, listNamespaceResponse.Items)
} }
} }
@ -73,11 +74,11 @@ func AccessAsUserWithKubectlTest(
assert.Eventually(t, canListNamespaces, accessRetryTimeout, accessRetryInterval) assert.Eventually(t, canListNamespaces, accessRetryTimeout, accessRetryInterval)
require.NoError(t, err) // prints out the error and stops the test in case of failure require.NoError(t, err) // prints out the error and stops the test in case of failure
require.Contains(t, kubectlCommandOutput, expectedNamespace) require.Containsf(t, kubectlCommandOutput, expectedNamespace, "actual output: %q", kubectlCommandOutput)
} }
} }
// accessAsGroupTest runs a generic test in which a clientUnderTest with membership in group // AccessAsGroupTest runs a generic test in which a clientUnderTest with membership in group
// testGroup tries to auth to the kube API (i.e., list namespaces). // testGroup tries to auth to the kube API (i.e., list namespaces).
// //
// Use this function if you want to simply validate that a user can auth to the kube API (via // Use this function if you want to simply validate that a user can auth to the kube API (via
@ -100,6 +101,7 @@ func AccessAsGroupTest(
} }
assert.Eventually(t, canListNamespaces, accessRetryTimeout, accessRetryInterval) assert.Eventually(t, canListNamespaces, accessRetryTimeout, accessRetryInterval)
require.NoError(t, err) // prints out the error and stops the test in case of failure require.NoError(t, err) // prints out the error and stops the test in case of failure
require.NotNil(t, listNamespaceResponse)
require.NotEmpty(t, listNamespaceResponse.Items) require.NotEmpty(t, listNamespaceResponse.Items)
} }
} }
@ -124,7 +126,7 @@ func AccessAsGroupWithKubectlTest(
assert.Eventually(t, canListNamespaces, accessRetryTimeout, accessRetryInterval) assert.Eventually(t, canListNamespaces, accessRetryTimeout, accessRetryInterval)
require.NoError(t, err) // prints out the error and stops the test in case of failure require.NoError(t, err) // prints out the error and stops the test in case of failure
require.Contains(t, kubectlCommandOutput, expectedNamespace) require.Containsf(t, kubectlCommandOutput, expectedNamespace, "actual output: %q", kubectlCommandOutput)
} }
} }