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/dns/record-set/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *dns.APIClie
}

func outputResult(p *print.Printer, model *inputModel, zoneLabel string, resp *dns.RecordSetResponse) error {
if resp == nil {
return fmt.Errorf("record set response is empty")
}
switch model.OutputFormat {
case print.JSONOutputFormat:
details, err := json.MarshalIndent(resp, "", " ")
Expand Down
43 changes: 39 additions & 4 deletions internal/cmd/dns/record-set/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import (
"strings"
"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/dns"
)

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

func TestOutputResult(t *testing.T) {
type args struct {
model *inputModel
zoneLabel string
resp *dns.RecordSetResponse
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "empty",
args: args{},
wantErr: true,
},
{
name: "only record set as argument",
args: args{
model: fixtureInputModel(),
resp: &dns.RecordSetResponse{Rrset: &dns.RecordSet{}},
},
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.zoneLabel, tt.args.resp); (err != nil) != tt.wantErr {
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
3 changes: 3 additions & 0 deletions internal/cmd/dns/record-set/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *dns.APIClie
}

func outputResult(p *print.Printer, outputFormat string, recordSet *dns.RecordSet) error {
if recordSet == nil {
return fmt.Errorf("record set response is empty")
}
switch outputFormat {
case print.JSONOutputFormat:
details, err := json.MarshalIndent(recordSet, "", " ")
Expand Down
39 changes: 36 additions & 3 deletions internal/cmd/dns/record-set/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/dns"
)

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

func TestOutputResult(t *testing.T) {
type args struct {
outputFormat string
recordSet *dns.RecordSet
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "empty",
args: args{},
wantErr: true,
},
{
name: "only record set as argument",
args: args{
recordSet: &dns.RecordSet{Records: &[]dns.Record{}},
},
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.recordSet); (err != nil) != tt.wantErr {
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
34 changes: 30 additions & 4 deletions internal/cmd/dns/record-set/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import (
"strconv"
"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"
sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config"
"github.com/stackitcloud/stackit-sdk-go/services/dns"
)
Expand Down Expand Up @@ -501,3 +500,30 @@ func TestFetchRecordSets(t *testing.T) {
})
}
}

func TestOutputResult(t *testing.T) {
type args struct {
outputFormat string
recordSets []dns.RecordSet
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "empty",
args: args{},
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.recordSets); (err != nil) != tt.wantErr {
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
3 changes: 3 additions & 0 deletions internal/cmd/dns/zone/clone/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *dns.APIClie
}

func outputResult(p *print.Printer, model *inputModel, projectLabel string, resp *dns.ZoneResponse) error {
if resp == nil {
return fmt.Errorf("dns zone response is empty")
}
switch model.OutputFormat {
case print.JSONOutputFormat:
details, err := json.MarshalIndent(resp, "", " ")
Expand Down
43 changes: 39 additions & 4 deletions internal/cmd/dns/zone/clone/clone_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/dns"
)

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

func TestOutputResult(t *testing.T) {
type args struct {
model *inputModel
projectLabel string
resp *dns.ZoneResponse
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "empty",
args: args{},
wantErr: true,
},
{
name: "only zone response as argument",
args: args{
model: fixtureInputModel(),
resp: &dns.ZoneResponse{Zone: &dns.Zone{}},
},
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.resp); (err != nil) != tt.wantErr {
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
3 changes: 3 additions & 0 deletions internal/cmd/dns/zone/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *dns.APIClie
}

func outputResult(p *print.Printer, model *inputModel, projectLabel string, resp *dns.ZoneResponse) error {
if resp == nil {
return fmt.Errorf("dns zone response is empty")
}
switch model.OutputFormat {
case print.JSONOutputFormat:
details, err := json.MarshalIndent(resp, "", " ")
Expand Down
43 changes: 39 additions & 4 deletions internal/cmd/dns/zone/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/dns"
)

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

func TestOutputResult(t *testing.T) {
type args struct {
model *inputModel
projectLabel string
resp *dns.ZoneResponse
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "empty",
args: args{},
wantErr: true,
},
{
name: "only zone response as argument",
args: args{
model: fixtureInputModel(),
resp: &dns.ZoneResponse{Zone: &dns.Zone{}},
},
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.resp); (err != nil) != tt.wantErr {
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
3 changes: 3 additions & 0 deletions internal/cmd/dns/zone/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *dns.APIClie
}

func outputResult(p *print.Printer, outputFormat string, zone *dns.Zone) error {
if zone == nil {
return fmt.Errorf("zone response is empty")
}
switch outputFormat {
case print.JSONOutputFormat:
details, err := json.MarshalIndent(zone, "", " ")
Expand Down
39 changes: 36 additions & 3 deletions internal/cmd/dns/zone/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/dns"
)

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

func TestOutputResult(t *testing.T) {
type args struct {
outputFormat string
zone *dns.Zone
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "empty",
args: args{},
wantErr: true,
},
{
name: "only zone as argument",
args: args{
zone: &dns.Zone{},
},
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.zone); (err != nil) != tt.wantErr {
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
Loading
Loading