@@ -9,29 +9,50 @@ import (
99 "github.com/UpCloudLtd/upcloud-cli/v3/internal/mockexecute"
1010
1111 "github.com/UpCloudLtd/upcloud-go-api/v8/upcloud"
12+ "github.com/UpCloudLtd/upcloud-go-api/v8/upcloud/request"
1213 "github.com/jedib0t/go-pretty/v6/text"
1314 "github.com/stretchr/testify/assert"
14- "github.com/stretchr/testify/mock"
1515)
1616
1717func TestDatabaseListTitleFallback (t * testing.T ) {
1818 text .DisableColors ()
1919 databases := []upcloud.ManagedDatabase {
20- {UUID : "091f1afe-4ddd-4d43-afad-6aa3069cc7fe" , Title : "service-name" , Name : "hotname -prefix-1" , State : "running" },
21- {UUID : "091f1afe-4ddd-4d43-afad-6aa3069cc7fe" , Name : "hotname -prefix-2" , State : "running" },
20+ {UUID : "091f1afe-4ddd-4d43-afad-6aa3069cc7fe" , Title : "service-name" , Name : "hostname -prefix-1" , State : "running" },
21+ {UUID : "091f1afe-4ddd-4d43-afad-6aa3069cc7fe" , Name : "hostname -prefix-2" , State : "running" },
2222 }
2323
24- mService := smock.Service {}
25- mService .On ("GetManagedDatabases" , mock .Anything ).Return (databases , nil )
26-
27- conf := config .New ()
28- command := commands .BuildCommand (ListCommand (), nil , conf )
29-
30- output , err := mockexecute .MockExecute (command , & mService , conf )
31-
32- assert .NoError (t , err )
33- assert .Regexp (t , `UUID\s+Title\s+Type\s+Plan\s+Zone\s+State` , output )
34- assert .Contains (t , output , "service-name" )
35- assert .NotContains (t , output , "hotname-prefix-1" )
36- assert .Contains (t , output , "hotname-prefix-2" )
24+ for _ , test := range []struct {
25+ name string
26+ args []string
27+ page request.Page
28+ }{
29+ {
30+ name : "default page" ,
31+ page : request.Page {Size : 100 , Number : 0 },
32+ },
33+ {
34+ name : "limit and page args" ,
35+ page : request.Page {Size : 18 , Number : 19 },
36+ args : []string {"--limit" , "18" , "--page" , "19" },
37+ },
38+ } {
39+ t .Run (test .name , func (t * testing.T ) {
40+ page := test .page
41+
42+ mService := smock.Service {}
43+ mService .On ("GetManagedDatabases" , & request.GetManagedDatabasesRequest {Page : & page }).Return (databases , nil )
44+
45+ conf := config .New ()
46+ command := commands .BuildCommand (ListCommand (), nil , conf )
47+ command .Cobra ().SetArgs (test .args )
48+
49+ output , err := mockexecute .MockExecute (command , & mService , conf )
50+
51+ assert .NoError (t , err )
52+ assert .Regexp (t , `UUID\s+Title\s+Type\s+Plan\s+Zone\s+State` , output )
53+ assert .Contains (t , output , "service-name" )
54+ assert .NotContains (t , output , "hostname-prefix-1" )
55+ assert .Contains (t , output , "hostname-prefix-2" )
56+ })
57+ }
3758}
0 commit comments