From ee56cf47b4e0af50177d9e0fd0aa95056dbf51b2 Mon Sep 17 00:00:00 2001 From: 7h3-3mp7y-m4n Date: Thu, 17 Oct 2024 03:44:41 +0530 Subject: [PATCH 1/2] Fixed the init_test by comparing Signed-off-by: 7h3-3mp7y-m4n --- main_init_test.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/main_init_test.go b/main_init_test.go index 6731065..523860e 100644 --- a/main_init_test.go +++ b/main_init_test.go @@ -16,6 +16,7 @@ package main import ( "context" + "fmt" "os" "path/filepath" "strings" @@ -150,7 +151,17 @@ func TestInitWithProvisioners(t *testing.T) { provs, err := loader.LoadProvisionersFromDirectory(filepath.Join(td, ".score-k8s"), loader.DefaultSuffix) assert.NoError(t, err) if assert.Greater(t, len(provs), 2) { - assert.Equal(t, "template://two", provs[0].Uri()) - assert.Equal(t, "template://one", provs[1].Uri()) + expectedProvisioners := map[string]bool{ + "template://one": true, + "template://two": true, + } + for _, prov := range provs { + if _, found := expectedProvisioners[prov.Uri()]; found { + delete(expectedProvisioners, prov.Uri()) + } + } + for provisioner := range expectedProvisioners { + assert.Fail(t, fmt.Sprintf("Expected provisioner '%s' not found", provisioner)) + } } } From 97da5a090aac17c29c1cb2c6d30eb3b33872377b Mon Sep 17 00:00:00 2001 From: 7h3-3mp7y-m4n Date: Thu, 17 Oct 2024 14:54:11 +0530 Subject: [PATCH 2/2] improved the test by adding changes Signed-off-by: 7h3-3mp7y-m4n --- main_init_test.go | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/main_init_test.go b/main_init_test.go index 523860e..3b1d5a1 100644 --- a/main_init_test.go +++ b/main_init_test.go @@ -19,6 +19,7 @@ import ( "fmt" "os" "path/filepath" + "slices" "strings" "testing" @@ -27,6 +28,7 @@ import ( "github.com/stretchr/testify/require" "github.com/score-spec/score-k8s/internal/project" + "github.com/score-spec/score-k8s/internal/provisioners" "github.com/score-spec/score-k8s/internal/provisioners/loader" ) @@ -150,18 +152,10 @@ func TestInitWithProvisioners(t *testing.T) { provs, err := loader.LoadProvisionersFromDirectory(filepath.Join(td, ".score-k8s"), loader.DefaultSuffix) assert.NoError(t, err) - if assert.Greater(t, len(provs), 2) { - expectedProvisioners := map[string]bool{ - "template://one": true, - "template://two": true, - } - for _, prov := range provs { - if _, found := expectedProvisioners[prov.Uri()]; found { - delete(expectedProvisioners, prov.Uri()) - } - } - for provisioner := range expectedProvisioners { - assert.Fail(t, fmt.Sprintf("Expected provisioner '%s' not found", provisioner)) - } + expectedProvisionerUris := []string{"template://one", "template://two"} + for _, expectedUri := range expectedProvisionerUris { + assert.True(t, slices.ContainsFunc(provs, func(p provisioners.Provisioner) bool { + return p.Uri() == expectedUri + }), fmt.Sprintf("Expected provisioner '%s' not found", expectedUri)) } }