@@ -15,22 +15,56 @@ import (
1515
1616func TestZoneListHumanOutput (t * testing.T ) {
1717 text .DisableColors ()
18- zones := upcloud.Zones {
19- Zones : []upcloud.Zone {
20- {ID : "fi-hel1" , Description : "Helsinki #1" , Public : 1 },
21- {ID : "de-fra1" , Description : "Frankfurt #1" , Public : 1 },
22- },
23- }
2418
25- mService := smock.Service {}
26- mService .On ("GetZones" ).Return (& zones , nil )
19+ for _ , test := range []struct {
20+ name string
21+ zones upcloud.Zones
22+ expected string
23+ }{
24+ {
25+ name : "no private zones" ,
26+ zones : upcloud.Zones {
27+ Zones : []upcloud.Zone {
28+ {ID : "fi-hel1" , Description : "Helsinki #1" , Public : 1 },
29+ {ID : "de-fra1" , Description : "Frankfurt #1" , Public : 1 },
30+ },
31+ },
32+ expected : `
33+ ID Description Public
34+ ───────── ────────────── ────────
35+ fi-hel1 Helsinki #1 yes
36+ de-fra1 Frankfurt #1 yes
37+
38+ ` ,
39+ }, {
40+ name : "with private zones" ,
41+ zones : upcloud.Zones {
42+ Zones : []upcloud.Zone {
43+ {ID : "de-fra1" , Description : "Frankfurt #1" , Public : 1 },
44+ {ID : "de-tst1" , Description : "Test #1" , Public : 0 , ParentZone : "de-fra1" },
45+ },
46+ },
47+ expected : `
48+ ID Description Public Parent zone
49+ ───────── ────────────── ──────── ─────────────
50+ de-fra1 Frankfurt #1 yes
51+ de-tst1 Test #1 no de-fra1
2752
28- conf := config .New ()
29- command := commands .BuildCommand (ListCommand (), nil , conf )
53+ ` ,
54+ },
55+ } {
56+ t .Run (test .name , func (t * testing.T ) {
57+ zones := test .zones
58+ mService := smock.Service {}
59+ mService .On ("GetZones" ).Return (& zones , nil )
60+
61+ conf := config .New ()
62+ command := commands .BuildCommand (ListCommand (), nil , conf )
3063
31- output , err := mockexecute .MockExecute (command , & mService , conf )
64+ output , err := mockexecute .MockExecute (command , & mService , conf )
3265
33- assert .NoError (t , err )
34- assert .Regexp (t , "ID\\ s+Description\\ s+Public" , output )
35- assert .Regexp (t , "fi-hel1\\ s+Helsinki #1\\ s+yes" , output )
66+ assert .NoError (t , err )
67+ assert .Equal (t , output , test .expected )
68+ })
69+ }
3670}
0 commit comments