@@ -33,15 +33,24 @@ import (
33
33
grpcstatus "google.golang.org/grpc/status"
34
34
)
35
35
36
+ // testName generates a unique name for testing purposes by creating a new UUID.
37
+ // It returns the UUID as a string or fails the test if UUID generation fails.
36
38
func testName (t * testing.T ) string {
39
+ t .Helper ()
40
+
37
41
u , err := uuid .NewV4 ()
38
42
if err != nil {
39
43
t .Fatalf ("testName: failed to generate uuid: %v" , err )
40
44
}
41
45
return u .String ()
42
46
}
43
47
48
+ // testLocation retrieves the location for testing purposes from the environment variable
49
+ // GOLANG_REGIONAL_SAMPLES_LOCATION. If the environment variable is not set,
50
+ // the test is skipped.
44
51
func testLocation (t * testing.T ) string {
52
+ t .Helper ()
53
+
45
54
v := os .Getenv ("GOLANG_REGIONAL_SAMPLES_LOCATION" )
46
55
if v == "" {
47
56
t .Skip ("testLocation: missing GOLANG_REGIONAL_SAMPLES_LOCATION" )
@@ -50,7 +59,10 @@ func testLocation(t *testing.T) string {
50
59
return v
51
60
}
52
61
62
+ // testParameterWithKmsKey creates a parameter with a KMS key in the specified GCP project.
63
+ // It returns the created parameter and its ID or fails the test if parameter creation fails.
53
64
func testParameterWithKmsKey (t * testing.T , projectID , kms_key string ) (* parametermanagerpb.Parameter , string ) {
65
+ t .Helper ()
54
66
parameterID := testName (t )
55
67
locationId := testLocation (t )
56
68
@@ -78,7 +90,10 @@ func testParameterWithKmsKey(t *testing.T, projectID, kms_key string) (*paramete
78
90
return parameter , parameterID
79
91
}
80
92
93
+ // testCleanupParameter deletes the specified parameter in the GCP project.
94
+ // It fails the test if the parameter deletion fails.
81
95
func testCleanupParameter (t * testing.T , name string ) {
96
+ t .Helper ()
82
97
locationId := testLocation (t )
83
98
ctx := context .Background ()
84
99
@@ -98,7 +113,10 @@ func testCleanupParameter(t *testing.T, name string) {
98
113
}
99
114
}
100
115
116
+ // testCleanupKeyVersions deletes the specified key version in the GCP project.
117
+ // It fails the test if the key version deletion fails.
101
118
func testCleanupKeyVersions (t * testing.T , name string ) {
119
+ t .Helper ()
102
120
ctx := context .Background ()
103
121
104
122
client , err := kms .NewKeyManagementClient (ctx )
@@ -116,7 +134,10 @@ func testCleanupKeyVersions(t *testing.T, name string) {
116
134
}
117
135
}
118
136
137
+ // testCreateKeyRing creates a key ring in the specified GCP project.
138
+ // It fails the test if the key ring creation fails.
119
139
func testCreateKeyRing (t * testing.T , projectID , keyRingId string ) {
140
+ t .Helper ()
120
141
ctx := context .Background ()
121
142
locationID := testLocation (t )
122
143
@@ -149,7 +170,10 @@ func testCreateKeyRing(t *testing.T, projectID, keyRingId string) {
149
170
}
150
171
}
151
172
173
+ // testCreateKeyHSM creates a HSM key in the specified key ring in the GCP project.
174
+ // It fails the test if the key creation fails.
152
175
func testCreateKeyHSM (t * testing.T , projectID , keyRing , id string ) {
176
+ t .Helper ()
153
177
ctx := context .Background ()
154
178
locationID := testLocation (t )
155
179
client , err := kms .NewKeyManagementClient (ctx )
@@ -188,6 +212,8 @@ func testCreateKeyHSM(t *testing.T, projectID, keyRing, id string) {
188
212
}
189
213
}
190
214
215
+ // TestCreateRegionalParamWithKmsKey tests the createRegionalParamWithKmsKey function by creating a regional parameter with a KMS key,
216
+ // and verifies if the parameter was successfully created by checking the output.
191
217
func TestCreateRegionalParamWithKmsKey (t * testing.T ) {
192
218
tc := testutil .SystemTest (t )
193
219
@@ -211,6 +237,8 @@ func TestCreateRegionalParamWithKmsKey(t *testing.T) {
211
237
}
212
238
}
213
239
240
+ // TestUpdateRegionalParamKmsKey tests the updateRegionalParamKmsKey function by creating a regional parameter with a KMS key,
241
+ // updating the KMS key, and verifying if the parameter was successfully updated by checking the output.
214
242
func TestUpdateRegionalParamKmsKey (t * testing.T ) {
215
243
tc := testutil .SystemTest (t )
216
244
@@ -234,6 +262,8 @@ func TestUpdateRegionalParamKmsKey(t *testing.T) {
234
262
}
235
263
}
236
264
265
+ // TestRemoveRegionalParamKmsKey tests the removeRegionalParamKmsKey function by creating a regional parameter with a KMS key,
266
+ // removing the KMS key, and verifying if the KMS key was successfully removed by checking the output.
237
267
func TestRemoveRegionalParamKmsKey (t * testing.T ) {
238
268
tc := testutil .SystemTest (t )
239
269
0 commit comments