Skip to content

Commit 05957fd

Browse files
committed
Add tests for storage_anywhere_cache
1 parent f81b3f1 commit 05957fd

File tree

3 files changed

+141
-0
lines changed

3 files changed

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

0 commit comments

Comments
 (0)