Skip to content

Commit e428a44

Browse files
committed
Add tests for storage_anywhere_cache
1 parent f81b3f1 commit e428a44

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed

mmv1/products/storage/AnywhereCache.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ 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'
35+
external_providers: ["time"]
3036
identity:
3137
- bucket
3238
- 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,108 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
package storage_test
4+
5+
import (
6+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
7+
"github.com/hashicorp/terraform-provider-google/google/acctest"
8+
"testing"
9+
)
10+
11+
func TestAccStorageAnywhereCache_update(t *testing.T) {
12+
t.Parallel()
13+
14+
context := map[string]interface{}{
15+
"random_suffix": acctest.RandString(t, 10),
16+
}
17+
18+
acctest.VcrTest(t, resource.TestCase{
19+
PreCheck: func() { acctest.AccTestPreCheck(t) },
20+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
21+
CheckDestroy: testAccCheckStorageAnywhereCacheDestroyProducer(t),
22+
ExternalProviders: map[string]resource.ExternalProvider{
23+
"time": {},
24+
},
25+
Steps: []resource.TestStep{
26+
{
27+
Config: testAccStorageAnywhereCache_full(context),
28+
},
29+
{
30+
ResourceName: "google_storage_anywhere_cache.cache",
31+
ImportState: true,
32+
ImportStateVerify: true,
33+
ImportStateVerifyIgnore: []string{"bucket"},
34+
},
35+
{
36+
Config: testAccStorageAnywhereCache_update(context),
37+
},
38+
{
39+
ResourceName: "google_storage_anywhere_cache.cache",
40+
ImportState: true,
41+
ImportStateVerify: true,
42+
ImportStateVerifyIgnore: []string{"bucket"},
43+
},
44+
},
45+
})
46+
}
47+
48+
func testAccStorageAnywhereCache_full(context map[string]interface{}) string {
49+
return acctest.Nprintf(`
50+
resource "google_storage_bucket" "bucket" {
51+
name = "tf-test-my-bucket%{random_suffix}"
52+
location = "US"
53+
}
54+
55+
resource "google_storage_bucket_iam_binding" "binding" {
56+
bucket = google_storage_bucket.bucket.name
57+
role = "roles/storage.admin"
58+
members = [
59+
"allUsers",
60+
]
61+
depends_on = [ google_storage_bucket.bucket ]
62+
}
63+
64+
resource "time_sleep" "wait_4000_seconds" {
65+
depends_on = [google_storage_bucket.bucket]
66+
destroy_duration = "4000s"
67+
}
68+
69+
resource "google_storage_anywhere_cache" "cache" {
70+
bucket = google_storage_bucket.bucket.name
71+
zone = "us-central1-f"
72+
admission_policy = "admit-on-first-miss"
73+
ttl = "90000s"
74+
depends_on = [ google_storage_bucket_iam_binding.binding ]
75+
}
76+
`, context)
77+
}
78+
79+
func testAccStorageAnywhereCache_update(context map[string]interface{}) string {
80+
return acctest.Nprintf(`
81+
resource "google_storage_bucket" "bucket" {
82+
name = "tf-test-my-bucket%{random_suffix}"
83+
location = "US"
84+
}
85+
86+
resource "google_storage_bucket_iam_binding" "binding" {
87+
bucket = google_storage_bucket.bucket.name
88+
role = "roles/storage.admin"
89+
members = [
90+
"allUsers",
91+
]
92+
depends_on = [ google_storage_bucket.bucket ]
93+
}
94+
95+
resource "time_sleep" "wait_4000_seconds" {
96+
depends_on = [google_storage_bucket.bucket]
97+
destroy_duration = "4000s"
98+
}
99+
100+
resource "google_storage_anywhere_cache" "cache" {
101+
bucket = google_storage_bucket.bucket.name
102+
zone = "us-central1-f"
103+
admission_policy = "admit-on-second-miss"
104+
ttl = "100000s"
105+
depends_on = [ google_storage_bucket_iam_binding.binding ]
106+
}
107+
`, context)
108+
}

0 commit comments

Comments
 (0)