Skip to content

Commit aab9ddd

Browse files
committed
multi asset types
1 parent 1c9487a commit aab9ddd

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

test/integration/node_pool/node_pool_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestNodePool(t *testing.T) {
4242

4343
//cluster := gcloud.Runf(t, "container clusters describe %s --zone %s --project %s", clusterName, location, projectId)
4444
clusterResourceName := fmt.Sprintf("//container.googleapis.com/projects/%s/locations/%s/clusters/%s", projectId, location, clusterName)
45-
cluster := gkeutils.GetProjectResources(t, projectId, gkeutils.WithAssetType("container.googleapis.com/Cluster")).Get("#(name=\"" + clusterResourceName + "\").resource.data")
45+
cluster := gkeutils.GetProjectResources(t, projectId, gkeutils.WithAssetTypes([]string{"container.googleapis.com/Cluster"})).Get("#(name=\"" + clusterResourceName + "\").resource.data")
4646

4747
// Cluster
4848
assert.Contains([]string{"RUNNING", "RECONCILING"}, cluster.Get("status").String(), "Cluster is Running")

test/integration/utils/cai.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
package utils
1919

2020
import (
21+
"fmt"
22+
"strings"
2123
"testing"
2224
"time"
2325

@@ -26,23 +28,30 @@ import (
2628
)
2729

2830
type CmdCfg struct {
29-
sleep int // minutes to sleep prior to CAI retreval. default: 2
30-
assetType string // asset type to retrieve. default: all
31+
sleep int // minutes to sleep prior to CAI retreval. default: 2
32+
assetTypes []string // asset types to retrieve. empty: all
33+
args []string // arguments to pass to call
3134
}
3235

3336
type cmdOption func(*CmdCfg)
3437

3538
// newCmdConfig sets defaults and options
3639
func newCmdConfig(opts ...cmdOption) (*CmdCfg) {
3740
caiOpts := &CmdCfg{
38-
sleep: 2,
39-
assetType: "",
41+
sleep: 2,
42+
assetTypes: nil,
43+
args: nil,
4044
}
4145

4246
for _, opt := range opts {
4347
opt(caiOpts)
4448
}
4549

50+
if caiOpts.assetTypes != nil {
51+
caiOpts.args = []string{"--asset-types", strings.Join(caiOpts.assetTypes, ",")}
52+
}
53+
caiOpts.args = append(caiOpts.args, "--content-type", "resource")
54+
4655
return caiOpts
4756
}
4857

@@ -53,20 +62,21 @@ func WithSleep(sleep int) cmdOption {
5362
}
5463
}
5564

56-
// Set asset type
57-
func WithAssetType(assetType string) cmdOption {
65+
// Set asset types
66+
func WithAssetTypes(assetTypes []string) cmdOption {
5867
return func(f *CmdCfg) {
59-
f.assetType = assetType
68+
f.assetTypes = assetTypes
6069
}
6170
}
6271

6372
// GetProjectResources returns the cloud asset inventory resources for a project as a gjson.Result
6473
func GetProjectResources(t testing.TB, project string, opts ...cmdOption) gjson.Result {
6574
caiOpts := newCmdConfig(opts...)
75+
76+
// Cloud Asset Inventory offers best-effort data freshness.
77+
t.Logf("Sleeping for %d minutes before retrieving Cloud Asset Inventory...", caiOpts.sleep)
6678
time.Sleep(time.Duration(caiOpts.sleep) * time.Minute)
67-
if caiOpts.assetType != "" {
68-
return gcloud.Runf(t, "asset list --project=%s --asset-types=%s --content-type=resource", project, caiOpts.assetType)
69-
} else {
70-
return gcloud.Runf(t, "asset list --project=%s --content-type=resource", project)
71-
}
79+
80+
cmd := fmt.Sprintf("asset list --project %s", project)
81+
return gcloud.Runf(t, strings.Join(append([]string{cmd}, caiOpts.args...), " "))
7282
}

0 commit comments

Comments
 (0)