@@ -25,11 +25,12 @@ import (
2525
2626func TestExtractAndDefaultParameters (t * testing.T ) {
2727 tests := []struct {
28- name string
29- parameters map [string ]string
30- labels map [string ]string
31- expectParams DiskParameters
32- expectErr bool
28+ name string
29+ parameters map [string ]string
30+ labels map [string ]string
31+ enableStoragePools bool
32+ expectParams DiskParameters
33+ expectErr bool
3334 }{
3435 {
3536 name : "defaults" ,
@@ -202,9 +203,10 @@ func TestExtractAndDefaultParameters(t *testing.T) {
202203 },
203204 },
204205 {
205- name : "storage pool parameters" ,
206- parameters : map [string ]string {ParameterKeyType : "hyperdisk-balanced" , ParameterKeyStoragePools : "projects/my-project/zones/us-central1-a/storagePools/storagePool-1,projects/my-project/zones/us-central1-b/storagePools/storagePool-2" },
207- labels : map [string ]string {},
206+ name : "storage pool parameters" ,
207+ enableStoragePools : true ,
208+ parameters : map [string ]string {ParameterKeyType : "hyperdisk-balanced" , ParameterKeyStoragePools : "projects/my-project/zones/us-central1-a/storagePools/storagePool-1,projects/my-project/zones/us-central1-b/storagePools/storagePool-2" },
209+ labels : map [string ]string {},
208210 expectParams : DiskParameters {
209211 DiskType : "hyperdisk-balanced" ,
210212 ReplicationType : "none" ,
@@ -227,46 +229,59 @@ func TestExtractAndDefaultParameters(t *testing.T) {
227229 },
228230 },
229231 {
230- name : "invalid storage pool parameters, starts with /projects instead of projects" ,
231- parameters : map [string ]string {ParameterKeyType : "hyperdisk-balanced" , ParameterKeyStoragePools : "/projects/my-project/zones/us-central1-a/storagePools/storagePool-1" },
232- labels : map [string ]string {},
233- expectErr : true ,
232+ name : "invalid storage pool parameters, starts with /projects instead of projects" ,
233+ enableStoragePools : true ,
234+ parameters : map [string ]string {ParameterKeyType : "hyperdisk-balanced" , ParameterKeyStoragePools : "/projects/my-project/zones/us-central1-a/storagePools/storagePool-1" },
235+ labels : map [string ]string {},
236+ expectErr : true ,
234237 },
235238 {
236- name : "invalid storage pool parameters, missing projects" ,
237- parameters : map [string ]string {ParameterKeyType : "hyperdisk-balanced" , ParameterKeyStoragePools : "zones/us-central1-a/storagePools/storagePool-1" },
238- labels : map [string ]string {},
239- expectErr : true ,
239+ name : "invalid storage pool parameters, missing projects" ,
240+ enableStoragePools : true ,
241+ parameters : map [string ]string {ParameterKeyType : "hyperdisk-balanced" , ParameterKeyStoragePools : "zones/us-central1-a/storagePools/storagePool-1" },
242+ labels : map [string ]string {},
243+ expectErr : true ,
240244 },
241245 {
242- name : "invalid storage pool parameters, missing zones" ,
243- parameters : map [string ]string {ParameterKeyType : "hyperdisk-balanced" , ParameterKeyStoragePools : "projects/my-project/storagePools/storagePool-1" },
244- labels : map [string ]string {},
245- expectErr : true ,
246+ name : "invalid storage pool parameters, missing zones" ,
247+ enableStoragePools : true ,
248+ parameters : map [string ]string {ParameterKeyType : "hyperdisk-balanced" , ParameterKeyStoragePools : "projects/my-project/storagePools/storagePool-1" },
249+ labels : map [string ]string {},
250+ expectErr : true ,
246251 },
247252 {
248- name : "invalid storage pool parameters, duplicate projects" ,
249- parameters : map [string ]string {ParameterKeyType : "hyperdisk-balanced" , ParameterKeyStoragePools : "projects/my-project/projects/my-project/storagePools/storagePool-1" },
250- labels : map [string ]string {},
251- expectErr : true ,
253+ name : "invalid storage pool parameters, duplicate projects" ,
254+ enableStoragePools : true ,
255+ parameters : map [string ]string {ParameterKeyType : "hyperdisk-balanced" , ParameterKeyStoragePools : "projects/my-project/projects/my-project/storagePools/storagePool-1" },
256+ labels : map [string ]string {},
257+ expectErr : true ,
252258 },
253259 {
254- name : "invalid storage pool parameters, duplicate zones" ,
255- parameters : map [string ]string {ParameterKeyType : "hyperdisk-balanced" , ParameterKeyStoragePools : "zones/us-central1-a/zones/us-central1-a/storagePools/storagePool-1" },
256- labels : map [string ]string {},
257- expectErr : true ,
260+ name : "invalid storage pool parameters, duplicate zones" ,
261+ enableStoragePools : true ,
262+ parameters : map [string ]string {ParameterKeyType : "hyperdisk-balanced" , ParameterKeyStoragePools : "zones/us-central1-a/zones/us-central1-a/storagePools/storagePool-1" },
263+ labels : map [string ]string {},
264+ expectErr : true ,
258265 },
259266 {
260- name : "invalid storage pool parameters, duplicate storagePools" ,
261- parameters : map [string ]string {ParameterKeyType : "hyperdisk-balanced" , ParameterKeyStoragePools : "projects/my-project/storagePools/us-central1-a/storagePools/storagePool-1" },
262- labels : map [string ]string {},
263- expectErr : true ,
267+ name : "invalid storage pool parameters, duplicate storagePools" ,
268+ enableStoragePools : true ,
269+ parameters : map [string ]string {ParameterKeyType : "hyperdisk-balanced" , ParameterKeyStoragePools : "projects/my-project/storagePools/us-central1-a/storagePools/storagePool-1" },
270+ labels : map [string ]string {},
271+ expectErr : true ,
272+ },
273+ {
274+ name : "storage pool parameters, enableStoragePools is false" ,
275+ enableStoragePools : false ,
276+ parameters : map [string ]string {ParameterKeyType : "hyperdisk-balanced" , ParameterKeyStoragePools : "projects/my-project/zones/us-central1-a/storagePools/storagePool-1,projects/my-project/zones/us-central1-b/storagePools/storagePool-2" },
277+ labels : map [string ]string {},
278+ expectErr : true ,
264279 },
265280 }
266281
267282 for _ , tc := range tests {
268283 t .Run (tc .name , func (t * testing.T ) {
269- p , err := ExtractAndDefaultParameters (tc .parameters , "testDriver" , tc .labels )
284+ p , err := ExtractAndDefaultParameters (tc .parameters , "testDriver" , tc .labels , tc . enableStoragePools )
270285 if gotErr := err != nil ; gotErr != tc .expectErr {
271286 t .Fatalf ("ExtractAndDefaultParameters(%+v) = %v; expectedErr: %v" , tc .parameters , err , tc .expectErr )
272287 }
0 commit comments