Skip to content

Commit bf42372

Browse files
committed
fix: integrate review findings
1 parent 3d2c0fd commit bf42372

File tree

4 files changed

+22
-41
lines changed

4 files changed

+22
-41
lines changed

internal/cmd/postgresflex/instance/update/update.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
118118
s.Stop()
119119
}
120120

121-
return outputResult(p, model.OutputFormat, model.Async, model, instanceLabel, resp)
121+
return outputResult(p, model.OutputFormat, model.Async, instanceLabel, resp)
122122
},
123123
}
124124
configureFlags(cmd)
@@ -307,10 +307,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient PostgreSQLFl
307307
return req, nil
308308
}
309309

310-
func outputResult(p *print.Printer, outputFormat string, async bool, model *inputModel, instanceLabel string, resp *postgresflex.PartialUpdateInstanceResponse) error {
311-
if model == nil {
312-
return fmt.Errorf("no model passsed")
313-
}
310+
func outputResult(p *print.Printer, outputFormat string, async bool, instanceLabel string, resp *postgresflex.PartialUpdateInstanceResponse) error {
314311
if resp == nil {
315312
return fmt.Errorf("no response passed")
316313
}

internal/cmd/postgresflex/instance/update/update_test.go

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,6 @@ func TestBuildRequest(t *testing.T) {
593593
func Test_outputResult(t *testing.T) {
594594
type args struct {
595595
outputFormat string
596-
model *inputModel
597596
instanceLabel string
598597
resp *postgresflex.PartialUpdateInstanceResponse
599598
}
@@ -603,29 +602,14 @@ func Test_outputResult(t *testing.T) {
603602
wantErr bool
604603
}{
605604
{"empty model", args{}, true},
606-
{"empty response", args{outputFormat: "", model: &inputModel{}}, true},
605+
{"empty response", args{outputFormat: ""}, true},
607606
{"standard", args{
608607
outputFormat: "",
609-
model: &inputModel{},
610608
instanceLabel: "test",
611609
resp: &postgresflex.PartialUpdateInstanceResponse{},
612610
}, false},
613611
{"complet", args{
614-
outputFormat: "",
615-
model: &inputModel{
616-
GlobalFlagModel: &globalflags.GlobalFlagModel{},
617-
InstanceId: testInstanceId,
618-
InstanceName: new(string),
619-
ACL: &[]string{},
620-
BackupSchedule: new(string),
621-
FlavorId: new(string),
622-
CPU: new(int64),
623-
RAM: new(int64),
624-
StorageClass: new(string),
625-
StorageSize: new(int64),
626-
Version: new(string),
627-
Type: new(string),
628-
},
612+
outputFormat: "",
629613
instanceLabel: "test",
630614
resp: &postgresflex.PartialUpdateInstanceResponse{
631615
Item: &postgresflex.Instance{},
@@ -637,7 +621,7 @@ func Test_outputResult(t *testing.T) {
637621

638622
for _, tt := range tests {
639623
t.Run(tt.name, func(t *testing.T) {
640-
if err := outputResult(p, tt.args.outputFormat, true, tt.args.model, tt.args.instanceLabel, tt.args.resp); (err != nil) != tt.wantErr {
624+
if err := outputResult(p, tt.args.outputFormat, true, tt.args.instanceLabel, tt.args.resp); (err != nil) != tt.wantErr {
641625
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
642626
}
643627
})

internal/cmd/postgresflex/options/options.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,17 @@ func buildAndExecuteRequest(ctx context.Context, p *print.Printer, model *inputM
166166
}
167167
}
168168

169-
return outputResult(p, model.OutputFormat, *model, flavors, versions, storages)
169+
return outputResult(p, *model, flavors, versions, storages)
170170
}
171171

172-
func outputResult(p *print.Printer, outputFormat string, model inputModel, flavors *postgresflex.ListFlavorsResponse, versions *postgresflex.ListVersionsResponse, storages *postgresflex.ListStoragesResponse) error {
172+
func outputResult(p *print.Printer, model inputModel, flavors *postgresflex.ListFlavorsResponse, versions *postgresflex.ListVersionsResponse, storages *postgresflex.ListStoragesResponse) error {
173173
options := &options{}
174174
if flavors != nil {
175175
options.Flavors = flavors.Flavors
176176
}
177+
if model.GlobalFlagModel == nil {
178+
return fmt.Errorf("no global model defined")
179+
}
177180
if versions != nil {
178181
options.Versions = versions.Versions
179182
}
@@ -184,7 +187,7 @@ func outputResult(p *print.Printer, outputFormat string, model inputModel, flavo
184187
}
185188
}
186189

187-
switch outputFormat {
190+
switch model.OutputFormat {
188191
case print.JSONOutputFormat:
189192
details, err := json.MarshalIndent(options, "", " ")
190193
if err != nil {

internal/cmd/postgresflex/options/options_test.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -324,30 +324,27 @@ func TestBuildAndExecuteRequest(t *testing.T) {
324324

325325
func Test_outputResult(t *testing.T) {
326326
type args struct {
327-
outputFormat string
328-
model inputModel
329-
flavors *postgresflex.ListFlavorsResponse
330-
versions *postgresflex.ListVersionsResponse
331-
storages *postgresflex.ListStoragesResponse
327+
model inputModel
328+
flavors *postgresflex.ListFlavorsResponse
329+
versions *postgresflex.ListVersionsResponse
330+
storages *postgresflex.ListStoragesResponse
332331
}
333332
tests := []struct {
334333
name string
335334
args args
336335
wantErr bool
337336
}{
338-
{"empty", args{}, false},
337+
{"empty", args{model: inputModel{GlobalFlagModel: &globalflags.GlobalFlagModel{}}}, false},
339338
{"standard", args{
340-
outputFormat: "",
341-
model: inputModel{},
342-
flavors: &postgresflex.ListFlavorsResponse{},
343-
versions: &postgresflex.ListVersionsResponse{},
344-
storages: &postgresflex.ListStoragesResponse{},
339+
model: inputModel{GlobalFlagModel: &globalflags.GlobalFlagModel{}},
340+
flavors: &postgresflex.ListFlavorsResponse{},
341+
versions: &postgresflex.ListVersionsResponse{},
342+
storages: &postgresflex.ListStoragesResponse{},
345343
}, false},
346344
{
347345
"complete",
348346
args{
349-
outputFormat: "",
350-
model: inputModel{GlobalFlagModel: &globalflags.GlobalFlagModel{}, Flavors: false, Versions: false, Storages: false, FlavorId: new(string)},
347+
model: inputModel{GlobalFlagModel: &globalflags.GlobalFlagModel{}, Flavors: false, Versions: false, Storages: false, FlavorId: new(string)},
351348
flavors: &postgresflex.ListFlavorsResponse{
352349
Flavors: &[]postgresflex.Flavor{},
353350
},
@@ -366,7 +363,7 @@ func Test_outputResult(t *testing.T) {
366363
p.Cmd = NewCmd(p)
367364
for _, tt := range tests {
368365
t.Run(tt.name, func(t *testing.T) {
369-
if err := outputResult(p, tt.args.outputFormat, tt.args.model, tt.args.flavors, tt.args.versions, tt.args.storages); (err != nil) != tt.wantErr {
366+
if err := outputResult(p, tt.args.model, tt.args.flavors, tt.args.versions, tt.args.storages); (err != nil) != tt.wantErr {
370367
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
371368
}
372369
})

0 commit comments

Comments
 (0)