Skip to content

Commit a36687d

Browse files
committed
fix tests
1 parent 2859cb3 commit a36687d

8 files changed

Lines changed: 38 additions & 43 deletions

File tree

internal/cmd/network-area/network-range/create/create_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4949
},
5050
OrganizationId: utils.Ptr(testOrgId),
5151
NetworkAreaId: utils.Ptr(testNetworkAreaId),
52-
NetworkRange: utils.Ptr("1.1.1.0/24"),
52+
NetworkRange: "1.1.1.0/24",
5353
}
5454
for _, mod := range mods {
5555
mod(model)
@@ -58,7 +58,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5858
}
5959

6060
func fixtureRequest(mods ...func(request *iaas.ApiCreateNetworkAreaRangeRequest)) iaas.ApiCreateNetworkAreaRangeRequest {
61-
request := testClient.CreateNetworkAreaRange(testCtx, testOrgId, testNetworkAreaId, testRegion)
61+
request := testClient.DefaultAPI.CreateNetworkAreaRange(testCtx, testOrgId, testNetworkAreaId, testRegion)
6262
request = request.CreateNetworkAreaRangePayload(fixturePayload())
6363
for _, mod := range mods {
6464
mod(&request)
@@ -68,9 +68,9 @@ func fixtureRequest(mods ...func(request *iaas.ApiCreateNetworkAreaRangeRequest)
6868

6969
func fixturePayload(mods ...func(payload *iaas.CreateNetworkAreaRangePayload)) iaas.CreateNetworkAreaRangePayload {
7070
payload := iaas.CreateNetworkAreaRangePayload{
71-
Ipv4: &[]iaas.NetworkRange{
71+
Ipv4: []iaas.NetworkRange{
7272
{
73-
Prefix: utils.Ptr("1.1.1.0/24"),
73+
Prefix: "1.1.1.0/24",
7474
},
7575
},
7676
}
@@ -177,7 +177,7 @@ func TestBuildRequest(t *testing.T) {
177177

178178
diff := cmp.Diff(request, tt.expectedRequest,
179179
cmp.AllowUnexported(tt.expectedRequest),
180-
cmpopts.EquateComparable(testCtx),
180+
cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}),
181181
)
182182
if diff != "" {
183183
t.Fatalf("Data does not match: %s", diff)

internal/cmd/network-area/route/update/update_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st
5454

5555
func fixturePayload(mods ...func(payload *iaas.UpdateNetworkAreaRoutePayload)) iaas.UpdateNetworkAreaRoutePayload {
5656
payload := iaas.UpdateNetworkAreaRoutePayload{
57-
Labels: &map[string]interface{}{
57+
Labels: map[string]any{
5858
"value": "key",
5959
},
6060
}
@@ -65,10 +65,10 @@ func fixturePayload(mods ...func(payload *iaas.UpdateNetworkAreaRoutePayload)) i
6565
return payload
6666
}
6767

68-
func fixturePayloadAsStringMap() map[string]string {
68+
func fixturePayloadAsMap() map[string]any {
6969
payload := fixturePayload()
70-
labelsMap := make(map[string]string)
71-
for k, v := range *payload.Labels {
70+
labelsMap := make(map[string]any)
71+
for k, v := range payload.Labels {
7272
if value, ok := v.(string); ok {
7373
labelsMap[k] = value
7474
}
@@ -77,7 +77,7 @@ func fixturePayloadAsStringMap() map[string]string {
7777
}
7878

7979
func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
80-
payload := fixturePayloadAsStringMap()
80+
payload := fixturePayloadAsMap()
8181
model := &inputModel{
8282
GlobalFlagModel: &globalflags.GlobalFlagModel{
8383
Verbosity: globalflags.VerbosityDefault,
@@ -86,7 +86,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
8686
OrganizationId: utils.Ptr(testOrgId),
8787
NetworkAreaId: utils.Ptr(testNetworkAreaId),
8888
RouteId: testRouteId,
89-
Labels: utils.Ptr(payload),
89+
Labels: payload,
9090
}
9191
for _, mod := range mods {
9292
mod(model)
@@ -95,7 +95,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
9595
}
9696

9797
func fixtureRequest(mods ...func(request *iaas.ApiUpdateNetworkAreaRouteRequest)) iaas.ApiUpdateNetworkAreaRouteRequest {
98-
request := testClient.UpdateNetworkAreaRoute(testCtx, testOrgId, testNetworkAreaId, testRegion, testRouteId)
98+
request := testClient.DefaultAPI.UpdateNetworkAreaRoute(testCtx, testOrgId, testNetworkAreaId, testRegion, testRouteId)
9999
request = request.UpdateNetworkAreaRoutePayload(fixturePayload())
100100
for _, mod := range mods {
101101
mod(&request)
@@ -268,7 +268,7 @@ func TestBuildRequest(t *testing.T) {
268268

269269
diff := cmp.Diff(request, tt.expectedRequest,
270270
cmp.AllowUnexported(tt.expectedRequest),
271-
cmpopts.EquateComparable(testCtx),
271+
cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}),
272272
)
273273
if diff != "" {
274274
t.Fatalf("Data does not match: %s", diff)

internal/cmd/network-area/routingtable/route/describe/describe_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,6 @@ func TestOutputResult(t *testing.T) {
196196
route: &iaas.Route{},
197197
wantErr: false,
198198
},
199-
{
200-
name: "json empty route",
201-
outputFormat: print.JSONOutputFormat,
202-
route: &iaas.Route{},
203-
wantErr: false,
204-
},
205199
{
206200
name: "pretty output with one route",
207201
outputFormat: print.PrettyOutputFormat,

internal/cmd/network-area/update/update_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func TestParseInput(t *testing.T) {
222222
delete(flagValues, labelFlag)
223223
}),
224224
expectedModel: fixtureInputModel(func(model *inputModel) {
225-
model.Labels = map[string]any{}
225+
model.Labels = nil
226226
}),
227227
isValid: true,
228228
},

internal/cmd/server/service-account/detach/detach_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func TestBuildRequest(t *testing.T) {
222222

223223
diff := cmp.Diff(request, tt.expectedRequest,
224224
cmp.AllowUnexported(tt.expectedRequest),
225-
cmpopts.EquateComparable(testCtx),
225+
cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}),
226226
)
227227
if diff != "" {
228228
t.Fatalf("Data does not match: %s", diff)

internal/cmd/volume/create/create.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ type inputModel struct {
4242
Labels map[string]any
4343
PerformanceClass *string
4444
Size *int64
45-
SourceId string
46-
SourceType string
45+
SourceId *string
46+
SourceType *string
4747
}
4848

4949
func NewCmd(params *types.CmdParams) *cobra.Command {
@@ -149,8 +149,8 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
149149
Labels: flags.FlagToStringToAny(p, cmd, labelFlag),
150150
PerformanceClass: flags.FlagToStringPointer(p, cmd, performanceClassFlag),
151151
Size: flags.FlagToInt64Pointer(p, cmd, sizeFlag),
152-
SourceId: flags.FlagToStringValue(p, cmd, sourceIdFlag),
153-
SourceType: flags.FlagToStringValue(p, cmd, sourceTypeFlag),
152+
SourceId: flags.FlagToStringPointer(p, cmd, sourceIdFlag),
153+
SourceType: flags.FlagToStringPointer(p, cmd, sourceTypeFlag),
154154
}
155155

156156
p.DebugInputModel(model)
@@ -159,10 +159,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
159159

160160
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiCreateVolumeRequest {
161161
req := apiClient.DefaultAPI.CreateVolume(ctx, model.ProjectId, model.Region)
162-
source := &iaas.VolumeSource{
163-
Id: model.SourceId,
164-
Type: model.SourceType,
165-
}
166162

167163
payload := iaas.CreateVolumePayload{
168164
AvailabilityZone: model.AvailabilityZone,
@@ -173,7 +169,12 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
173169
Size: model.Size,
174170
}
175171

176-
payload.Source = source
172+
if model.SourceId != nil && model.SourceType != nil {
173+
payload.Source = &iaas.VolumeSource{
174+
Id: *model.SourceId,
175+
Type: *model.SourceType,
176+
}
177+
}
177178

178179
return req.CreateVolumePayload(payload)
179180
}

internal/cmd/volume/create/create_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5959
Description: utils.Ptr("example-volume-description"),
6060
PerformanceClass: utils.Ptr("example-perf-class"),
6161
Size: utils.Ptr(int64(5)),
62-
SourceId: testSourceId,
63-
SourceType: "example-source-type",
62+
SourceId: &testSourceId,
63+
SourceType: utils.Ptr("example-source-type"),
6464
Labels: map[string]any{
6565
"key": "value",
6666
},
@@ -144,8 +144,8 @@ func TestParseInput(t *testing.T) {
144144
model.Labels = nil
145145
model.PerformanceClass = nil
146146
model.Size = nil
147-
model.SourceType = ""
148-
model.SourceId = ""
147+
model.SourceType = nil
148+
model.SourceId = nil
149149
}),
150150
},
151151
{
@@ -201,8 +201,8 @@ func TestParseInput(t *testing.T) {
201201
}),
202202
isValid: true,
203203
expectedModel: fixtureInputModel(func(model *inputModel) {
204-
model.SourceId = testSourceId
205-
model.SourceType = "example-source-type"
204+
model.SourceId = &testSourceId
205+
model.SourceType = utils.Ptr("example-source-type")
206206
}),
207207
},
208208
}

internal/cmd/volume/update/update_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6262
Name: utils.Ptr("example-volume-name"),
6363
Description: utils.Ptr("example-volume-desc"),
6464
VolumeId: testVolumeId,
65-
Labels: utils.Ptr(map[string]string{
65+
Labels: map[string]any{
6666
"key": "value",
67-
}),
67+
},
6868
}
6969
for _, mod := range mods {
7070
mod(model)
@@ -73,7 +73,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
7373
}
7474

7575
func fixtureRequest(mods ...func(request *iaas.ApiUpdateVolumeRequest)) iaas.ApiUpdateVolumeRequest {
76-
request := testClient.UpdateVolume(testCtx, testProjectId, testRegion, testVolumeId)
76+
request := testClient.DefaultAPI.UpdateVolume(testCtx, testProjectId, testRegion, testVolumeId)
7777
request = request.UpdateVolumePayload(fixturePayload())
7878
for _, mod := range mods {
7979
mod(&request)
@@ -85,9 +85,9 @@ func fixturePayload(mods ...func(payload *iaas.UpdateVolumePayload)) iaas.Update
8585
payload := iaas.UpdateVolumePayload{
8686
Name: utils.Ptr("example-volume-name"),
8787
Description: utils.Ptr("example-volume-desc"),
88-
Labels: utils.Ptr(map[string]interface{}{
88+
Labels: map[string]any{
8989
"key": "value",
90-
}),
90+
},
9191
}
9292
for _, mod := range mods {
9393
mod(&payload)
@@ -173,7 +173,7 @@ func TestParseInput(t *testing.T) {
173173
}),
174174
isValid: true,
175175
expectedModel: fixtureInputModel(func(model *inputModel) {
176-
model.Labels = &map[string]string{
176+
model.Labels = map[string]any{
177177
"key": "value",
178178
}
179179
}),
@@ -253,7 +253,7 @@ func TestBuildRequest(t *testing.T) {
253253

254254
diff := cmp.Diff(request, tt.expectedRequest,
255255
cmp.AllowUnexported(tt.expectedRequest),
256-
cmpopts.EquateComparable(testCtx),
256+
cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}),
257257
)
258258
if diff != "" {
259259
t.Fatalf("Data does not match: %s", diff)

0 commit comments

Comments
 (0)