15
15
package e2e
16
16
17
17
import (
18
+ "fmt"
18
19
"path/filepath"
19
20
"strings"
20
21
@@ -26,7 +27,11 @@ import (
26
27
"sigs.k8s.io/yaml"
27
28
)
28
29
29
- func exportResource (h * create.Harness , obj * unstructured.Unstructured ) string {
30
+ type Expectations struct {
31
+ Location bool // location or region
32
+ }
33
+
34
+ func exportResource (h * create.Harness , obj * unstructured.Unstructured , expectations * Expectations ) string {
30
35
exportURI := ""
31
36
32
37
projectID := resolveProjectID (h , obj )
@@ -35,8 +40,13 @@ func exportResource(h *create.Harness, obj *unstructured.Unstructured) string {
35
40
if resourceID == "" {
36
41
resourceID = obj .GetName ()
37
42
}
38
- // location, _, _ := unstructured.NestedString(obj.Object, "spec", "location")
39
-
43
+ location , found , err := unstructured .NestedString (obj .Object , "spec" , "location" )
44
+ if err != nil {
45
+ h .T .Error (fmt .Errorf ("retrieving location from obj: %w" , err ))
46
+ }
47
+ if ! found && expectations .Location {
48
+ h .T .Error ("expected to find location or region in obj but did not find it" )
49
+ }
40
50
// This list should match https://cloud.google.com/asset-inventory/docs/resource-name-format
41
51
gvk := obj .GroupVersionKind ()
42
52
switch gvk .GroupKind () {
@@ -51,6 +61,10 @@ func exportResource(h *create.Harness, obj *unstructured.Unstructured) string {
51
61
52
62
case schema.GroupKind {Group : "monitoring.cnrm.cloud.google.com" , Kind : "MonitoringDashboard" }:
53
63
exportURI = "//monitoring.googleapis.com/projects/" + projectID + "/dashboards/" + resourceID
64
+
65
+ case schema.GroupKind {Group : "cloudbuild.cnrm.cloud.google.com" , Kind : "CloudBuildWorkerPool" }:
66
+ exportURI = "//cloudbuild.googleapis.com/projects/" + projectID + "/locations/" + location + "/workerPools/" + resourceID
67
+
54
68
}
55
69
56
70
if exportURI == "" {
@@ -74,7 +88,7 @@ func exportResource(h *create.Harness, obj *unstructured.Unstructured) string {
74
88
}
75
89
76
90
func exportResourceAsUnstructured (h * create.Harness , obj * unstructured.Unstructured ) * unstructured.Unstructured {
77
- s := exportResource (h , obj )
91
+ s := exportResource (h , obj , & Expectations {} )
78
92
if s == "" {
79
93
return nil
80
94
}
0 commit comments