Skip to content

Commit de5fd52

Browse files
authored
feat(zone): display parent zone if user has access to private zones (#309)
1 parent 289cc47 commit de5fd52

6 files changed

Lines changed: 110 additions & 23 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Add `host list` command for listing private cloud hosts.
1313
- Add `--host` argument to `server restart` command.
1414
- Add `--avoid-host` and `--host` arguments to `server start` command.
15+
- Add `Parent zone` column to `zone list` output for users that have access to private zones.
1516

1617
### Changed
1718

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.21
44

55
require (
66
github.com/UpCloudLtd/progress v1.0.2
7-
github.com/UpCloudLtd/upcloud-go-api/v8 v8.2.0
7+
github.com/UpCloudLtd/upcloud-go-api/v8 v8.4.0
88
github.com/adrg/xdg v0.3.2
99
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
1010
github.com/gemalto/flume v0.12.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym
1717
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
1818
github.com/UpCloudLtd/progress v1.0.2 h1:CTr1bBuFuXop9TEhR1PakbUMPTlUVL7Bgae9JgqXwPg=
1919
github.com/UpCloudLtd/progress v1.0.2/go.mod h1:iGxOnb9HvHW0yrLGUjHr0lxHhn7TehgWwh7a8NqK6iQ=
20-
github.com/UpCloudLtd/upcloud-go-api/v8 v8.2.0 h1:+/vej9U9eSOUFt1MRRtB+GXEXWtLacyfWn9KmHCnLkw=
21-
github.com/UpCloudLtd/upcloud-go-api/v8 v8.2.0/go.mod h1:pMuPcIQ5VUC65UETsaEPgHiDymxwX/3xYm4vlC4E9VI=
20+
github.com/UpCloudLtd/upcloud-go-api/v8 v8.4.0 h1:xtc+lscOHhrA4d2N8ifjAOu0zL/d8OXhnFI1w9BIbPg=
21+
github.com/UpCloudLtd/upcloud-go-api/v8 v8.4.0/go.mod h1:/BL9bYxio0GCdotzBvZjkpm1fSDtD0+0z6PtNMew9HU=
2222
github.com/adrg/xdg v0.3.2 h1:GUSGQ5pHdev83AYhDSS1A/CX+0JIsxbiWtow2DSA+RU=
2323
github.com/adrg/xdg v0.3.2/go.mod h1:7I2hH/IT30IsupOpKZ5ue7/qNi3CoKzD6tL3HwpaRMQ=
2424
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=

internal/commands/zone/list.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,36 @@ func (s *listCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Ou
2525
return nil, err
2626
}
2727

28+
hasParentZones := false
2829
rows := []output.TableRow{}
2930
for _, z := range zones.Zones {
31+
if len(z.ParentZone) > 0 {
32+
hasParentZones = true
33+
}
34+
3035
rows = append(rows, output.TableRow{
3136
z.ID,
3237
z.Description,
3338
z.Public,
39+
z.ParentZone,
3440
})
3541
}
3642

43+
columns := []output.TableColumn{
44+
{Key: "id", Header: "ID"},
45+
{Key: "description", Header: "Description"},
46+
{Key: "public", Header: "Public", Format: format.Boolean},
47+
}
48+
49+
if hasParentZones {
50+
columns = append(columns, output.TableColumn{Key: "parent_zone", Header: "Parent zone"})
51+
}
52+
3753
return output.MarshaledWithHumanOutput{
3854
Value: zones,
3955
Output: output.Table{
40-
Columns: []output.TableColumn{
41-
{Key: "id", Header: "ID"},
42-
{Key: "description", Header: "Description"},
43-
{Key: "public", Header: "Public", Format: format.Boolean},
44-
},
45-
Rows: rows,
56+
Columns: columns,
57+
Rows: rows,
4658
},
4759
}, nil
4860
}

internal/commands/zone/list_test.go

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,56 @@ import (
1515

1616
func 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
}

internal/mock/mock.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,46 @@ func (m *Service) ModifyGateway(_ context.Context, r *request.ModifyGatewayReque
12651265
return args[0].(*upcloud.Gateway), args.Error(1)
12661266
}
12671267

1268+
func (m *Service) GetGatewayPlans(ctx context.Context) ([]upcloud.GatewayPlan, error) {
1269+
return nil, nil
1270+
}
1271+
1272+
func (m *Service) GetGatewayConnections(ctx context.Context, r *request.GetGatewayConnectionsRequest) ([]upcloud.GatewayConnection, error) {
1273+
return nil, nil
1274+
}
1275+
1276+
func (m *Service) GetGatewayConnection(ctx context.Context, r *request.GetGatewayConnectionRequest) (*upcloud.GatewayConnection, error) {
1277+
return nil, nil
1278+
}
1279+
1280+
func (m *Service) CreateGatewayConnection(ctx context.Context, r *request.CreateGatewayConnectionRequest) (*upcloud.GatewayConnection, error) {
1281+
return nil, nil
1282+
}
1283+
1284+
func (m *Service) ModifyGatewayConnection(ctx context.Context, r *request.ModifyGatewayConnectionRequest) (*upcloud.GatewayConnection, error) {
1285+
return nil, nil
1286+
}
1287+
1288+
func (m *Service) DeleteGatewayConnection(ctx context.Context, r *request.DeleteGatewayConnectionRequest) error {
1289+
return nil
1290+
}
1291+
1292+
func (m *Service) GetGatewayConnectionTunnels(ctx context.Context, r *request.GetGatewayConnectionTunnelsRequest) ([]upcloud.GatewayTunnel, error) {
1293+
return nil, nil
1294+
}
1295+
1296+
func (m *Service) GetGatewayConnectionTunnel(ctx context.Context, r *request.GetGatewayConnectionTunnelRequest) (*upcloud.GatewayTunnel, error) {
1297+
return nil, nil
1298+
}
1299+
1300+
func (m *Service) CreateGatewayConnectionTunnel(ctx context.Context, r *request.CreateGatewayConnectionTunnelRequest) (*upcloud.GatewayTunnel, error) {
1301+
return nil, nil
1302+
}
1303+
1304+
func (m *Service) DeleteGatewayConnectionTunnel(ctx context.Context, r *request.DeleteGatewayConnectionTunnelRequest) error {
1305+
return nil
1306+
}
1307+
12681308
func (m *Service) GetNetworkPeerings(ctx context.Context, f ...request.QueryFilter) (upcloud.NetworkPeerings, error) {
12691309
return nil, nil
12701310
}

0 commit comments

Comments
 (0)