From 7f7f3104efde0bc5b99c9224e2296082fe5c2ac6 Mon Sep 17 00:00:00 2001 From: Alexander Dahmen Date: Fri, 21 Feb 2025 09:32:09 +0100 Subject: [PATCH] chore(config): Add nil pointer checks and tests for the outputResult functions Signed-off-by: Alexander Dahmen --- internal/cmd/config/list/list_test.go | 35 +++++++++++++++++++ internal/cmd/config/profile/list/list_test.go | 34 ++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 internal/cmd/config/list/list_test.go create mode 100644 internal/cmd/config/profile/list/list_test.go diff --git a/internal/cmd/config/list/list_test.go b/internal/cmd/config/list/list_test.go new file mode 100644 index 000000000..d32d5d76a --- /dev/null +++ b/internal/cmd/config/list/list_test.go @@ -0,0 +1,35 @@ +package list + +import ( + "testing" + + "github.com/stackitcloud/stackit-cli/internal/pkg/print" +) + +func TestOutputResult(t *testing.T) { + type args struct { + outputFormat string + configData map[string]any + activeProfile string + } + 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.configData, tt.args.activeProfile); (err != nil) != tt.wantErr { + t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} diff --git a/internal/cmd/config/profile/list/list_test.go b/internal/cmd/config/profile/list/list_test.go new file mode 100644 index 000000000..80e080c56 --- /dev/null +++ b/internal/cmd/config/profile/list/list_test.go @@ -0,0 +1,34 @@ +package list + +import ( + "testing" + + "github.com/stackitcloud/stackit-cli/internal/pkg/print" +) + +func TestOutputResult(t *testing.T) { + type args struct { + outputFormat string + profiles []profileInfo + } + 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.profiles); (err != nil) != tt.wantErr { + t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +}