Skip to content

Commit 70bc46c

Browse files
committed
add tests for storage_anywhere_cache
1 parent f81b3f1 commit 70bc46c

File tree

3 files changed

+147
-0
lines changed

3 files changed

+147
-0
lines changed

mmv1/products/storage/AnywhereCache.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ update_verb: 'PATCH'
2727
delete_verb: 'POST'
2828
import_format: ['b/{{bucket}}/anywhereCaches/{{anywhere_cache_id}}']
2929
id_format: '{{bucket}}/{{anywhere_cache_id}}'
30+
examples:
31+
- name: 'storage_anywhere_cache_basic'
32+
primary_resource_id: 'cache'
33+
vars:
34+
bucket_name: 'my-bucket'
3035
identity:
3136
- bucket
3237
- anywhereCacheId
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
resource "google_storage_bucket" "bucket" {
2+
name = "{{index $.Vars "bucket_name"}}"
3+
location = "US"
4+
}
5+
6+
resource "google_storage_bucket_iam_binding" "binding" {
7+
bucket = google_storage_bucket.bucket.name
8+
role = "roles/storage.admin"
9+
members = [
10+
"allUsers",
11+
]
12+
depends_on = [ google_storage_bucket.bucket ]
13+
}
14+
15+
resource "time_sleep" "wait_4000_seconds" {
16+
depends_on = [google_storage_bucket.bucket]
17+
destroy_duration = "4000s"
18+
}
19+
20+
resource "google_storage_anywhere_cache" "cache" {
21+
bucket = google_storage_bucket.bucket.name
22+
zone = "us-central1-f"
23+
depends_on = [ google_storage_bucket_iam_binding.binding ]
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
package storage_test
4+
5+
import (
6+
"fmt"
7+
"strings"
8+
"testing"
9+
10+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
11+
"github.com/hashicorp/terraform-plugin-testing/terraform"
12+
13+
"github.com/hashicorp/terraform-provider-google/google/acctest"
14+
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
15+
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
16+
)
17+
18+
func TestAccStorageAnywhereCache_update(t *testing.T) {
19+
t.Parallel()
20+
21+
context := map[string]interface{}{
22+
"random_suffix": acctest.RandString(t, 10),
23+
}
24+
25+
acctest.VcrTest(t, resource.TestCase{
26+
PreCheck: func() { acctest.AccTestPreCheck(t) },
27+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
28+
CheckDestroy: testAccCheckStorageAnywhereCacheDestroyProducer(t),
29+
Steps: []resource.TestStep{
30+
{
31+
Config: testAccStorageAnywhereCache_full(context),
32+
},
33+
{
34+
ResourceName: "google_storage_anywhere_cache.cache",
35+
ImportState: true,
36+
ImportStateVerify: true,
37+
ImportStateVerifyIgnore: []string{"bucket"},
38+
},
39+
{
40+
Config: testAccStorageAnywhereCache_update(context),
41+
ConfigPlanChecks: resource.ConfigPlanChecks{
42+
PreApply: []plancheck.PlanCheck{
43+
plancheck.ExpectResourceAction("google_storage_anywhere_cache.cache", plancheck.ResourceActionUpdate),
44+
},
45+
},
46+
},
47+
{
48+
ResourceName: "google_storage_anywhere_cache.cache",
49+
ImportState: true,
50+
ImportStateVerify: true,
51+
ImportStateVerifyIgnore: []string{"bucket"},
52+
},
53+
},
54+
})
55+
}
56+
57+
func testAccStorageAnywhereCache_full(context map[string]interface{}) string {
58+
return acctest.Nprintf(`
59+
resource "google_storage_bucket" "bucket" {
60+
name = "tf-test-my-bucket%{random_suffix}"
61+
location = "US"
62+
}
63+
64+
resource "google_storage_bucket_iam_binding" "binding" {
65+
bucket = google_storage_bucket.bucket.name
66+
role = "roles/storage.admin"
67+
members = [
68+
"allUsers",
69+
]
70+
depends_on = [ google_storage_bucket.bucket ]
71+
}
72+
73+
resource "time_sleep" "wait_4000_seconds" {
74+
depends_on = [google_storage_bucket.bucket]
75+
destroy_duration = "4000s"
76+
}
77+
78+
resource "google_storage_anywhere_cache" "cache" {
79+
bucket = google_storage_bucket.bucket.name
80+
zone = "us-central1-f"
81+
admission_policy = "admit-on-first-miss"
82+
ttl = "90000s"
83+
depends_on = [ google_storage_bucket_iam_binding.binding ]
84+
}
85+
`, context)
86+
}
87+
88+
func testAccStorageAnywhereCache_update(context map[string]interface{}) string {
89+
return acctest.Nprintf(`
90+
resource "google_storage_bucket" "bucket" {
91+
name = "tf-test-my-bucket%{random_suffix}"
92+
location = "US"
93+
}
94+
95+
resource "google_storage_bucket_iam_binding" "binding" {
96+
bucket = google_storage_bucket.bucket.name
97+
role = "roles/storage.admin"
98+
members = [
99+
"allUsers",
100+
]
101+
depends_on = [ google_storage_bucket.bucket ]
102+
}
103+
104+
resource "time_sleep" "wait_4000_seconds" {
105+
depends_on = [google_storage_bucket.bucket]
106+
destroy_duration = "4000s"
107+
}
108+
109+
resource "google_storage_anywhere_cache" "cache" {
110+
bucket = google_storage_bucket.bucket.name
111+
zone = "us-central1-f"
112+
admission_policy = "admit-on-second-miss"
113+
ttl = "100000s"
114+
depends_on = [ google_storage_bucket_iam_binding.binding ]
115+
}
116+
`, context)
117+
}
118+

0 commit comments

Comments
 (0)