diff --git a/go.mod b/go.mod index 5f4370739..0952b8b52 100644 --- a/go.mod +++ b/go.mod @@ -29,11 +29,12 @@ require ( github.com/stretchr/testify v1.8.4 github.com/xeipuuv/gojsonschema v1.2.0 golang.org/x/sync v0.3.0 - gopkg.in/yaml.v2 v2.4.0 k8s.io/code-generator v0.28.3 sigs.k8s.io/yaml v1.4.0 ) +require gopkg.in/yaml.v2 v2.4.0 // indirect + require ( atomicgo.dev/cursor v0.1.1 // indirect atomicgo.dev/keyboard v0.2.9 // indirect diff --git a/tests/integration/sync_test.go b/tests/integration/sync_test.go index 5a143ead7..90cf00ade 100644 --- a/tests/integration/sync_test.go +++ b/tests/integration/sync_test.go @@ -4698,25 +4698,29 @@ func Test_Sync_KonnectRename(t *testing.T) { }, } for _, tc := range tests { + tc := tc t.Run(tc.name, func(t *testing.T) { runWhenKonnect(t) setup(t) + if tc.controlPlaneName != "" { + t.Logf("running test against DECK_KONNECT_CONTROL_PLANE_NAME %s", tc.controlPlaneName) t.Setenv("DECK_KONNECT_CONTROL_PLANE_NAME", tc.controlPlaneName) t.Cleanup(func() { reset(t, "--konnect-control-plane-name", tc.controlPlaneName) }) } else if tc.runtimeGroupName != "" { + t.Logf("running test against DECK_KONNECT_RUNTIME_GROUP_NAME %s", tc.runtimeGroupName) t.Setenv("DECK_KONNECT_RUNTIME_GROUP_NAME", tc.runtimeGroupName) t.Cleanup(func() { reset(t, "--konnect-runtime-group-name", tc.runtimeGroupName) }) } + client, err := getTestClient() - if err != nil { - t.Fatalf(err.Error()) - } - sync(tc.kongFile, tc.flags...) + require.NoError(t, err) + + require.NoError(t, sync(tc.kongFile, tc.flags...)) testKongState(t, client, true, tc.expectedState, nil) }) } diff --git a/tests/integration/test_utils.go b/tests/integration/test_utils.go index 714ceb45b..900a687e1 100644 --- a/tests/integration/test_utils.go +++ b/tests/integration/test_utils.go @@ -14,6 +14,7 @@ import ( deckDump "github.com/kong/deck/dump" "github.com/kong/deck/utils" "github.com/kong/go-kong/kong" + "github.com/stretchr/testify/assert" ) func int32p(i int) *int32 { @@ -174,6 +175,8 @@ func sortSlices(x, y interface{}) bool { func testKongState(t *testing.T, client *kong.Client, isKonnect bool, expectedState utils.KongRawState, ignoreFields []cmp.Option, ) { + t.Helper() + // Get entities from Kong ctx := context.Background() dumpConfig := deckDump.Config{} @@ -181,7 +184,7 @@ func testKongState(t *testing.T, client *kong.Client, isKonnect bool, dumpConfig.RBACResourcesOnly = true } if isKonnect { - controlPlaneName := os.Getenv("DECK_KONNECT_CONTROL_PLANE_NAME") + controlPlaneName := os.Getenv("DECK_KONNECT_RUNTIME_GROUP_NAME") if controlPlaneName == "" { controlPlaneName = os.Getenv("DECK_KONNECT_CONTROL_PLANE_NAME") } @@ -219,20 +222,20 @@ func testKongState(t *testing.T, client *kong.Client, isKonnect bool, opt = append(opt, ignoreFields...) if diff := cmp.Diff(kongState, &expectedState, opt...); diff != "" { - t.Errorf(diff) + t.Errorf("Not expecting diff in kong state but got:\n%s", diff) } } func reset(t *testing.T, opts ...string) { + t.Helper() + deckCmd := cmd.NewRootCmd() - args := []string{"reset", "--force"} + args := []string{"gateway", "reset", "--force"} if len(opts) > 0 { args = append(args, opts...) } deckCmd.SetArgs(args) - if err := deckCmd.Execute(); err != nil { - t.Fatalf(err.Error(), "failed to reset Kong's state") - } + assert.NoError(t, deckCmd.Execute(), "failed to reset Kong's state") } func readFile(filepath string) (string, error) { @@ -258,7 +261,7 @@ func setup(t *testing.T) { func sync(kongFile string, opts ...string) error { deckCmd := cmd.NewRootCmd() - args := []string{"sync", "-s", kongFile} + args := []string{"gateway", "sync", kongFile} if len(opts) > 0 { args = append(args, opts...) }