Skip to content

Commit 434f580

Browse files
committed
adapted network area routes list command to align to expectations
1 parent 5c17195 commit 434f580

2 files changed

Lines changed: 17 additions & 15 deletions

File tree

internal/cmd/network-area/route/list/list.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,21 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7474
return fmt.Errorf("list static routes: %w", err)
7575
}
7676

77-
if resp.Items == nil || len(*resp.Items) == 0 {
78-
var networkAreaLabel string
79-
networkAreaLabel, err = iaasUtils.GetNetworkAreaName(ctx, apiClient, *model.OrganizationId, *model.NetworkAreaId)
80-
if err != nil {
81-
params.Printer.Debug(print.ErrorLevel, "get network area name: %v", err)
82-
networkAreaLabel = *model.NetworkAreaId
83-
}
84-
params.Printer.Info("No static routes found for STACKIT Network Area %q\n", networkAreaLabel)
85-
return nil
77+
items := resp.GetItems()
78+
79+
var networkAreaLabel string
80+
networkAreaLabel, err = iaasUtils.GetNetworkAreaName(ctx, apiClient, *model.OrganizationId, *model.NetworkAreaId)
81+
if err != nil {
82+
params.Printer.Debug(print.ErrorLevel, "get network area name: %v", err)
83+
networkAreaLabel = *model.NetworkAreaId
8684
}
8785

8886
// Truncate output
89-
items := *resp.Items
9087
if model.Limit != nil && len(items) > int(*model.Limit) {
9188
items = items[:*model.Limit]
9289
}
9390

94-
return outputResult(params.Printer, model.OutputFormat, items)
91+
return outputResult(params.Printer, model.OutputFormat, networkAreaLabel, items)
9592
},
9693
}
9794
configureFlags(cmd)
@@ -132,8 +129,12 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
132129
return apiClient.ListNetworkAreaRoutes(ctx, *model.OrganizationId, *model.NetworkAreaId, model.Region)
133130
}
134131

135-
func outputResult(p *print.Printer, outputFormat string, routes []iaas.Route) error {
132+
func outputResult(p *print.Printer, outputFormat, networkAreaLabel string, routes []iaas.Route) error {
136133
return p.OutputResult(outputFormat, routes, func() error {
134+
if len(routes) == 0 {
135+
p.Outputf("No static routes found for STACKIT Network Area %q\n", networkAreaLabel)
136+
return nil
137+
}
137138
table := tables.NewTable()
138139
table.SetHeader("Static Route ID", "Next Hop", "Next Hop Type", "Destination")
139140

internal/cmd/network-area/route/list/list_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,9 @@ func TestBuildRequest(t *testing.T) {
185185

186186
func TestOutputResult(t *testing.T) {
187187
type args struct {
188-
outputFormat string
189-
routes []iaas.Route
188+
outputFormat string
189+
networkAreaLabel string
190+
routes []iaas.Route
190191
}
191192
tests := []struct {
192193
name string
@@ -235,7 +236,7 @@ func TestOutputResult(t *testing.T) {
235236
p.Cmd = NewCmd(&types.CmdParams{Printer: p})
236237
for _, tt := range tests {
237238
t.Run(tt.name, func(t *testing.T) {
238-
if err := outputResult(p, tt.args.outputFormat, tt.args.routes); (err != nil) != tt.wantErr {
239+
if err := outputResult(p, tt.args.outputFormat, tt.args.networkAreaLabel, tt.args.routes); (err != nil) != tt.wantErr {
239240
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
240241
}
241242
})

0 commit comments

Comments
 (0)