From 94ada8b992915af49c23d3601437b53161bd36e0 Mon Sep 17 00:00:00 2001 From: Will Vedder Date: Wed, 20 Sep 2023 13:27:54 -0400 Subject: [PATCH 1/3] Adding sorting for more deterministic tests --- internal/cli/actions_test.go | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/internal/cli/actions_test.go b/internal/cli/actions_test.go index b92ed7e63..b664443eb 100644 --- a/internal/cli/actions_test.go +++ b/internal/cli/actions_test.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "io" + "sort" "testing" "github.com/auth0/go-auth0/management" @@ -210,6 +211,12 @@ func TestActionsPickerOptions(t *testing.T) { }) } } + +func sortActionSecrets(secrets []management.ActionSecret) { + sort.Slice(secrets, func(i, j int) bool { + return secrets[i].GetName() < secrets[j].GetName() + }) +} func TestActionsInputSecretsToActionSecrets(t *testing.T) { t.Run("it should map input secrets to action payload", func(t *testing.T) { input := map[string]string{ @@ -218,6 +225,8 @@ func TestActionsInputSecretsToActionSecrets(t *testing.T) { "secret3": "value3", } res := inputSecretsToActionSecrets(input) + sortActionSecrets(*res) + expected := []management.ActionSecret{ { Name: auth0.String("secret1"), @@ -244,3 +253,40 @@ func TestActionsInputSecretsToActionSecrets(t *testing.T) { assert.Equal(t, res, &expected) }) } + +func sortActionDependencies(dependencies []management.ActionDependency) { + sort.Slice(dependencies, func(i, j int) bool { + return dependencies[i].GetName() < dependencies[j].GetName() + }) +} +func TestActionsInputDependenciesToActionDependencies(t *testing.T) { + t.Run("it should map input dependencies to action payload", func(t *testing.T) { + input := map[string]string{ + "lodash": "4.0.0", + "uuid": "9.0.0", + } + res := inputDependenciesToActionDependencies(input) + sortActionDependencies(*res) + expected := []management.ActionDependency{ + { + Name: auth0.String("lodash"), + Version: auth0.String("4.0.0"), + }, + { + Name: auth0.String("uuid"), + Version: auth0.String("9.0.0"), + }, + } + + assert.Len(t, *res, 2) + assert.Equal(t, *res, expected) + }) + + t.Run("it should handle empty input dependencies", func(t *testing.T) { + emptyInput := map[string]string{} + res := inputDependenciesToActionDependencies(emptyInput) + expected := []management.ActionDependency{} + assert.Len(t, *res, 0) + assert.Equal(t, expected, *res) + }) +} From d3cea0d309b18f38bc67cb7f1249ca937bee7317 Mon Sep 17 00:00:00 2001 From: Will Vedder Date: Wed, 20 Sep 2023 13:30:04 -0400 Subject: [PATCH 2/3] Adding third case for deps --- internal/cli/actions_test.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/cli/actions_test.go b/internal/cli/actions_test.go index b664443eb..243edb2f9 100644 --- a/internal/cli/actions_test.go +++ b/internal/cli/actions_test.go @@ -262,12 +262,17 @@ func sortActionDependencies(dependencies []management.ActionDependency) { func TestActionsInputDependenciesToActionDependencies(t *testing.T) { t.Run("it should map input dependencies to action payload", func(t *testing.T) { input := map[string]string{ - "lodash": "4.0.0", - "uuid": "9.0.0", + "fs-extra": "11.1.1", + "lodash": "4.0.0", + "uuid": "9.0.0", } res := inputDependenciesToActionDependencies(input) sortActionDependencies(*res) expected := []management.ActionDependency{ + { + Name: auth0.String("fs-extra"), + Version: auth0.String("11.1.1"), + }, { Name: auth0.String("lodash"), Version: auth0.String("4.0.0"), @@ -278,7 +283,7 @@ func TestActionsInputDependenciesToActionDependencies(t *testing.T) { }, } - assert.Len(t, *res, 2) + assert.Len(t, *res, 3) assert.Equal(t, *res, expected) }) From 9b869e471c2522c491f1c3faa0ce053d11db499d Mon Sep 17 00:00:00 2001 From: Will Vedder Date: Thu, 21 Sep 2023 10:59:18 -0400 Subject: [PATCH 3/3] Removing sorting --- internal/cli/actions_test.go | 68 +++++++++++++----------------------- 1 file changed, 24 insertions(+), 44 deletions(-) diff --git a/internal/cli/actions_test.go b/internal/cli/actions_test.go index 243edb2f9..a091703cf 100644 --- a/internal/cli/actions_test.go +++ b/internal/cli/actions_test.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "io" - "sort" "testing" "github.com/auth0/go-auth0/management" @@ -212,11 +211,6 @@ func TestActionsPickerOptions(t *testing.T) { } } -func sortActionSecrets(secrets []management.ActionSecret) { - sort.Slice(secrets, func(i, j int) bool { - return secrets[i].GetName() < secrets[j].GetName() - }) -} func TestActionsInputSecretsToActionSecrets(t *testing.T) { t.Run("it should map input secrets to action payload", func(t *testing.T) { input := map[string]string{ @@ -225,24 +219,20 @@ func TestActionsInputSecretsToActionSecrets(t *testing.T) { "secret3": "value3", } res := inputSecretsToActionSecrets(input) - sortActionSecrets(*res) - expected := []management.ActionSecret{ - { - Name: auth0.String("secret1"), - Value: auth0.String("value1"), - }, - { - Name: auth0.String("secret2"), - Value: auth0.String("value2"), - }, - { - Name: auth0.String("secret3"), - Value: auth0.String("value3"), - }, - } assert.Len(t, *res, 3) - assert.Equal(t, *res, expected) + assert.Contains(t, *res, management.ActionSecret{ + Name: auth0.String("secret1"), + Value: auth0.String("value1"), + }) + assert.Contains(t, *res, management.ActionSecret{ + Name: auth0.String("secret2"), + Value: auth0.String("value2"), + }) + assert.Contains(t, *res, management.ActionSecret{ + Name: auth0.String("secret3"), + Value: auth0.String("value3"), + }) }) t.Run("it should handle empty input secrets", func(t *testing.T) { @@ -253,12 +243,6 @@ func TestActionsInputSecretsToActionSecrets(t *testing.T) { assert.Equal(t, res, &expected) }) } - -func sortActionDependencies(dependencies []management.ActionDependency) { - sort.Slice(dependencies, func(i, j int) bool { - return dependencies[i].GetName() < dependencies[j].GetName() - }) -} func TestActionsInputDependenciesToActionDependencies(t *testing.T) { t.Run("it should map input dependencies to action payload", func(t *testing.T) { input := map[string]string{ @@ -267,24 +251,20 @@ func TestActionsInputDependenciesToActionDependencies(t *testing.T) { "uuid": "9.0.0", } res := inputDependenciesToActionDependencies(input) - sortActionDependencies(*res) - expected := []management.ActionDependency{ - { - Name: auth0.String("fs-extra"), - Version: auth0.String("11.1.1"), - }, - { - Name: auth0.String("lodash"), - Version: auth0.String("4.0.0"), - }, - { - Name: auth0.String("uuid"), - Version: auth0.String("9.0.0"), - }, - } assert.Len(t, *res, 3) - assert.Equal(t, *res, expected) + assert.Contains(t, *res, management.ActionDependency{ + Name: auth0.String("fs-extra"), + Version: auth0.String("11.1.1"), + }) + assert.Contains(t, *res, management.ActionDependency{ + Name: auth0.String("lodash"), + Version: auth0.String("4.0.0"), + }) + assert.Contains(t, *res, management.ActionDependency{ + Name: auth0.String("uuid"), + Version: auth0.String("9.0.0"), + }) }) t.Run("it should handle empty input dependencies", func(t *testing.T) {