Skip to content

Commit 837652f

Browse files
committed
refactor(server): use snapshot to test server show output
1 parent 3076c4c commit 837652f

File tree

4 files changed

+50
-47
lines changed

4 files changed

+50
-47
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
github.com/UpCloudLtd/upcloud-go-api/v4 v4.8.0
77
github.com/adrg/xdg v0.3.2
88
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
9+
github.com/bradleyjkemp/cupaloy/v2 v2.7.0
910
github.com/gemalto/flume v0.12.0
1011
github.com/jedib0t/go-pretty/v6 v6.0.5
1112
github.com/m7shapan/cidr v0.0.0-20200427124835-7eba0889a5d2

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
3434
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
3535
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
3636
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
37+
github.com/bradleyjkemp/cupaloy/v2 v2.7.0 h1:AT0vOjO68RcLyenLCHOGZzSNiuto7ziqzq6Q1/3xzMQ=
38+
github.com/bradleyjkemp/cupaloy/v2 v2.7.0/go.mod h1:bm7JXdkRd4BHJk9HpwqAI8BoAY1lps46Enkdqw6aRX0=
3739
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
3840
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
3941
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
Common
3+
UUID: 0077fa3d-32db-4b09-9f5f-30d9e9afb565
4+
Hostname: server1.example.com
5+
Title: server1.example.com
6+
Plan: 1xCPU-2GB
7+
Zone: fi-hel1
8+
State: started
9+
Simple Backup: 0100,dailies
10+
Licence: 0
11+
Metadata: True
12+
Timezone: UTC
13+
Host ID: 7653311107
14+
Tags: DEV,Ubuntu
15+
16+
Storage: (Flags: B = bootdisk, P = part of plan)
17+
18+
UUID Title Type Address Size (GiB) Flags
19+
────────────────────────────────────── ───────────────────────────────── ────── ────────── ──────────── ───────
20+
012580a1-32a1-466e-a323-689ca16f2d43 Storage for server1.example.com disk virtio:0 20 P
21+
22+
NICs: (Flags: S = source IP filtering, B = bootable)
23+
24+
# Type IP Address MAC Address Network Flags
25+
─── ───────── ──────────────────────────────────────────────────── ─────────────────── ────────────────────────────────────── ───────
26+
1 public IPv4: 94.237.0.207 de:ff:ff:ff:66:89 037fcf2a-6745-45dd-867e-f9479ea8c044
27+
2 utility IPv4: 10.6.3.95 (f) de:ff:ff:ff:ed:85 03000000-0000-4000-8045-000000000000
28+
3 public IPv6: xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx de:ff:ff:ff:cc:20 03c93fd8-cc60-4849-91b8-6e404b228e2a
29+
30+
Firewall Rules:
31+
32+
# Direction Action Src IPAddress Dest IPAddress Src Port Dest Port Protocol
33+
─── ─────────── ──────── ─────────────── ──────────────── ────────── ─────────── ───────────────
34+
1 in accept Any Any Any Any IPv4/tcp
35+
2 out drop 10.10.10.0 → 10.20.20.0 0 → Any IPv4/udp/icmp
36+
10.10.10.99 1024
37+
38+
39+
Remote Access
40+
Type: vnc
41+
Host: fi-hel1.vnc.upcloud.com
42+
Port: 3000
43+
Password: aabbccdd
44+
45+

internal/commands/server/show_test.go

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/UpCloudLtd/upcloud-cli/internal/config"
88
smock "github.com/UpCloudLtd/upcloud-cli/internal/mock"
99
"github.com/UpCloudLtd/upcloud-cli/internal/mockexecute"
10+
"github.com/bradleyjkemp/cupaloy/v2"
1011

1112
"github.com/UpCloudLtd/upcloud-go-api/v4/upcloud"
1213
"github.com/UpCloudLtd/upcloud-go-api/v4/upcloud/request"
@@ -148,52 +149,6 @@ func TestServerHumanOutput(t *testing.T) {
148149
},
149150
}
150151

151-
expected := `
152-
Common
153-
UUID: 0077fa3d-32db-4b09-9f5f-30d9e9afb565
154-
Hostname: server1.example.com
155-
Title: server1.example.com
156-
Plan: 1xCPU-2GB
157-
Zone: fi-hel1
158-
State: started
159-
Simple Backup: 0100,dailies
160-
Licence: 0
161-
Metadata: True
162-
Timezone: UTC
163-
Host ID: 7653311107
164-
Tags: DEV,Ubuntu
165-
166-
Storage: (Flags: B = bootdisk, P = part of plan)
167-
168-
UUID Title Type Address Size (GiB) Flags
169-
────────────────────────────────────── ───────────────────────────────── ────── ────────── ──────────── ───────
170-
012580a1-32a1-466e-a323-689ca16f2d43 Storage for server1.example.com disk virtio:0 20 P
171-
172-
NICs: (Flags: S = source IP filtering, B = bootable)
173-
174-
# Type IP Address MAC Address Network Flags
175-
─── ───────── ──────────────────────────────────────────────────── ─────────────────── ────────────────────────────────────── ───────
176-
1 public IPv4: 94.237.0.207 de:ff:ff:ff:66:89 037fcf2a-6745-45dd-867e-f9479ea8c044
177-
2 utility IPv4: 10.6.3.95 (f) de:ff:ff:ff:ed:85 03000000-0000-4000-8045-000000000000
178-
3 public IPv6: xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx de:ff:ff:ff:cc:20 03c93fd8-cc60-4849-91b8-6e404b228e2a
179-
180-
Firewall Rules:
181-
182-
# Direction Action Src IPAddress Dest IPAddress Src Port Dest Port Protocol
183-
─── ─────────── ──────── ─────────────── ──────────────── ────────── ─────────── ───────────────
184-
1 in accept Any Any Any Any IPv4/tcp
185-
2 out drop 10.10.10.0 → 10.20.20.0 0 → Any IPv4/udp/icmp
186-
10.10.10.99 1024
187-
188-
189-
Remote Access
190-
Type: vnc
191-
Host: fi-hel1.vnc.upcloud.com
192-
Port: 3000
193-
Password: aabbccdd
194-
195-
`
196-
197152
mService := smock.Service{}
198153
mService.On("GetServers").Return(&upcloud.Servers{Servers: []upcloud.Server{srv.Server}}, nil)
199154
mService.On("GetServerDetails", &request.GetServerDetailsRequest{UUID: uuid}).Return(srv, nil)
@@ -213,5 +168,5 @@ func TestServerHumanOutput(t *testing.T) {
213168
output, err := mockexecute.MockExecute(command, &mService, conf)
214169

215170
assert.NoError(t, err)
216-
assert.Equal(t, expected, output)
171+
cupaloy.SnapshotT(t, output)
217172
}

0 commit comments

Comments
 (0)