-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathlist_test.go
More file actions
101 lines (85 loc) · 2.09 KB
/
list_test.go
File metadata and controls
101 lines (85 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package datacenter_test
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
"github.com/hetznercloud/cli/internal/cmd/datacenter"
"github.com/hetznercloud/cli/internal/testutil"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)
func TestList(t *testing.T) {
fx := testutil.NewFixture(t)
defer fx.Finish()
time.Local = time.UTC
cmd := datacenter.ListCmd.CobraCommand(fx.State())
fx.ExpectEnsureToken()
fx.Client.DatacenterClient.EXPECT().
AllWithOpts(
gomock.Any(),
hcloud.DatacenterListOpts{
ListOpts: hcloud.ListOpts{PerPage: 50},
Sort: []string{"id:asc"},
},
).
Return([]*hcloud.Datacenter{
{
ID: 4,
Name: "fsn1-dc14",
Location: &hcloud.Location{Name: "fsn1"},
Description: "Falkenstein 1 virtual DC 14",
},
}, nil)
out, errOut, err := fx.Run(cmd, []string{})
expOut := `ID NAME DESCRIPTION LOCATION
4 fsn1-dc14 Falkenstein 1 virtual DC 14 fsn1
`
require.NoError(t, err)
assert.Empty(t, errOut)
assert.Equal(t, expOut, out)
}
func TestListJSON(t *testing.T) {
fx := testutil.NewFixture(t)
defer fx.Finish()
time.Local = time.UTC
cmd := datacenter.ListCmd.CobraCommand(fx.State())
fx.ExpectEnsureToken()
fx.Client.DatacenterClient.EXPECT().
AllWithOpts(
gomock.Any(),
hcloud.DatacenterListOpts{
ListOpts: hcloud.ListOpts{PerPage: 50},
Sort: []string{"id:asc"},
},
).
Return([]*hcloud.Datacenter{
{
ID: 4,
Name: "fsn1-dc14",
Location: &hcloud.Location{Name: "fsn1"},
Description: "Falkenstein 1 virtual DC 14",
},
}, nil)
out, errOut, err := fx.Run(cmd, []string{"-o=json"})
require.NoError(t, err)
assert.Empty(t, errOut)
assert.JSONEq(t, `
[
{
"id": 4,
"name": "fsn1-dc14",
"description": "Falkenstein 1 virtual DC 14",
"location": {
"id": 0,
"name": "fsn1",
"description": "",
"country": "",
"city": "",
"latitude": 0,
"longitude": 0,
"network_zone": ""
}
}
]`, out)
}