Skip to content

Commit b663d3d

Browse files
committed
adapted network area routes list command to align to expectations
1 parent 48e9f80 commit b663d3d

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
@@ -183,8 +183,9 @@ func TestBuildRequest(t *testing.T) {
183183

184184
func TestOutputResult(t *testing.T) {
185185
type args struct {
186-
outputFormat string
187-
routes []iaas.Route
186+
outputFormat string
187+
networkAreaLabel string
188+
routes []iaas.Route
188189
}
189190
tests := []struct {
190191
name string
@@ -232,7 +233,7 @@ func TestOutputResult(t *testing.T) {
232233
params := testparams.NewTestParams()
233234
for _, tt := range tests {
234235
t.Run(tt.name, func(t *testing.T) {
235-
if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.routes); (err != nil) != tt.wantErr {
236+
if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.networkAreaLabel, tt.args.routes); (err != nil) != tt.wantErr {
236237
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
237238
}
238239
})

0 commit comments

Comments
 (0)