|
| 1 | +// Copyright 2022 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 simple_example |
| 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/stretchr/testify/assert" |
| 24 | +) |
| 25 | + |
| 26 | +func TestImportOnlyExample(t *testing.T) { |
| 27 | + bpt := tft.NewTFBlueprintTest(t) |
| 28 | + bpt.DefineVerify(func(assert *assert.Assertions) { |
| 29 | + bpt.DefaultVerify(assert) |
| 30 | + |
| 31 | + projectId := bpt.GetStringOutput("project_id") |
| 32 | + keyring := bpt.GetStringOutput("keyring") |
| 33 | + location := bpt.GetStringOutput("location") |
| 34 | + keys := [2]string{"one", "two"} |
| 35 | + |
| 36 | + op := gcloud.Runf(t, "--project=%s kms keyrings list --location %s --filter name:%s", projectId, location, keyring).Array()[0].Get("name") |
| 37 | + assert.Contains(op.String(), fmt.Sprintf("projects/%s/locations/%s/keyRings/%s", projectId, location, keyring), "Contains KeyRing") |
| 38 | + |
| 39 | + op1 := gcloud.Runf(t, "kms keys list --project=%s --keyring %s --location %s", projectId, keyring, location).Array() |
| 40 | + for index, element := range op1 { |
| 41 | + assert.Equal(element.Get("name").String(), fmt.Sprintf("projects/%s/locations/%s/keyRings/%s/cryptoKeys/%s", projectId, location, keyring, keys[index]), "Contains Keys") |
| 42 | + assert.True(element.Get("importOnly").Bool(), "ImportOnly flag") |
| 43 | + } |
| 44 | + }) |
| 45 | + |
| 46 | + bpt.Test() |
| 47 | +} |
0 commit comments