Skip to content

Commit

Permalink
fix(gcloud): support Run cmd with quotes (#2748)
Browse files Browse the repository at this point in the history
  • Loading branch information
apeabody authored Dec 11, 2024
1 parent 27410ac commit 561befd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions infra/blueprint-test/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/gruntwork-io/terratest v0.48.0
github.com/hashicorp/terraform-config-inspect v0.0.0-20241129133400-c404f8227ea6
github.com/hashicorp/terraform-json v0.23.0
github.com/mattn/go-shellwords v1.0.12
github.com/mitchellh/go-testing-interface v1.14.2-0.20210821155943-2d9075ca8770
github.com/otiai10/copy v1.14.0
github.com/stretchr/testify v1.10.0
Expand Down
2 changes: 2 additions & 0 deletions infra/blueprint-test/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk=
github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=
github.com/mattn/go-zglob v0.0.4 h1:LQi2iOm0/fGgu80AioIJ/1j9w9Oh+9DZ39J4VAGzHQM=
github.com/mattn/go-zglob v0.0.4/go.mod h1:MxxjyoXXnMxfIpxTK2GAkw1w8glPsQILx3N5wrKakiY=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
Expand Down
8 changes: 6 additions & 2 deletions infra/blueprint-test/pkg/gcloud/gcloud.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2021 Google LLC
* Copyright 2021-2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,6 +24,7 @@ import (
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/utils"
"github.com/gruntwork-io/terratest/modules/logger"
"github.com/gruntwork-io/terratest/modules/shell"
"github.com/mattn/go-shellwords"
"github.com/mitchellh/go-testing-interface"
"github.com/tidwall/gjson"
)
Expand Down Expand Up @@ -93,7 +94,10 @@ func RunCmdE(t testing.TB, cmd string, opts ...cmdOption) (string, error) {
t.Fatal(err)
}
// split command into args
args := strings.Fields(cmd)
args, err := shellwords.Parse(cmd)
if err != nil {
t.Fatal(err)
}
gcloudCmd := shell.Command{
Command: "gcloud",
Args: append(args, gOpts.commonArgs...),
Expand Down
19 changes: 19 additions & 0 deletions infra/blueprint-test/pkg/gcloud/gcloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,22 @@ func TestRunf(t *testing.T) {
})
}
}

func TestRun(t *testing.T) {
tests := []struct {
name string
cmd string
}{
{
name: "Run with quotes",
cmd: "organizations list --filter=\"DISPLAY_NAME!=google.com AND lifecycleState=ACTIVE\"",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
op := Runf(t, tt.cmd)
assert := assert.New(t)
assert.NotEmpty(op.String())
})
}
}

0 comments on commit 561befd

Please sign in to comment.