@@ -17,15 +17,8 @@ import (
1717 "github.com/stackitcloud/stackit-sdk-go/services/iaas"
1818)
1919
20- var projectIdFlag = globalflags .ProjectIdFlag
21-
22- type testCtxKey struct {}
23-
24- var (
25- testCtx = context .WithValue (context .Background (), testCtxKey {}, "foo" )
26- testClient = & iaas.APIClient {}
27- testProjectId = uuid .NewString ()
28-
20+ const (
21+ testRegion = "eu01"
2922 testLocalImagePath = "/does/not/exist"
3023 testDiskFormat = "raw"
3124 testDiskSize int64 = 16 * 1024 * 1024 * 1024
4942 testLabels = "foo=FOO,bar=BAR,baz=BAZ"
5043)
5144
45+ type testCtxKey struct {}
46+
47+ var (
48+ testCtx = context .WithValue (context .Background (), testCtxKey {}, "foo" )
49+ testClient = & iaas.APIClient {}
50+ testProjectId = uuid .NewString ()
51+ )
52+
5253func fixtureFlagValues (mods ... func (flagValues map [string ]string )) map [string ]string {
5354 flagValues := map [string ]string {
54- projectIdFlag : testProjectId ,
55+ globalflags .ProjectIdFlag : testProjectId ,
56+ globalflags .RegionFlag : testRegion ,
5557
5658 nameFlag : testName ,
5759 diskFormatFlag : testDiskFormat ,
@@ -93,30 +95,34 @@ func parseLabels(labelstring string) map[string]string {
9395
9496func fixtureInputModel (mods ... func (model * inputModel )) * inputModel {
9597 model := & inputModel {
96- GlobalFlagModel : & globalflags.GlobalFlagModel {ProjectId : testProjectId , Verbosity : globalflags .VerbosityDefault },
97- Name : testName ,
98- DiskFormat : testDiskFormat ,
99- LocalFilePath : testLocalImagePath ,
100- Labels : utils .Ptr (parseLabels (testLabels )),
98+ GlobalFlagModel : & globalflags.GlobalFlagModel {
99+ ProjectId : testProjectId ,
100+ Verbosity : globalflags .VerbosityDefault ,
101+ Region : testRegion ,
102+ },
103+ Name : testName ,
104+ DiskFormat : testDiskFormat ,
105+ LocalFilePath : testLocalImagePath ,
106+ Labels : utils .Ptr (parseLabels (testLabels )),
101107 Config : & imageConfig {
102- Architecture : & testArchitecture ,
103- BootMenu : & testBootmenu ,
104- CdromBus : & testCdRomBus ,
105- DiskBus : & testDiskBus ,
106- NicModel : & testNicModel ,
107- OperatingSystem : & testOperatingSystem ,
108- OperatingSystemDistro : & testOperatingSystemDistro ,
109- OperatingSystemVersion : & testOperatingSystemVersion ,
110- RescueBus : & testRescueBus ,
111- RescueDevice : & testRescueDevice ,
112- SecureBoot : & testSecureBoot ,
108+ Architecture : utils . Ptr ( testArchitecture ) ,
109+ BootMenu : utils . Ptr ( testBootmenu ) ,
110+ CdromBus : utils . Ptr ( testCdRomBus ) ,
111+ DiskBus : utils . Ptr ( testDiskBus ) ,
112+ NicModel : utils . Ptr ( testNicModel ) ,
113+ OperatingSystem : utils . Ptr ( testOperatingSystem ) ,
114+ OperatingSystemDistro : utils . Ptr ( testOperatingSystemDistro ) ,
115+ OperatingSystemVersion : utils . Ptr ( testOperatingSystemVersion ) ,
116+ RescueBus : utils . Ptr ( testRescueBus ) ,
117+ RescueDevice : utils . Ptr ( testRescueDevice ) ,
118+ SecureBoot : utils . Ptr ( testSecureBoot ) ,
113119 Uefi : testUefi ,
114- VideoModel : & testVideoModel ,
115- VirtioScsi : & testVirtioScsi ,
120+ VideoModel : utils . Ptr ( testVideoModel ) ,
121+ VirtioScsi : utils . Ptr ( testVirtioScsi ) ,
116122 },
117- MinDiskSize : & testDiskSize ,
118- MinRam : & testRamSize ,
119- Protected : & testProtected ,
123+ MinDiskSize : utils . Ptr ( testDiskSize ) ,
124+ MinRam : utils . Ptr ( testRamSize ) ,
125+ Protected : utils . Ptr ( testProtected ) ,
120126 }
121127 for _ , mod := range mods {
122128 mod (model )
@@ -127,31 +133,31 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
127133func fixtureCreatePayload (mods ... func (payload * iaas.CreateImagePayload )) (payload iaas.CreateImagePayload ) {
128134 payload = iaas.CreateImagePayload {
129135 Config : & iaas.ImageConfig {
130- Architecture : & testArchitecture ,
131- BootMenu : & testBootmenu ,
132- CdromBus : iaas .NewNullableString (& testCdRomBus ),
133- DiskBus : iaas .NewNullableString (& testDiskBus ),
134- NicModel : iaas .NewNullableString (& testNicModel ),
135- OperatingSystem : & testOperatingSystem ,
136- OperatingSystemDistro : iaas .NewNullableString (& testOperatingSystemDistro ),
137- OperatingSystemVersion : iaas .NewNullableString (& testOperatingSystemVersion ),
138- RescueBus : iaas .NewNullableString (& testRescueBus ),
139- RescueDevice : iaas .NewNullableString (& testRescueDevice ),
140- SecureBoot : & testSecureBoot ,
141- Uefi : & testUefi ,
142- VideoModel : iaas .NewNullableString (& testVideoModel ),
143- VirtioScsi : & testVirtioScsi ,
136+ Architecture : utils . Ptr ( testArchitecture ) ,
137+ BootMenu : utils . Ptr ( testBootmenu ) ,
138+ CdromBus : iaas .NewNullableString (utils . Ptr ( testCdRomBus ) ),
139+ DiskBus : iaas .NewNullableString (utils . Ptr ( testDiskBus ) ),
140+ NicModel : iaas .NewNullableString (utils . Ptr ( testNicModel ) ),
141+ OperatingSystem : utils . Ptr ( testOperatingSystem ) ,
142+ OperatingSystemDistro : iaas .NewNullableString (utils . Ptr ( testOperatingSystemDistro ) ),
143+ OperatingSystemVersion : iaas .NewNullableString (utils . Ptr ( testOperatingSystemVersion ) ),
144+ RescueBus : iaas .NewNullableString (utils . Ptr ( testRescueBus ) ),
145+ RescueDevice : iaas .NewNullableString (utils . Ptr ( testRescueDevice ) ),
146+ SecureBoot : utils . Ptr ( testSecureBoot ) ,
147+ Uefi : utils . Ptr ( testUefi ) ,
148+ VideoModel : iaas .NewNullableString (utils . Ptr ( testVideoModel ) ),
149+ VirtioScsi : utils . Ptr ( testVirtioScsi ) ,
144150 },
145- DiskFormat : & testDiskFormat ,
151+ DiskFormat : utils . Ptr ( testDiskFormat ) ,
146152 Labels : & map [string ]interface {}{
147153 "foo" : "FOO" ,
148154 "bar" : "BAR" ,
149155 "baz" : "BAZ" ,
150156 },
151- MinDiskSize : & testDiskSize ,
152- MinRam : & testRamSize ,
153- Name : & testName ,
154- Protected : & testProtected ,
157+ MinDiskSize : utils . Ptr ( testDiskSize ) ,
158+ MinRam : utils . Ptr ( testRamSize ) ,
159+ Name : utils . Ptr ( testName ) ,
160+ Protected : utils . Ptr ( testProtected ) ,
155161 }
156162 for _ , mod := range mods {
157163 mod (& payload )
@@ -160,7 +166,7 @@ func fixtureCreatePayload(mods ...func(payload *iaas.CreateImagePayload)) (paylo
160166}
161167
162168func fixtureRequest (mods ... func (request * iaas.ApiCreateImageRequest )) iaas.ApiCreateImageRequest {
163- request := testClient .CreateImage (testCtx , testProjectId )
169+ request := testClient .CreateImage (testCtx , testProjectId , testRegion )
164170
165171 request = request .CreateImagePayload (fixtureCreatePayload ())
166172
@@ -192,21 +198,21 @@ func TestParseInput(t *testing.T) {
192198 {
193199 description : "project id missing" ,
194200 flagValues : fixtureFlagValues (func (flagValues map [string ]string ) {
195- delete (flagValues , projectIdFlag )
201+ delete (flagValues , globalflags . ProjectIdFlag )
196202 }),
197203 isValid : false ,
198204 },
199205 {
200206 description : "project id invalid 1" ,
201207 flagValues : fixtureFlagValues (func (flagValues map [string ]string ) {
202- flagValues [projectIdFlag ] = ""
208+ flagValues [globalflags . ProjectIdFlag ] = ""
203209 }),
204210 isValid : false ,
205211 },
206212 {
207213 description : "project id invalid 2" ,
208214 flagValues : fixtureFlagValues (func (flagValues map [string ]string ) {
209- flagValues [projectIdFlag ] = "invalid-uuid"
215+ flagValues [globalflags . ProjectIdFlag ] = "invalid-uuid"
210216 }),
211217 isValid : false ,
212218 },
0 commit comments