Skip to content

Commit 5974d1c

Browse files
committed
Add tests for storage_anywhere_cache
1 parent f81b3f1 commit 5974d1c

File tree

3 files changed

+134
-0
lines changed

3 files changed

+134
-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,105 @@
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+
Steps: []resource.TestStep{
23+
{
24+
Config: testAccStorageAnywhereCache_full(context),
25+
},
26+
{
27+
ResourceName: "google_storage_anywhere_cache.cache",
28+
ImportState: true,
29+
ImportStateVerify: true,
30+
ImportStateVerifyIgnore: []string{"bucket"},
31+
},
32+
{
33+
Config: testAccStorageAnywhereCache_update(context),
34+
},
35+
{
36+
ResourceName: "google_storage_anywhere_cache.cache",
37+
ImportState: true,
38+
ImportStateVerify: true,
39+
ImportStateVerifyIgnore: []string{"bucket"},
40+
},
41+
},
42+
})
43+
}
44+
45+
func testAccStorageAnywhereCache_full(context map[string]interface{}) string {
46+
return acctest.Nprintf(`
47+
resource "google_storage_bucket" "bucket" {
48+
name = "tf-test-my-bucket%{random_suffix}"
49+
location = "US"
50+
}
51+
52+
resource "google_storage_bucket_iam_binding" "binding" {
53+
bucket = google_storage_bucket.bucket.name
54+
role = "roles/storage.admin"
55+
members = [
56+
"allUsers",
57+
]
58+
depends_on = [ google_storage_bucket.bucket ]
59+
}
60+
61+
resource "time_sleep" "wait_4000_seconds" {
62+
depends_on = [google_storage_bucket.bucket]
63+
destroy_duration = "4000s"
64+
}
65+
66+
resource "google_storage_anywhere_cache" "cache" {
67+
bucket = google_storage_bucket.bucket.name
68+
zone = "us-central1-f"
69+
admission_policy = "admit-on-first-miss"
70+
ttl = "90000s"
71+
depends_on = [ google_storage_bucket_iam_binding.binding ]
72+
}
73+
`, context)
74+
}
75+
76+
func testAccStorageAnywhereCache_update(context map[string]interface{}) string {
77+
return acctest.Nprintf(`
78+
resource "google_storage_bucket" "bucket" {
79+
name = "tf-test-my-bucket%{random_suffix}"
80+
location = "US"
81+
}
82+
83+
resource "google_storage_bucket_iam_binding" "binding" {
84+
bucket = google_storage_bucket.bucket.name
85+
role = "roles/storage.admin"
86+
members = [
87+
"allUsers",
88+
]
89+
depends_on = [ google_storage_bucket.bucket ]
90+
}
91+
92+
resource "time_sleep" "wait_4000_seconds" {
93+
depends_on = [google_storage_bucket.bucket]
94+
destroy_duration = "4000s"
95+
}
96+
97+
resource "google_storage_anywhere_cache" "cache" {
98+
bucket = google_storage_bucket.bucket.name
99+
zone = "us-central1-f"
100+
admission_policy = "admit-on-second-miss"
101+
ttl = "100000s"
102+
depends_on = [ google_storage_bucket_iam_binding.binding ]
103+
}
104+
`, context)
105+
}

0 commit comments

Comments
 (0)