@@ -3,13 +3,14 @@ package list
33import (
44 "context"
55 "testing"
6-
7- "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
8- "github.com/stackitcloud/stackit-cli/internal/pkg/utils"
6+ "time"
97
108 "github.com/google/go-cmp/cmp"
119 "github.com/google/go-cmp/cmp/cmpopts"
1210 "github.com/google/uuid"
11+ "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
12+ "github.com/stackitcloud/stackit-cli/internal/pkg/print"
13+ "github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1314 "github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
1415)
1516
@@ -205,3 +206,49 @@ func TestBuildRequest(t *testing.T) {
205206 })
206207 }
207208}
209+
210+ func Test_outputResult (t * testing.T ) {
211+ type args struct {
212+ outputFormat string
213+ backups []postgresflex.Backup
214+ }
215+ tests := []struct {
216+ name string
217+ args args
218+ wantErr bool
219+ }{
220+ {"empty" , args {}, false },
221+ {"standard" , args {outputFormat : "" , backups : []postgresflex.Backup {}}, false },
222+ {"complete" , args {outputFormat : "" , backups : []postgresflex.Backup {
223+ {
224+ EndTime : utils .Ptr (time .Now ().Format (time .RFC3339 )),
225+ Id : utils .Ptr ("id" ),
226+ Labels : & []string {"foo" , "bar" , "baz" },
227+ Name : utils .Ptr ("name" ),
228+ Options : & map [string ]string {"test1" : "test1" , "test2" : "test2" },
229+ Size : utils .Ptr (int64 (42 )),
230+ StartTime : utils .Ptr (time .Now ().Format (time .RFC3339 )),
231+ },
232+ {
233+ EndTime : utils .Ptr (time .Now ().Format (time .RFC3339 )),
234+ Id : utils .Ptr ("id" ),
235+ Labels : & []string {"foo" , "bar" , "baz" },
236+ Name : utils .Ptr ("name" ),
237+ Options : & map [string ]string {"test1" : "test1" , "test2" : "test2" },
238+ Size : utils .Ptr (int64 (42 )),
239+ StartTime : utils .Ptr (time .Now ().Format (time .RFC3339 )),
240+ },
241+ },
242+ }, false },
243+ }
244+ p := print .NewPrinter ()
245+ p .Cmd = NewCmd (p )
246+
247+ for _ , tt := range tests {
248+ t .Run (tt .name , func (t * testing.T ) {
249+ if err := outputResult (p , tt .args .outputFormat , tt .args .backups ); (err != nil ) != tt .wantErr {
250+ t .Errorf ("outputResult() error = %v, wantErr %v" , err , tt .wantErr )
251+ }
252+ })
253+ }
254+ }
0 commit comments