@@ -15,8 +15,10 @@ import (
15
15
)
16
16
17
17
const (
18
- volumeTestName = "test-volume"
19
- volumeTestSize = 1
18
+ volumeTestName = "test-volume"
19
+ volume1TestName = "test-volume-1"
20
+ volume2TestName = "test-volume-2"
21
+ volumeTestSize = 1
20
22
)
21
23
22
24
func TestAccVolumeDataSource (t * testing.T ) {
@@ -30,42 +32,72 @@ func TestAccVolumeDataSource(t *testing.T) {
30
32
t .Fatal (err )
31
33
}
32
34
33
- opts := volumes.CreateOpts {
34
- Name : volumeTestName ,
35
+ opts1 := volumes.CreateOpts {
36
+ Name : volume1TestName ,
35
37
Size : volumeTestSize ,
36
38
Source : volumes .NewVolume ,
37
39
TypeName : volumes .Standard ,
40
+ Metadata : map [string ]string {"key1" : "val1" , "key2" : "val2" },
38
41
}
39
42
40
- volumeID , err := createTestVolume (client , opts )
43
+ volume1ID , err := createTestVolume (client , opts1 )
41
44
if err != nil {
42
45
t .Fatal (err )
43
46
}
44
47
45
- defer volumes .Delete (client , volumeID , volumes.DeleteOpts {})
48
+ opts2 := volumes.CreateOpts {
49
+ Name : volume2TestName ,
50
+ Size : volumeTestSize ,
51
+ Source : volumes .NewVolume ,
52
+ TypeName : volumes .Standard ,
53
+ Metadata : map [string ]string {"key1" : "val1" , "key3" : "val3" },
54
+ }
55
+
56
+ volume2ID , err := createTestVolume (client , opts2 )
57
+ if err != nil {
58
+ t .Fatal (err )
59
+ }
60
+
61
+ defer volumes .Delete (client , volume1ID , volumes.DeleteOpts {})
62
+ defer volumes .Delete (client , volume2ID , volumes.DeleteOpts {})
46
63
47
64
fullName := "data.gcore_volume.acctest"
48
- tpl := func (name string ) string {
65
+ tpl := func (name string , metaQuery string ) string {
49
66
return fmt .Sprintf (`
50
67
data "gcore_volume" "acctest" {
51
68
%s
52
69
%s
53
70
name = "%s"
71
+ %s
54
72
}
55
- ` , projectInfo (), regionInfo (), name )
73
+ ` , projectInfo (), regionInfo (), name , metaQuery )
56
74
}
57
75
58
76
resource .Test (t , resource.TestCase {
59
77
PreCheck : func () { testAccPreCheck (t ) },
60
78
ProviderFactories : testAccProviders ,
61
79
Steps : []resource.TestStep {
62
80
{
63
- Config : tpl (opts .Name ),
81
+ Config : tpl (opts1 .Name , `metadata_k="key1"` ),
82
+ Check : resource .ComposeTestCheckFunc (
83
+ testAccCheckResourceExists (fullName ),
84
+ resource .TestCheckResourceAttr (fullName , "name" , opts1 .Name ),
85
+ resource .TestCheckResourceAttr (fullName , "id" , volume1ID ),
86
+ resource .TestCheckResourceAttr (fullName , "size" , strconv .Itoa (opts1 .Size )),
87
+ testAccCheckMetadata (fullName , true , map [string ]string {
88
+ "key1" : "val1" , "key2" : "val2" }),
89
+ ),
90
+ },
91
+ {
92
+ Config : tpl (opts2 .Name , `metadata_kv={key3 = "val3"}` ),
64
93
Check : resource .ComposeTestCheckFunc (
65
94
testAccCheckResourceExists (fullName ),
66
- resource .TestCheckResourceAttr (fullName , "name" , opts .Name ),
67
- resource .TestCheckResourceAttr (fullName , "id" , volumeID ),
68
- resource .TestCheckResourceAttr (fullName , "size" , strconv .Itoa (opts .Size )),
95
+ resource .TestCheckResourceAttr (fullName , "name" , opts2 .Name ),
96
+ resource .TestCheckResourceAttr (fullName , "id" , volume2ID ),
97
+ resource .TestCheckResourceAttr (fullName , "size" , strconv .Itoa (opts2 .Size )),
98
+ testAccCheckMetadata (fullName , true , map [string ]string {
99
+ "key3" : "val3" ,
100
+ }),
69
101
),
70
102
},
71
103
},
0 commit comments