From e8b4f7fc7614ddbf44e6ef8e72f33d86cba345a7 Mon Sep 17 00:00:00 2001 From: Justin Chadwell Date: Tue, 22 Nov 2022 17:56:46 +0000 Subject: [PATCH] test: fix flaky duplicate cache test Return args order is not guaranteed (since we use a map internally), so we need to make sure the test does not rely on order of returns. Signed-off-by: Justin Chadwell --- control/control_test.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/control/control_test.go b/control/control_test.go index 9955ca549..1c5f499b6 100644 --- a/control/control_test.go +++ b/control/control_test.go @@ -11,7 +11,7 @@ func TestDuplicateCacheOptions(t *testing.T) { var testCases = []struct { name string opts []*controlapi.CacheOptionsEntry - expected []uint + expected []*controlapi.CacheOptionsEntry }{ { name: "avoids unique opts", @@ -59,17 +59,28 @@ func TestDuplicateCacheOptions(t *testing.T) { }, }, }, - expected: []uint{0, 2}, + expected: []*controlapi.CacheOptionsEntry{ + { + Type: "registry", + Attrs: map[string]string{ + "ref": "example.com/ref:v1.0.0", + }, + }, + { + Type: "local", + Attrs: map[string]string{ + "dest": "/path/for/export", + }, + }, + }, }, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - p, err := findDuplicateCacheOptions(tc.opts) + result, err := findDuplicateCacheOptions(tc.opts) require.NoError(t, err) - for i, j := range tc.expected { - require.Equal(t, p[i], tc.opts[j]) - } + require.ElementsMatch(t, tc.expected, result) }) } }