Fix some unit tests

This commit is contained in:
Joshua Casey
2024-08-27 13:26:38 -05:00
parent c12402ee49
commit 504f0dc26f
5 changed files with 45 additions and 6 deletions
@@ -2300,11 +2300,12 @@ func TestController(t *testing.T) {
require.NoError(t, err)
}
if !assert.ElementsMatch(t, tt.wantActions(), pinnipedAPIClient.Actions()) {
scrubbedActions := testutil.ScrubListOptionsForActions(t, pinnipedAPIClient.Actions())
if !assert.ElementsMatch(t, tt.wantActions(), scrubbedActions) {
// cmp.Diff is superior to require.ElementsMatch in terms of readability here.
// require.ElementsMatch will handle pointers better than require.Equal, but
// the timestamps are still incredibly verbose.
require.Fail(t, cmp.Diff(tt.wantActions(), pinnipedAPIClient.Actions()), "actions should be exactly the expected number of actions and also contain the correct resources")
require.Fail(t, cmp.Diff(tt.wantActions(), scrubbedActions), "actions should be exactly the expected number of actions and also contain the correct resources")
}
require.Equal(t, len(tt.wantNamesOfJWTAuthenticatorsInCache), len(cache.Keys()), fmt.Sprintf("expected cache entries is incorrect. wanted:%d, got: %d, keys: %v", len(tt.wantNamesOfJWTAuthenticatorsInCache), len(cache.Keys()), cache.Keys()))
@@ -1952,7 +1952,7 @@ func TestController(t *testing.T) {
}
require.NotEmpty(t, tt.wantActions, "wantActions is required for test %s", tt.name)
require.Equal(t, tt.wantActions(), pinnipedAPIClient.Actions())
require.Equal(t, tt.wantActions(), testutil.ScrubListOptionsForActions(t, pinnipedAPIClient.Actions()))
require.Equal(t, len(tt.wantNamesOfWebhookAuthenticatorsInCache), len(cache.Keys()), fmt.Sprintf("expected cache entries is incorrect. wanted:%d, got: %d, keys: %v", len(tt.wantNamesOfWebhookAuthenticatorsInCache), len(cache.Keys()), cache.Keys()))
actualLog, _ := strings.CutSuffix(log.String(), "\n")