Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: fix konnect integration tests #1101

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions tests/integration/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down
17 changes: 10 additions & 7 deletions tests/integration/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -174,14 +175,16 @@ 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{}
if expectedState.RBACEndpointPermissions != nil {
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")
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are keeping the "old" syntax on purpose here since we care more about not breaking existing workflows than introducing possible bugs into new functionalities. @Tieske has some WIP task to improve our posture here.

if len(opts) > 0 {
args = append(args, opts...)
}
Expand Down
Loading