|
| 1 | +// Copyright 2024 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package tags_project |
| 16 | + |
| 17 | +import ( |
| 18 | + "fmt" |
| 19 | + "testing" |
| 20 | + |
| 21 | + "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/gcloud" |
| 22 | + "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft" |
| 23 | + "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/utils" |
| 24 | + "github.com/stretchr/testify/assert" |
| 25 | +) |
| 26 | + |
| 27 | +func TestTagsProject(t *testing.T) { |
| 28 | + tagsProjectT := tft.NewTFBlueprintTest(t) |
| 29 | + tagsProjectT.DefineVerify(func(assert *assert.Assertions) { |
| 30 | + tagsProjectT.DefaultVerify(assert) |
| 31 | + |
| 32 | + projectNum := tagsProjectT.GetStringOutput("project_num") |
| 33 | + tagValue := tagsProjectT.GetTFSetupStringOutput("tag_value") |
| 34 | + |
| 35 | + parent := fmt.Sprintf("//cloudresourcemanager.googleapis.com/projects/%s", projectNum) |
| 36 | + projBindings := gcloud.Runf(t, "resource-manager tags bindings list --parent=%s", parent).Array() |
| 37 | + assert.Len(projBindings, 1, "expected one binding") |
| 38 | + |
| 39 | + binding := utils.GetFirstMatchResult(t, projBindings, "parent", parent) |
| 40 | + assert.Equalf(fmt.Sprintf("tagValues/%s", tagValue), binding.Get("tagValue").String(), "expected binding to %s", tagValue) |
| 41 | + }) |
| 42 | + tagsProjectT.Test() |
| 43 | +} |
0 commit comments