From c36cd22d24c4dc2bfe410afdcbadeaa6f252cb33 Mon Sep 17 00:00:00 2001 From: Yuwen Ma Date: Sat, 22 Jun 2024 00:06:09 +0000 Subject: [PATCH 1/2] fix: replace mockresourcemanager generated Project number --- .../_generated_object_projectinfolder.golden.yaml | 2 +- .../_generated_object_projectinorg.golden.yaml | 2 +- ...nerated_object_projectmovedfoldertofolder.golden.yaml | 2 +- tests/e2e/normalize.go | 9 +++++++++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/test/resourcefixture/testdata/basic/resourcemanager/v1beta1/project/projectinfolder/_generated_object_projectinfolder.golden.yaml b/pkg/test/resourcefixture/testdata/basic/resourcemanager/v1beta1/project/projectinfolder/_generated_object_projectinfolder.golden.yaml index 2bbedc3a25..dcc3c056da 100644 --- a/pkg/test/resourcefixture/testdata/basic/resourcemanager/v1beta1/project/projectinfolder/_generated_object_projectinfolder.golden.yaml +++ b/pkg/test/resourcefixture/testdata/basic/resourcemanager/v1beta1/project/projectinfolder/_generated_object_projectinfolder.golden.yaml @@ -25,5 +25,5 @@ status: reason: UpToDate status: "True" type: Ready - number: "2727742225" + number: "518915279" observedGeneration: 3 diff --git a/pkg/test/resourcefixture/testdata/basic/resourcemanager/v1beta1/project/projectinorg/_generated_object_projectinorg.golden.yaml b/pkg/test/resourcefixture/testdata/basic/resourcemanager/v1beta1/project/projectinorg/_generated_object_projectinorg.golden.yaml index d8ce0c0fe3..94170d4c99 100644 --- a/pkg/test/resourcefixture/testdata/basic/resourcemanager/v1beta1/project/projectinorg/_generated_object_projectinorg.golden.yaml +++ b/pkg/test/resourcefixture/testdata/basic/resourcemanager/v1beta1/project/projectinorg/_generated_object_projectinorg.golden.yaml @@ -25,5 +25,5 @@ status: reason: UpToDate status: "True" type: Ready - number: "2713651918" + number: "518915279" observedGeneration: 3 diff --git a/pkg/test/resourcefixture/testdata/basic/resourcemanager/v1beta1/project/projectmovedfoldertofolder/_generated_object_projectmovedfoldertofolder.golden.yaml b/pkg/test/resourcefixture/testdata/basic/resourcemanager/v1beta1/project/projectmovedfoldertofolder/_generated_object_projectmovedfoldertofolder.golden.yaml index 9872b41b50..b129862254 100644 --- a/pkg/test/resourcefixture/testdata/basic/resourcemanager/v1beta1/project/projectmovedfoldertofolder/_generated_object_projectmovedfoldertofolder.golden.yaml +++ b/pkg/test/resourcefixture/testdata/basic/resourcemanager/v1beta1/project/projectmovedfoldertofolder/_generated_object_projectmovedfoldertofolder.golden.yaml @@ -24,5 +24,5 @@ status: reason: UpToDate status: "True" type: Ready - number: "2589592254" + number: "518915279" observedGeneration: 3 diff --git a/tests/e2e/normalize.go b/tests/e2e/normalize.go index d393cc4bcb..5e10108d24 100644 --- a/tests/e2e/normalize.go +++ b/tests/e2e/normalize.go @@ -95,9 +95,18 @@ func normalizeKRMObject(u *unstructured.Unstructured, project testgcp.GCPProject visitor.stringTransforms = append(visitor.stringTransforms, func(path string, s string) string { return strings.ReplaceAll(s, project.ProjectID, "${projectId}") }) + + // Update the project number with variable marker. + if u.GetKind() == "Project" { + // The ProjectNumber is ProjectID based. For those tests relying on the Mock Resource Manager server, + // the ProjectID is dynamic, different from the default mock test Project "mock-project", + // so the number is different as well. + visitor.replacePaths[".status.number"] = fmt.Sprintf("%d", project.ProjectNumber) + } visitor.stringTransforms = append(visitor.stringTransforms, func(path string, s string) string { return strings.ReplaceAll(s, fmt.Sprintf("%d", project.ProjectNumber), "${projectNumber}") }) + visitor.stringTransforms = append(visitor.stringTransforms, func(path string, s string) string { return strings.ReplaceAll(s, uniqueID, "${uniqueId}") }) From c09245443302fc4aa88ac2f47fdeab804618f578 Mon Sep 17 00:00:00 2001 From: Yuwen Ma Date: Sat, 22 Jun 2024 00:26:18 +0000 Subject: [PATCH 2/2] a better approach --- .../_generated_object_projectinfolder.golden.yaml | 2 +- .../_generated_object_projectinorg.golden.yaml | 2 +- ...ed_object_projectmovedfoldertofolder.golden.yaml | 2 +- tests/e2e/normalize.go | 13 ++++++------- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/pkg/test/resourcefixture/testdata/basic/resourcemanager/v1beta1/project/projectinfolder/_generated_object_projectinfolder.golden.yaml b/pkg/test/resourcefixture/testdata/basic/resourcemanager/v1beta1/project/projectinfolder/_generated_object_projectinfolder.golden.yaml index dcc3c056da..e9eddcccd5 100644 --- a/pkg/test/resourcefixture/testdata/basic/resourcemanager/v1beta1/project/projectinfolder/_generated_object_projectinfolder.golden.yaml +++ b/pkg/test/resourcefixture/testdata/basic/resourcemanager/v1beta1/project/projectinfolder/_generated_object_projectinfolder.golden.yaml @@ -25,5 +25,5 @@ status: reason: UpToDate status: "True" type: Ready - number: "518915279" + number: ${projectNumber} observedGeneration: 3 diff --git a/pkg/test/resourcefixture/testdata/basic/resourcemanager/v1beta1/project/projectinorg/_generated_object_projectinorg.golden.yaml b/pkg/test/resourcefixture/testdata/basic/resourcemanager/v1beta1/project/projectinorg/_generated_object_projectinorg.golden.yaml index 94170d4c99..df4b4d130a 100644 --- a/pkg/test/resourcefixture/testdata/basic/resourcemanager/v1beta1/project/projectinorg/_generated_object_projectinorg.golden.yaml +++ b/pkg/test/resourcefixture/testdata/basic/resourcemanager/v1beta1/project/projectinorg/_generated_object_projectinorg.golden.yaml @@ -25,5 +25,5 @@ status: reason: UpToDate status: "True" type: Ready - number: "518915279" + number: ${projectNumber} observedGeneration: 3 diff --git a/pkg/test/resourcefixture/testdata/basic/resourcemanager/v1beta1/project/projectmovedfoldertofolder/_generated_object_projectmovedfoldertofolder.golden.yaml b/pkg/test/resourcefixture/testdata/basic/resourcemanager/v1beta1/project/projectmovedfoldertofolder/_generated_object_projectmovedfoldertofolder.golden.yaml index b129862254..37b0a9eea4 100644 --- a/pkg/test/resourcefixture/testdata/basic/resourcemanager/v1beta1/project/projectmovedfoldertofolder/_generated_object_projectmovedfoldertofolder.golden.yaml +++ b/pkg/test/resourcefixture/testdata/basic/resourcemanager/v1beta1/project/projectmovedfoldertofolder/_generated_object_projectmovedfoldertofolder.golden.yaml @@ -24,5 +24,5 @@ status: reason: UpToDate status: "True" type: Ready - number: "518915279" + number: ${projectNumber} observedGeneration: 3 diff --git a/tests/e2e/normalize.go b/tests/e2e/normalize.go index 5e10108d24..21422dd004 100644 --- a/tests/e2e/normalize.go +++ b/tests/e2e/normalize.go @@ -92,17 +92,16 @@ func normalizeKRMObject(u *unstructured.Unstructured, project testgcp.GCPProject // TODO: This should not be needed, we want to avoid churning the kube objects visitor.sortSlices.Insert(".spec.access") + if u.GetKind() == "Project" { + // For some tests that talk to the Mock Resource Manager, the Project object's ProjectID and ProjectNumber are dynamcially generated. + // We do not want to overrride this with the default mocked Project "mock-project". + visitor.replacePaths[".status.number"] = "${projectNumber}" + } + visitor.stringTransforms = append(visitor.stringTransforms, func(path string, s string) string { return strings.ReplaceAll(s, project.ProjectID, "${projectId}") }) - // Update the project number with variable marker. - if u.GetKind() == "Project" { - // The ProjectNumber is ProjectID based. For those tests relying on the Mock Resource Manager server, - // the ProjectID is dynamic, different from the default mock test Project "mock-project", - // so the number is different as well. - visitor.replacePaths[".status.number"] = fmt.Sprintf("%d", project.ProjectNumber) - } visitor.stringTransforms = append(visitor.stringTransforms, func(path string, s string) string { return strings.ReplaceAll(s, fmt.Sprintf("%d", project.ProjectNumber), "${projectNumber}") })