From fb94b6fe1a3d60950d19f1e9c1f4bf2589243b65 Mon Sep 17 00:00:00 2001 From: willdavsmith Date: Wed, 13 Sep 2023 11:30:56 -0700 Subject: [PATCH] Fixing test --- test/validation/aws.go | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/test/validation/aws.go b/test/validation/aws.go index fb731db981..fcf2cd5442 100644 --- a/test/validation/aws.go +++ b/test/validation/aws.go @@ -191,7 +191,37 @@ func assertFieldsArePresent(t *testing.T, actual any, expected any) { } else { require.Fail(t, "types of actual and expected do not match") } + case []any: + // Check if the actual slice contains all elements of the expected slice + // This is necessary because there may be a creation timestamp in the actual slice that + // is not present in the expected slice + require.True(t, subslice(actual, expected.([]any))) default: - require.Equal(t, actual, expected) + require.Equal(t, expected, actual) } } + +// contains checks if the given slice contains the given element +func contains[T comparable](s []T, e T) bool { + for _, a := range s { + if a == e { + return true + } + } + + return false +} + +// subslice checks if s1 is a subslice of s2 +func subslice[T comparable](s1 []T, s2 []T) bool { + if len(s1) > len(s2) { + return false + } + for _, e := range s1 { + if !contains(s2, e) { + return false + } + } + + return true +}