Skip to content

Commit

Permalink
a better approach
Browse files Browse the repository at this point in the history
  • Loading branch information
yuwenma committed Jun 22, 2024
1 parent c36cd22 commit c092454
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ status:
reason: UpToDate
status: "True"
type: Ready
number: "518915279"
number: ${projectNumber}
observedGeneration: 3
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ status:
reason: UpToDate
status: "True"
type: Ready
number: "518915279"
number: ${projectNumber}
observedGeneration: 3
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ status:
reason: UpToDate
status: "True"
type: Ready
number: "518915279"
number: ${projectNumber}
observedGeneration: 3
13 changes: 6 additions & 7 deletions tests/e2e/normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
})
Expand Down

0 comments on commit c092454

Please sign in to comment.