Skip to content

Commit

Permalink
Copied tag key tests and adjusted for values
Browse files Browse the repository at this point in the history
  • Loading branch information
melinath committed Mar 18, 2021
1 parent 2a9e92c commit 1be62ba
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 0 deletions.
1 change: 1 addition & 0 deletions mmv1/products/tags/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides
- !ruby/object:Provider::Terraform::Examples
name: "tag_value_basic"
min_version: 'beta'
skip_test: true
primary_resource_id: "value"
vars:
short_name: "foo"
Expand Down
150 changes: 150 additions & 0 deletions mmv1/third_party/terraform/tests/resource_tags_tag_key_test.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ func TestAccTags(t *testing.T) {
testCases := map[string]func(t *testing.T){
"basic": testAccTagsTagKey_tagKeyBasic,
"update": testAccTagsTagKey_update,
"basic": testAccTagsTagValue_tagValueBasic,
"update": testAccTagsTagValue_update,
}

for name, tc := range testCases {
Expand Down Expand Up @@ -156,4 +158,152 @@ func testAccCheckTagsTagKeyDestroyProducer(t *testing.T) func(s *terraform.State
}
}

func testAccTagsTagValue_tagValueBasic(t *testing.T) {
context := map[string]interface{}{
"org_id": getTestOrgFromEnv(t),
"random_suffix": randString(t, 10),
}

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProvidersOiCS,
ExternalProviders: map[string]resource.ExternalProvider{
"random": {},
},
CheckDestroy: testAccCheckTagsTagValueDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccTagsTagValue_tagValueBasicExample(context),
},
},
})
}

func testAccTagsTagValue_tagValueBasicExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_tags_tag_key" "key" {
provider = google-beta

parent = "organizations/%{org_id}"
short_name = "foobarbaz%{random_suffix}"
description = "For foo/bar/baz resources."
}

resource "google_tags_tag_value" "value" {
provider = google-beta

parent = "tagKeys/${google_tags_tag_key.key.name}"
short_name = "foo%{random_suffix}"
description = "For foo resources."
}
`, context)
}

func testAccTagsTagValue_update(t *testing.T) {
context := map[string]interface{}{
"org_id": getTestOrgFromEnv(t),
"random_suffix": randString(t, 10),
}

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProvidersOiCS,
ExternalProviders: map[string]resource.ExternalProvider{
"random": {},
},
CheckDestroy: testAccCheckTagsTagValueDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccTagsTagValue_basic(context),
},
{
ResourceName: "google_tags_tag_key.key",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccTagsTagValue_basicUpdated(context),
},
{
ResourceName: "google_tags_tag_key.key",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccTagsTagValue_basic(context map[string]interface{}) string {
return Nprintf(`
resource "google_tags_tag_key" "key" {
provider = google-beta

parent = "organizations/%{org_id}"
short_name = "foobarbaz%{random_suffix}"
description = "For foo/bar/baz resources."
}

resource "google_tags_tag_value" "value" {
provider = google-beta

parent = "tagKeys/${google_tags_tag_key.key.name}"
short_name = "foo%{random_suffix}"
description = "For foo resources."
}
`, context)
}

func testAccTagsTagValue_basicUpdated(context map[string]interface{}) string {
return Nprintf(`
resource "google_tags_tag_key" "key" {
provider = google-beta

parent = "organizations/%{org_id}"
short_name = "foobarbaz%{random_suffix}"
description = "For foo/bar/baz resources."
}

resource "google_tags_tag_value" "value" {
provider = google-beta

parent = "tagKeys/${google_tags_tag_key.key.name}"
short_name = "foo%{random_suffix}"
description = "For any foo resources."
}
`, context)
}

func testAccCheckTagsTagValueDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
if rs.Type != "google_tags_tag_key" {
continue
}
if strings.HasPrefix(name, "data.") {
continue
}

config := googleProviderConfig(t)

url, err := replaceVarsForTest(config, rs, "{{TagsBasePath}}tagValues/{{name}}")
if err != nil {
return err
}

billingProject := ""

if config.BillingProject != "" {
billingProject = config.BillingProject
}

_, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil)
if err == nil {
return fmt.Errorf("TagsTagValue still exists at %s", url)
}
}

return nil
}
}

<% end %>

0 comments on commit 1be62ba

Please sign in to comment.