From b49d7a138380cb8a83ac119c1df7d33ca8267f3c Mon Sep 17 00:00:00 2001 From: Manuel Vaas Date: Wed, 21 Jan 2026 16:29:43 +0000 Subject: [PATCH 1/4] feat(iaas): List NICs for Project relates to STACKITCLI-307 and #1214 --- docs/stackit_network-interface_list.md | 3 ++ internal/cmd/network-interface/list/list.go | 59 +++++++++++++++------ 2 files changed, 46 insertions(+), 16 deletions(-) diff --git a/docs/stackit_network-interface_list.md b/docs/stackit_network-interface_list.md index f202a6667..8ed2447b3 100644 --- a/docs/stackit_network-interface_list.md +++ b/docs/stackit_network-interface_list.md @@ -13,6 +13,9 @@ stackit network-interface list [flags] ### Examples ``` + Lists all network interfaces in your current project + $ stackit network-interface list + Lists all network interfaces with network ID "xxx" $ stackit network-interface list --network-id xxx diff --git a/internal/cmd/network-interface/list/list.go b/internal/cmd/network-interface/list/list.go index 21c41a260..51d05ea63 100644 --- a/internal/cmd/network-interface/list/list.go +++ b/internal/cmd/network-interface/list/list.go @@ -33,6 +33,10 @@ type inputModel struct { NetworkId string } +type ExecutableRequest interface { + Execute() (*iaas.NICListResponse, error) +} + func NewCmd(params *types.CmdParams) *cobra.Command { cmd := &cobra.Command{ Use: "list", @@ -40,6 +44,10 @@ func NewCmd(params *types.CmdParams) *cobra.Command { Long: "Lists all network interfaces of a network.", Args: args.NoArgs, Example: examples.Build( + examples.NewExample( + `Lists all network interfaces in your current project`, + `$ stackit network-interface list`, + ), examples.NewExample( `Lists all network interfaces with network ID "xxx"`, `$ stackit network-interface list --network-id xxx`, @@ -71,22 +79,26 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } // Call API - req := buildRequest(ctx, model, apiClient) - resp, err := req.Execute() - if err != nil { - return fmt.Errorf("list network interfaces: %w", err) - } - - if resp.Items == nil || len(*resp.Items) == 0 { - networkLabel, err := iaasUtils.GetNetworkName(ctx, apiClient, model.ProjectId, model.Region, model.NetworkId) + var req ExecutableRequest + var networkLabel = "" + if model.NetworkId == "" { + // Return all NICs in the Project + req = buildProjectRequest(ctx, model, apiClient) + } else { + // Return the NICs for one Network + req = buildRequest(ctx, model, apiClient) + + networkLabel, err = iaasUtils.GetNetworkName(ctx, apiClient, model.ProjectId, model.Region, model.NetworkId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get network name: %v", err) networkLabel = model.NetworkId } else if networkLabel == "" { networkLabel = model.NetworkId } - params.Printer.Info("No network interfaces found for network %q\n", networkLabel) - return nil + } + resp, err := req.Execute() + if err != nil { + return fmt.Errorf("list network interfaces: %w", err) } // Truncate output @@ -95,7 +107,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { items = items[:*model.Limit] } - return outputResult(params.Printer, model.OutputFormat, items) + return outputResult(params.Printer, model.OutputFormat, items, networkLabel) }, } configureFlags(cmd) @@ -106,9 +118,6 @@ func configureFlags(cmd *cobra.Command) { cmd.Flags().Var(flags.UUIDFlag(), networkIdFlag, "Network ID") cmd.Flags().Int64(limitFlag, 0, "Maximum number of entries to list") cmd.Flags().String(labelSelectorFlag, "", "Filter by label") - - err := flags.MarkFlagsRequired(cmd, networkIdFlag) - cobra.CheckErr(err) } func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, error) { @@ -136,7 +145,16 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, return &model, nil } -func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListNicsRequest { +func buildProjectRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) ExecutableRequest { + req := apiClient.ListProjectNICs(ctx, model.ProjectId, model.Region) + if model.LabelSelector != nil { + req = req.LabelSelector(*model.LabelSelector) + } + + return req +} + +func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) ExecutableRequest { req := apiClient.ListNics(ctx, model.ProjectId, model.Region, model.NetworkId) if model.LabelSelector != nil { req = req.LabelSelector(*model.LabelSelector) @@ -145,8 +163,17 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli return req } -func outputResult(p *print.Printer, outputFormat string, nics []iaas.NIC) error { +func outputResult(p *print.Printer, outputFormat string, nics []iaas.NIC, networkLabel string) error { return p.OutputResult(outputFormat, nics, func() error { + if nics == nil || len(nics) == 0 { + if networkLabel == "" { + p.Outputf("No network interfaces found for your current project\n") + } else { + p.Outputf("No network interfaces found for network %q\n", networkLabel) + } + return nil + } + table := tables.NewTable() table.SetHeader("ID", "NAME", "NIC SECURITY", "DEVICE ID", "IPv4 ADDRESS", "STATUS", "TYPE") From daf75d6679260070579b661336201e37bf78e76e Mon Sep 17 00:00:00 2001 From: Manuel Vaas Date: Thu, 22 Jan 2026 16:09:46 +0100 Subject: [PATCH 2/4] feat(iaas): List NICs for Project Fixed tests and linter relates to STACKITCLI-307 and #1214 --- internal/cmd/network-interface/list/list.go | 2 +- internal/cmd/network-interface/list/list_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/cmd/network-interface/list/list.go b/internal/cmd/network-interface/list/list.go index 51d05ea63..09bf83d45 100644 --- a/internal/cmd/network-interface/list/list.go +++ b/internal/cmd/network-interface/list/list.go @@ -165,7 +165,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli func outputResult(p *print.Printer, outputFormat string, nics []iaas.NIC, networkLabel string) error { return p.OutputResult(outputFormat, nics, func() error { - if nics == nil || len(nics) == 0 { + if len(nics) == 0 { if networkLabel == "" { p.Outputf("No network interfaces found for your current project\n") } else { diff --git a/internal/cmd/network-interface/list/list_test.go b/internal/cmd/network-interface/list/list_test.go index d04c1d9b7..13ec2a785 100644 --- a/internal/cmd/network-interface/list/list_test.go +++ b/internal/cmd/network-interface/list/list_test.go @@ -196,7 +196,7 @@ func TestOutputResult(t *testing.T) { p.Cmd = NewCmd(&types.CmdParams{Printer: p}) for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if err := outputResult(p, tt.args.outputFormat, tt.args.nics); (err != nil) != tt.wantErr { + if err := outputResult(p, tt.args.outputFormat, tt.args.nics, "Label"); (err != nil) != tt.wantErr { t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr) } }) From 796aea1f74dce1f6359199e7ca2157927ae84422 Mon Sep 17 00:00:00 2001 From: Manuel Vaas Date: Mon, 26 Jan 2026 16:07:20 +0100 Subject: [PATCH 3/4] feat(iaas): List NICs for Project relates to STACKITCLI-307 and #1214 tests added network ids included in list of project NICs --- internal/cmd/network-interface/list/list.go | 93 ++++++++++++++----- .../cmd/network-interface/list/list_test.go | 92 ++++++++++++++++-- 2 files changed, 155 insertions(+), 30 deletions(-) diff --git a/internal/cmd/network-interface/list/list.go b/internal/cmd/network-interface/list/list.go index 09bf83d45..6deb0a7ac 100644 --- a/internal/cmd/network-interface/list/list.go +++ b/internal/cmd/network-interface/list/list.go @@ -1,9 +1,12 @@ package list import ( + "bytes" "context" "fmt" + "sort" + "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" @@ -33,10 +36,6 @@ type inputModel struct { NetworkId string } -type ExecutableRequest interface { - Execute() (*iaas.NICListResponse, error) -} - func NewCmd(params *types.CmdParams) *cobra.Command { cmd := &cobra.Command{ Use: "list", @@ -79,23 +78,39 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } // Call API - var req ExecutableRequest - var networkLabel = "" if model.NetworkId == "" { // Return all NICs in the Project - req = buildProjectRequest(ctx, model, apiClient) - } else { - // Return the NICs for one Network - req = buildRequest(ctx, model, apiClient) + req := buildProjectRequest(ctx, model, apiClient) + projectLabel, err := projectname.GetProjectName(ctx, params.Printer, params.CliVersion, cmd) + if err != nil { + projectLabel = model.ProjectId + } - networkLabel, err = iaasUtils.GetNetworkName(ctx, apiClient, model.ProjectId, model.Region, model.NetworkId) + resp, err := req.Execute() if err != nil { - params.Printer.Debug(print.ErrorLevel, "get network name: %v", err) - networkLabel = model.NetworkId - } else if networkLabel == "" { - networkLabel = model.NetworkId + return fmt.Errorf("list network interfaces: %w", err) + } + + // Truncate output + items := *resp.Items + if model.Limit != nil && len(items) > int(*model.Limit) { + items = items[:*model.Limit] } + + return outputProjectResult(params.Printer, model.OutputFormat, items, projectLabel) + } + + // Return the NICs for one Network + req := buildNetworkRequest(ctx, model, apiClient) + + networkLabel, err := iaasUtils.GetNetworkName(ctx, apiClient, model.ProjectId, model.Region, model.NetworkId) + if err != nil { + params.Printer.Debug(print.ErrorLevel, "get network name: %v", err) + networkLabel = model.NetworkId + } else if networkLabel == "" { + networkLabel = model.NetworkId } + resp, err := req.Execute() if err != nil { return fmt.Errorf("list network interfaces: %w", err) @@ -107,7 +122,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { items = items[:*model.Limit] } - return outputResult(params.Printer, model.OutputFormat, items, networkLabel) + return outputNetworkResult(params.Printer, model.OutputFormat, items, networkLabel) }, } configureFlags(cmd) @@ -145,7 +160,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, return &model, nil } -func buildProjectRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) ExecutableRequest { +func buildProjectRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListProjectNICsRequest { req := apiClient.ListProjectNICs(ctx, model.ProjectId, model.Region) if model.LabelSelector != nil { req = req.LabelSelector(*model.LabelSelector) @@ -154,7 +169,7 @@ func buildProjectRequest(ctx context.Context, model *inputModel, apiClient *iaas return req } -func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) ExecutableRequest { +func buildNetworkRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListNicsRequest { req := apiClient.ListNics(ctx, model.ProjectId, model.Region, model.NetworkId) if model.LabelSelector != nil { req = req.LabelSelector(*model.LabelSelector) @@ -163,14 +178,44 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli return req } -func outputResult(p *print.Printer, outputFormat string, nics []iaas.NIC, networkLabel string) error { +func outputProjectResult(p *print.Printer, outputFormat string, nics []iaas.NIC, projectLabel string) error { return p.OutputResult(outputFormat, nics, func() error { if len(nics) == 0 { - if networkLabel == "" { - p.Outputf("No network interfaces found for your current project\n") - } else { - p.Outputf("No network interfaces found for network %q\n", networkLabel) - } + p.Outputf("No network interfaces found for project %q\n", projectLabel) + return nil + } + + sort.SliceStable(nics, func(i, j int) bool { + result := bytes.Compare([]byte(*nics[i].NetworkId), []byte(*nics[j].NetworkId)) + return result == -1 + }) + + table := tables.NewTable() + table.SetHeader("ID", "NAME", "NETWORK ID", "NIC SECURITY", "DEVICE ID", "IPv4 ADDRESS", "STATUS", "TYPE") + + for _, nic := range nics { + table.AddRow( + utils.PtrString(nic.Id), + utils.PtrString(nic.Name), + utils.PtrString(nic.NetworkId), + utils.PtrString(nic.NicSecurity), + utils.PtrString(nic.Device), + utils.PtrString(nic.Ipv4), + utils.PtrString(nic.Status), + utils.PtrString(nic.Type), + ) + table.AddSeparator() + } + + p.Outputln(table.Render()) + return nil + }) +} + +func outputNetworkResult(p *print.Printer, outputFormat string, nics []iaas.NIC, networkLabel string) error { + return p.OutputResult(outputFormat, nics, func() error { + if len(nics) == 0 { + p.Outputf("No network interfaces found for network %q\n", networkLabel) return nil } diff --git a/internal/cmd/network-interface/list/list_test.go b/internal/cmd/network-interface/list/list_test.go index 13ec2a785..312b4a737 100644 --- a/internal/cmd/network-interface/list/list_test.go +++ b/internal/cmd/network-interface/list/list_test.go @@ -61,7 +61,16 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { return model } -func fixtureRequest(mods ...func(request *iaas.ApiListNicsRequest)) iaas.ApiListNicsRequest { +func fixtureProjectRequest(mods ...func(request *iaas.ApiListProjectNICsRequest)) iaas.ApiListProjectNICsRequest { + request := testClient.ListProjectNICs(testCtx, testProjectId, testRegion) + request = request.LabelSelector(testLabelSelector) + for _, mod := range mods { + mod(&request) + } + return request +} + +func fixtureNetworkRequest(mods ...func(request *iaas.ApiListNicsRequest)) iaas.ApiListNicsRequest { request := testClient.ListNics(testCtx, testProjectId, testRegion, testNetworkId) request = request.LabelSelector(testLabelSelector) for _, mod := range mods { @@ -148,7 +157,35 @@ func TestParseInput(t *testing.T) { } } -func TestBuildRequest(t *testing.T) { +func TestBuildProjectRequest(t *testing.T) { + tests := []struct { + description string + model *inputModel + expectedRequest iaas.ApiListProjectNICsRequest + }{ + { + description: "base", + model: fixtureInputModel(), + expectedRequest: fixtureProjectRequest(), + }, + } + + for _, tt := range tests { + t.Run(tt.description, func(t *testing.T) { + request := buildProjectRequest(testCtx, tt.model, testClient) + + diff := cmp.Diff(request, tt.expectedRequest, + cmp.AllowUnexported(tt.expectedRequest), + cmpopts.EquateComparable(testCtx), + ) + if diff != "" { + t.Fatalf("Data does not match: %s", diff) + } + }) + } +} + +func TestBuildNetworkRequest(t *testing.T) { tests := []struct { description string model *inputModel @@ -157,13 +194,13 @@ func TestBuildRequest(t *testing.T) { { description: "base", model: fixtureInputModel(), - expectedRequest: fixtureRequest(), + expectedRequest: fixtureNetworkRequest(), }, } for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - request := buildRequest(testCtx, tt.model, testClient) + request := buildNetworkRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), @@ -176,7 +213,7 @@ func TestBuildRequest(t *testing.T) { } } -func TestOutputResult(t *testing.T) { +func TestOutputProjectResult(t *testing.T) { type args struct { outputFormat string nics []iaas.NIC @@ -191,12 +228,55 @@ func TestOutputResult(t *testing.T) { args: args{}, wantErr: false, }, + { + name: "empty NIC in NIC-slice", + args: args{ + outputFormat: print.PrettyOutputFormat, + nics: []iaas.NIC{{}}, + }, + wantErr: false, + }, + } + p := print.NewPrinter() + p.Cmd = NewCmd(&types.CmdParams{Printer: p}) + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := outputProjectResult(p, tt.args.outputFormat, tt.args.nics, "Label"); (err != nil) != tt.wantErr { + t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestOutputNetworkResult(t *testing.T) { + type args struct { + outputFormat string + nics []iaas.NIC + } + tests := []struct { + name string + args args + wantErr bool + }{ + { + name: "empty", + args: args{}, + wantErr: false, + }, + { + name: "empty NIC in NIC-slice", + args: args{ + outputFormat: print.PrettyOutputFormat, + nics: []iaas.NIC{{}}, + }, + wantErr: false, + }, } p := print.NewPrinter() p.Cmd = NewCmd(&types.CmdParams{Printer: p}) for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if err := outputResult(p, tt.args.outputFormat, tt.args.nics, "Label"); (err != nil) != tt.wantErr { + if err := outputNetworkResult(p, tt.args.outputFormat, tt.args.nics, "Label"); (err != nil) != tt.wantErr { t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr) } }) From a7928cb8ca90652860bb329e869c088528f66891 Mon Sep 17 00:00:00 2001 From: Manuel Vaas Date: Tue, 27 Jan 2026 12:51:43 +0100 Subject: [PATCH 4/4] resolved comments --- docs/stackit_network-interface_list.md | 2 +- internal/cmd/network-interface/list/list.go | 76 +++++++++---------- .../cmd/network-interface/list/list_test.go | 6 +- 3 files changed, 41 insertions(+), 43 deletions(-) diff --git a/docs/stackit_network-interface_list.md b/docs/stackit_network-interface_list.md index 8ed2447b3..50276fe12 100644 --- a/docs/stackit_network-interface_list.md +++ b/docs/stackit_network-interface_list.md @@ -13,7 +13,7 @@ stackit network-interface list [flags] ### Examples ``` - Lists all network interfaces in your current project + Lists all network interfaces $ stackit network-interface list Lists all network interfaces with network ID "xxx" diff --git a/internal/cmd/network-interface/list/list.go b/internal/cmd/network-interface/list/list.go index 6deb0a7ac..2b7d12d1b 100644 --- a/internal/cmd/network-interface/list/list.go +++ b/internal/cmd/network-interface/list/list.go @@ -1,10 +1,10 @@ package list import ( - "bytes" + "cmp" "context" "fmt" - "sort" + "slices" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/types" @@ -33,7 +33,7 @@ type inputModel struct { *globalflags.GlobalFlagModel Limit *int64 LabelSelector *string - NetworkId string + NetworkId *string } func NewCmd(params *types.CmdParams) *cobra.Command { @@ -43,8 +43,9 @@ func NewCmd(params *types.CmdParams) *cobra.Command { Long: "Lists all network interfaces of a network.", Args: args.NoArgs, Example: examples.Build( + // Note: this subcommand uses two different API enpoints, which makes the implementation somewhat messy examples.NewExample( - `Lists all network interfaces in your current project`, + `Lists all network interfaces`, `$ stackit network-interface list`, ), examples.NewExample( @@ -77,52 +78,60 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - // Call API - if model.NetworkId == "" { - // Return all NICs in the Project + if model.NetworkId == nil { + // Call API to get all NICs in the Project req := buildProjectRequest(ctx, model, apiClient) - projectLabel, err := projectname.GetProjectName(ctx, params.Printer, params.CliVersion, cmd) - if err != nil { - projectLabel = model.ProjectId - } resp, err := req.Execute() if err != nil { return fmt.Errorf("list network interfaces: %w", err) } + if resp.Items == nil || len(*resp.Items) == 0 { + projectLabel, err := projectname.GetProjectName(ctx, params.Printer, params.CliVersion, cmd) + if err != nil { + projectLabel = model.ProjectId + } + params.Printer.Outputf("No network interfaces found for project %q\n", projectLabel) + return nil + } + // Truncate output items := *resp.Items if model.Limit != nil && len(items) > int(*model.Limit) { items = items[:*model.Limit] } - return outputProjectResult(params.Printer, model.OutputFormat, items, projectLabel) + return outputProjectResult(params.Printer, model.OutputFormat, items) } - // Return the NICs for one Network + // Call API to get NICs for one Network req := buildNetworkRequest(ctx, model, apiClient) - networkLabel, err := iaasUtils.GetNetworkName(ctx, apiClient, model.ProjectId, model.Region, model.NetworkId) - if err != nil { - params.Printer.Debug(print.ErrorLevel, "get network name: %v", err) - networkLabel = model.NetworkId - } else if networkLabel == "" { - networkLabel = model.NetworkId - } - resp, err := req.Execute() if err != nil { return fmt.Errorf("list network interfaces: %w", err) } + if resp.Items == nil || len(*resp.Items) == 0 { + networkLabel, err := iaasUtils.GetNetworkName(ctx, apiClient, model.ProjectId, model.Region, *model.NetworkId) + if err != nil { + params.Printer.Debug(print.ErrorLevel, "get network name: %v", err) + networkLabel = *model.NetworkId + } else if networkLabel == "" { + networkLabel = *model.NetworkId + } + params.Printer.Outputf("No network interfaces found for network %q\n", networkLabel) + return nil + } + // Truncate output items := *resp.Items if model.Limit != nil && len(items) > int(*model.Limit) { items = items[:*model.Limit] } - return outputNetworkResult(params.Printer, model.OutputFormat, items, networkLabel) + return outputNetworkResult(params.Printer, model.OutputFormat, items) }, } configureFlags(cmd) @@ -153,7 +162,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, GlobalFlagModel: globalFlags, Limit: limit, LabelSelector: flags.FlagToStringPointer(p, cmd, labelSelectorFlag), - NetworkId: flags.FlagToStringValue(p, cmd, networkIdFlag), + NetworkId: flags.FlagToStringPointer(p, cmd, networkIdFlag), } p.DebugInputModel(model) @@ -170,7 +179,7 @@ func buildProjectRequest(ctx context.Context, model *inputModel, apiClient *iaas } func buildNetworkRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListNicsRequest { - req := apiClient.ListNics(ctx, model.ProjectId, model.Region, model.NetworkId) + req := apiClient.ListNics(ctx, model.ProjectId, model.Region, *model.NetworkId) if model.LabelSelector != nil { req = req.LabelSelector(*model.LabelSelector) } @@ -178,16 +187,10 @@ func buildNetworkRequest(ctx context.Context, model *inputModel, apiClient *iaas return req } -func outputProjectResult(p *print.Printer, outputFormat string, nics []iaas.NIC, projectLabel string) error { +func outputProjectResult(p *print.Printer, outputFormat string, nics []iaas.NIC) error { return p.OutputResult(outputFormat, nics, func() error { - if len(nics) == 0 { - p.Outputf("No network interfaces found for project %q\n", projectLabel) - return nil - } - - sort.SliceStable(nics, func(i, j int) bool { - result := bytes.Compare([]byte(*nics[i].NetworkId), []byte(*nics[j].NetworkId)) - return result == -1 + slices.SortFunc(nics, func(a, b iaas.NIC) int { + return cmp.Compare(*a.NetworkId, *b.NetworkId) }) table := tables.NewTable() @@ -212,13 +215,8 @@ func outputProjectResult(p *print.Printer, outputFormat string, nics []iaas.NIC, }) } -func outputNetworkResult(p *print.Printer, outputFormat string, nics []iaas.NIC, networkLabel string) error { +func outputNetworkResult(p *print.Printer, outputFormat string, nics []iaas.NIC) error { return p.OutputResult(outputFormat, nics, func() error { - if len(nics) == 0 { - p.Outputf("No network interfaces found for network %q\n", networkLabel) - return nil - } - table := tables.NewTable() table.SetHeader("ID", "NAME", "NIC SECURITY", "DEVICE ID", "IPv4 ADDRESS", "STATUS", "TYPE") diff --git a/internal/cmd/network-interface/list/list_test.go b/internal/cmd/network-interface/list/list_test.go index 312b4a737..89e2fa2fc 100644 --- a/internal/cmd/network-interface/list/list_test.go +++ b/internal/cmd/network-interface/list/list_test.go @@ -53,7 +53,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { }, Limit: utils.Ptr(int64(10)), LabelSelector: utils.Ptr(testLabelSelector), - NetworkId: testNetworkId, + NetworkId: utils.Ptr(testNetworkId), } for _, mod := range mods { mod(model) @@ -241,7 +241,7 @@ func TestOutputProjectResult(t *testing.T) { p.Cmd = NewCmd(&types.CmdParams{Printer: p}) for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if err := outputProjectResult(p, tt.args.outputFormat, tt.args.nics, "Label"); (err != nil) != tt.wantErr { + if err := outputProjectResult(p, tt.args.outputFormat, tt.args.nics); (err != nil) != tt.wantErr { t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr) } }) @@ -276,7 +276,7 @@ func TestOutputNetworkResult(t *testing.T) { p.Cmd = NewCmd(&types.CmdParams{Printer: p}) for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if err := outputNetworkResult(p, tt.args.outputFormat, tt.args.nics, "Label"); (err != nil) != tt.wantErr { + if err := outputNetworkResult(p, tt.args.outputFormat, tt.args.nics); (err != nil) != tt.wantErr { t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr) } })