refactor(tests): replace uuid.NewString() with GenerateName in envtest tests#3707
Open
superyyrrzz wants to merge 7 commits intoKong:mainfrom
Open
refactor(tests): replace uuid.NewString() with GenerateName in envtest tests#3707superyyrrzz wants to merge 7 commits intoKong:mainfrom
superyyrrzz wants to merge 7 commits intoKong:mainfrom
Conversation
…t helpers and tests Use Kubernetes native GenerateName field for resource names in test code where .Name is not referenced before Create(). The API server assigns unique names with descriptive prefixes (e.g. "gw-abc12", "httproute-xyz34"), making test output easier to trace. Files updated: - test/envtest/k8s.go (CreateNamespace, CreatePod) - test/envtest/setup.go (deployGateway, deployGatewayUsingGatewayClass) - test/envtest/gateway_envtest_test.go (HTTPRoute in createHTTPRoutes) - test/envtest/httproute_controller_test.go (GatewayClass, Gateway, HTTPRoute, ReferenceGrant) - test/envtest/ingress_test.go (EndpointSlice) - test/envtest/k8s_objects_status_envtest_test.go (first HTTPRoute only) - test/envtest/kongadminapi_controller_envtest_test.go (6 EndpointSlices) - test/envtest/kongupstreampolicy_test.go (GatewayClass, Gateway, HTTPRoute) - test/envtest/adminapi_discoverer_envtest_test.go (EndpointSlice) - test/helpers/deploy/deploy_resources.go (2 safe functions) uuid.NewString() is intentionally kept where: - .Name is referenced before Create() (e.g. cross-resource references) - Used for non-name fields (UIDs, Konnect entity IDs) - Name is shared between ObjectMeta and Spec (dual-name pattern) Ref: Kong#102
Fix gci lint: align Namespace field with longer GenerateName field in struct literals across 6 envtest test files.
9b63d04 to
47fb450
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves #102 (partial — safe usages only)
uuid.NewString()with Kubernetes nativeGenerateNamefield for test resource names across envtest helpers and test files.Nameis not referenced beforeCreate()— the API server assigns the name on creationgw-abc12instead of a full UUID)Files changed (10)
test/envtest/k8s.goCreateNamespace/CreatePod→GenerateName: "ns-"/"pod-"test/envtest/setup.godeployGateway/deployGatewayUsingGatewayClass→GenerateName: "gw-"/"gwc-"test/envtest/gateway_envtest_test.goGenerateName: "httproute-"test/envtest/httproute_controller_test.goGenerateNametest/envtest/ingress_test.goGenerateName: "endpointslice-"test/envtest/kongadminapi_controller_envtest_test.goGenerateName(keepsuuidfor UID)test/envtest/adminapi_discoverer_envtest_test.goGenerateName: "endpointslice-"test/envtest/kongupstreampolicy_test.goGenerateNametest/envtest/k8s_objects_status_envtest_test.goGenerateName(second kept as-is, see below)test/helpers/deploy/deploy_resources.goGenerateNameIntentionally left unchanged
These usages require further discussion (#102):
test/envtest/k8s_objects_status_envtest_test.go:170—.Nameread viaDeepCopy+ObjectKeyFromObjectbeforeCreate()test/envtest/gatewayclass_envtest_test.go:384—.Namelogged beforeCreate()test/helpers/deploy/deploy_resources.go— 6 functions with "dual-name" pattern (ObjectMeta.Namereused forSpec.Name/Spec.CreateControlPlaneRequest.Name)test/helpers/generators.go— returned objects used by callers beforeCreate()GenerateNamedoesn't applyTest plan
make test.envtestpasses — all modified tests exercise the GenerateName pathmake test.unitpasses — no compilation errorsmake lintpasses