Skip to content

Commit 63e921d

Browse files
author
Devansh Thakur
committed
updated intake tests and make use of testutils
1 parent 9c4a82e commit 63e921d

File tree

1 file changed

+5
-40
lines changed

1 file changed

+5
-40
lines changed

internal/cmd/beta/intake/instance/list/list_test.go

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import (
88
"github.com/google/go-cmp/cmp"
99
"github.com/google/go-cmp/cmp/cmpopts"
1010
"github.com/google/uuid"
11+
"github.com/spf13/cobra"
1112
"github.com/stackitcloud/stackit-cli/internal/cmd/params"
1213
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1314
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
15+
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
1416
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1517
"github.com/stackitcloud/stackit-sdk-go/services/intake"
1618
)
@@ -109,46 +111,9 @@ func TestParseInput(t *testing.T) {
109111

110112
for _, tt := range tests {
111113
t.Run(tt.description, func(t *testing.T) {
112-
p := print.NewPrinter()
113-
cmd := NewCmd(&params.CmdParams{Printer: p})
114-
err := globalflags.Configure(cmd.Flags())
115-
if err != nil {
116-
t.Fatalf("configure global flags: %v", err)
117-
}
118-
119-
for flag, value := range tt.flagValues {
120-
err := cmd.Flags().Set(flag, value)
121-
if err != nil {
122-
if !tt.isValid {
123-
return
124-
}
125-
t.Fatalf("setting flag --%s=%s: %v", flag, value, err)
126-
}
127-
}
128-
129-
err = cmd.ValidateRequiredFlags()
130-
if err != nil {
131-
if !tt.isValid {
132-
return
133-
}
134-
t.Fatalf("error validating flags: %v", err)
135-
}
136-
137-
model, err := parseInput(p, cmd)
138-
if err != nil {
139-
if !tt.isValid {
140-
return
141-
}
142-
t.Fatalf("error parsing flags: %v", err)
143-
}
144-
145-
if !tt.isValid {
146-
t.Fatalf("did not fail on invalid input")
147-
}
148-
diff := cmp.Diff(model, tt.expectedModel)
149-
if diff != "" {
150-
t.Fatalf("Data does not match: %s", diff)
151-
}
114+
testutils.TestParseInput(t, NewCmd, func(p *print.Printer, cmd *cobra.Command, args []string) (*inputModel, error) {
115+
return parseInput(p, cmd)
116+
}, tt.expectedModel, nil, tt.flagValues, tt.isValid)
152117
})
153118
}
154119
}

0 commit comments

Comments
 (0)