Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/cmd/beta/volume/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
}

func outputResult(p *print.Printer, model *inputModel, projectLabel string, volume *iaas.Volume) error {
if volume == nil {
return fmt.Errorf("volume response is empty")
}
switch model.OutputFormat {
case print.JSONOutputFormat:
details, err := json.MarshalIndent(volume, "", " ")
Expand Down
43 changes: 39 additions & 4 deletions internal/cmd/beta/volume/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"context"
"testing"

"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/google/uuid"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
)

Expand Down Expand Up @@ -284,3 +283,39 @@ func TestBuildRequest(t *testing.T) {
})
}
}

func TestOutputResult(t *testing.T) {
type args struct {
model *inputModel
projectLabel string
volume *iaas.Volume
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "empty",
args: args{},
wantErr: true,
},
{
name: "volume as argument",
args: args{
model: fixtureInputModel(),
volume: &iaas.Volume{},
},
wantErr: false,
},
}
p := print.NewPrinter()
p.Cmd = NewCmd(p)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := outputResult(p, tt.args.model, tt.args.projectLabel, tt.args.volume); (err != nil) != tt.wantErr {
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
6 changes: 4 additions & 2 deletions internal/cmd/beta/volume/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ func NewCmd(p *print.Printer) *cobra.Command {
return err
}

volumeLabel, err := iaasUtils.GetVolumeName(ctx, apiClient, model.ProjectId, model.VolumeId)
volumeLabel := model.VolumeId
volumeName, err := iaasUtils.GetVolumeName(ctx, apiClient, model.ProjectId, model.VolumeId)
if err != nil {
p.Debug(print.ErrorLevel, "get volume name: %v", err)
volumeLabel = model.VolumeId
} else if volumeName != "" {
volumeLabel = volumeName
}

if !model.AssumeYes {
Expand Down
3 changes: 3 additions & 0 deletions internal/cmd/beta/volume/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
}

func outputResult(p *print.Printer, outputFormat string, volume *iaas.Volume) error {
if volume == nil {
return fmt.Errorf("volume response is empty")
}
switch outputFormat {
case print.JSONOutputFormat:
details, err := json.MarshalIndent(volume, "", " ")
Expand Down
39 changes: 36 additions & 3 deletions internal/cmd/beta/volume/describe/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import (
"context"
"testing"

"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/google/uuid"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
)

Expand Down Expand Up @@ -216,3 +215,37 @@ func TestBuildRequest(t *testing.T) {
})
}
}

func TestOutputResult(t *testing.T) {
type args struct {
outputFormat string
volume *iaas.Volume
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "empty",
args: args{},
wantErr: true,
},
{
name: "volume as argument",
args: args{
volume: &iaas.Volume{},
},
wantErr: false,
},
}
p := print.NewPrinter()
p.Cmd = NewCmd(p)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := outputResult(p, tt.args.outputFormat, tt.args.volume); (err != nil) != tt.wantErr {
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
41 changes: 37 additions & 4 deletions internal/cmd/beta/volume/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"context"
"testing"

"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/google/uuid"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
)

Expand Down Expand Up @@ -202,3 +201,37 @@ func TestBuildRequest(t *testing.T) {
})
}
}

func TestOutputResult(t *testing.T) {
type args struct {
outputFormat string
volumes []iaas.Volume
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "empty",
args: args{},
wantErr: false,
},
{
name: "set empty volume",
args: args{
volumes: []iaas.Volume{{}},
},
wantErr: false,
},
}
p := print.NewPrinter()
p.Cmd = NewCmd(p)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := outputResult(p, tt.args.outputFormat, tt.args.volumes); (err != nil) != tt.wantErr {
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
}

func outputResult(p *print.Printer, outputFormat string, performanceClass *iaas.VolumePerformanceClass) error {
if performanceClass == nil {
return fmt.Errorf("performanceClass response is empty")
}
switch outputFormat {
case print.JSONOutputFormat:
details, err := json.MarshalIndent(performanceClass, "", " ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import (
"context"
"testing"

"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/google/uuid"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
)

Expand Down Expand Up @@ -210,3 +209,37 @@ func TestBuildRequest(t *testing.T) {
})
}
}

func TestOutputResult(t *testing.T) {
type args struct {
outputFormat string
performanceClass *iaas.VolumePerformanceClass
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "empty",
args: args{},
wantErr: true,
},
{
name: "volume performance class as argument",
args: args{
performanceClass: &iaas.VolumePerformanceClass{},
},
wantErr: false,
},
}
p := print.NewPrinter()
p.Cmd = NewCmd(p)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := outputResult(p, tt.args.outputFormat, tt.args.performanceClass); (err != nil) != tt.wantErr {
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
41 changes: 37 additions & 4 deletions internal/cmd/beta/volume/performance-class/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"context"
"testing"

"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/google/uuid"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
)

Expand Down Expand Up @@ -202,3 +201,37 @@ func TestBuildRequest(t *testing.T) {
})
}
}

func TestOutputResult(t *testing.T) {
type args struct {
outputFormat string
performanceClasses []iaas.VolumePerformanceClass
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "empty",
args: args{},
wantErr: false,
},
{
name: "set empty volume",
args: args{
performanceClasses: []iaas.VolumePerformanceClass{{}},
},
wantErr: false,
},
}
p := print.NewPrinter()
p.Cmd = NewCmd(p)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := outputResult(p, tt.args.outputFormat, tt.args.performanceClasses); (err != nil) != tt.wantErr {
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
9 changes: 6 additions & 3 deletions internal/cmd/beta/volume/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
return fmt.Errorf("update volume: %w", err)
}

return outputResult(p, model, volumeLabel, resp)
return outputResult(p, model.OutputFormat, volumeLabel, resp)
},
}
configureFlags(cmd)
Expand Down Expand Up @@ -152,8 +152,11 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
return req.UpdateVolumePayload(payload)
}

func outputResult(p *print.Printer, model *inputModel, volumeLabel string, volume *iaas.Volume) error {
switch model.OutputFormat {
func outputResult(p *print.Printer, outputFormat, volumeLabel string, volume *iaas.Volume) error {
if volume == nil {
return fmt.Errorf("volume response is empty")
}
switch outputFormat {
case print.JSONOutputFormat:
details, err := json.MarshalIndent(volume, "", " ")
if err != nil {
Expand Down
42 changes: 38 additions & 4 deletions internal/cmd/beta/volume/update/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"context"
"testing"

"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/google/uuid"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
)

Expand Down Expand Up @@ -255,3 +254,38 @@ func TestBuildRequest(t *testing.T) {
})
}
}

func TestOutputResult(t *testing.T) {
type args struct {
outputFormat string
volumeLabel string
volume *iaas.Volume
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "empty",
args: args{},
wantErr: true,
},
{
name: "volume as argument",
args: args{
volume: &iaas.Volume{},
},
wantErr: false,
},
}
p := print.NewPrinter()
p.Cmd = NewCmd(p)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := outputResult(p, tt.args.outputFormat, tt.args.volumeLabel, tt.args.volume); (err != nil) != tt.wantErr {
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
Loading