From d31c8e7f3a8a13987f1f5517f6f1feeeab03ab49 Mon Sep 17 00:00:00 2001 From: Tate Exon Date: Wed, 31 Jul 2024 14:37:17 -0600 Subject: [PATCH] fix flaky test --- main_test.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/main_test.go b/main_test.go index 0e45924..b3e089f 100644 --- a/main_test.go +++ b/main_test.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "testing" "github.com/stretchr/testify/require" @@ -9,6 +10,13 @@ import ( "github.com/tateexon/go-change-delta/utils" ) +func verifySliceItemsPresent(t *testing.T, expected, actual []string) { + require.Equal(t, len(expected), len(actual), fmt.Sprintf("Expected: %+v\nActual: %+v\n", expected, actual)) + for _, item := range expected { + require.Contains(t, actual, item) + } +} + func TestSetConfig(t *testing.T) { config := setConfig(utils.Ptr("main"), utils.Ptr("abc"), utils.Ptr("abc,123"), utils.Ptr(1), utils.Ptr(true)) require.NotNil(t, config) @@ -81,8 +89,10 @@ func TestFindAllAffectedPackages(t *testing.T) { pkgs := findAllAffectedPackages(config, changedPackages, changedModPackages, depMap) require.Equal(t, 2, len(pkgs)) - require.Equal(t, "github.com/tateexon/go-change-delta/test", pkgs[0]) - require.Equal(t, "github.com/tateexon/go-change-delta/two", pkgs[1]) + verifySliceItemsPresent(t, []string{ + "github.com/tateexon/go-change-delta/test", + "github.com/tateexon/go-change-delta/two", + }, pkgs) }) t.Run("only changed go mod file", func(t *testing.T) {