From a8a0c2c1d95e743d344b3d95a6eda82fd0b1e62e Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Wed, 9 Nov 2022 14:06:17 -0500 Subject: [PATCH] Fix test flake in loader by sorting the expected tuples --- pkg/validationfile/loader_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/validationfile/loader_test.go b/pkg/validationfile/loader_test.go index f2b043c67f..4744e00bc6 100644 --- a/pkg/validationfile/loader_test.go +++ b/pkg/validationfile/loader_test.go @@ -1,6 +1,8 @@ package validationfile import ( + "sort" + "strings" "testing" core "github.com/authzed/spicedb/pkg/proto/core/v1" @@ -57,7 +59,19 @@ func TestPopulateFromFiles(t *testing.T) { parsed, _, err := PopulateFromFiles(ds, tt.filePaths) require.NoError(err) + + sort.Sort(sortByTuple(tt.want)) + sort.Sort(sortByTuple(parsed.Tuples)) + require.Equal(tt.want, parsed.Tuples) }) } } + +type sortByTuple []*core.RelationTuple + +func (a sortByTuple) Len() int { return len(a) } +func (a sortByTuple) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a sortByTuple) Less(i, j int) bool { + return strings.Compare(tuple.String(a[i]), tuple.String(a[j])) < 0 +}