Skip to content

Commit 0b98d35

Browse files
authored
fix(ipaddress): show full API response in marshaled outputs (#259)
1 parent 4c2024c commit 0b98d35

8 files changed

Lines changed: 247 additions & 130 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2424
- In JSON and YAML output of `kubernetes list`: display full API response.
2525
- **Breaking**: In JSON and YAML output of `database list`: display the full API response. Value of `title` is not replaced with value from `name`, if `title` is empty.
2626
- **Breaking**: In JSON and YAML output of `database types`: display the full API response. This changes the top level datatype from list to object, where keys are the available database type, e.g., `pg` and `mysql`.
27+
- **Breaking**: In JSON and YAML output of `ip-address list`: display full API response. This changes `partofplan` key to `part_of_plan` and `ptrrecord` key to `ptr_record`.
2728
- In human readable output of `kubernetes show` command, show node-groups as table. Node-group details are available with `kubernetes nodegroup show` command.
2829

30+
## Fixed
31+
- **Breaking**: In JSON and YAML output of `ip-address show`: use same JSON keys as in API documentation. This removes `credits` key that was used in place of `floating`.
32+
2933
## Removed
3034
- **Breaking**: Remove `database connection list` and `database connection cancel` commands in favor of `database session` counterparts
3135
- **Breaking**: In JSON and YAML output of `database properties * show`: pass-through the API response. This removes `key` field from the output.

internal/commands/account/show.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (s *showCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Ou
2727
return nil, err
2828
}
2929

30-
details, err := output.Details{
30+
details := output.Details{
3131
Sections: []output.DetailSection{
3232
{
3333
Rows: []output.DetailRow{
@@ -80,12 +80,12 @@ func (s *showCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Ou
8080
},
8181
},
8282
},
83-
}, nil
83+
}
8484

8585
return output.MarshaledWithHumanOutput{
8686
Value: account,
8787
Output: details,
88-
}, err
88+
}, nil
8989
}
9090

9191
func formatCredits(credits float64) string {

internal/commands/ipaddress/list.go

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -36,45 +36,49 @@ func (s *listCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Ou
3636
for i, ipAddress := range ips.IPAddresses {
3737
rows[i] = output.TableRow{ipAddress.Address, ipAddress.Access, ipAddress.Family, ipAddress.PartOfPlan, ipAddress.PTRRecord, ipAddress.ServerUUID, ipAddress.Floating, ipAddress.Zone}
3838
}
39-
return output.Table{
40-
Columns: []output.TableColumn{
41-
{
42-
Header: "Address",
43-
Key: "address",
44-
Colour: ui.DefaultAddressColours,
45-
},
46-
{
47-
Header: "Access",
48-
Key: "access",
49-
},
50-
{
51-
Header: "Family",
52-
Key: "family",
53-
},
54-
{
55-
Header: "Part of Plan",
56-
Key: "partofplan",
57-
Format: format.Boolean,
58-
},
59-
{
60-
Header: "PTR Record",
61-
Key: "ptrrecord",
62-
},
63-
{
64-
Header: "Server",
65-
Key: "server",
66-
Colour: ui.DefaultUUUIDColours,
67-
},
68-
{
69-
Header: "Floating",
70-
Key: "floating",
71-
Format: format.Boolean,
72-
},
73-
{
74-
Header: "Zone",
75-
Key: "zone",
39+
40+
return output.MarshaledWithHumanOutput{
41+
Value: ips,
42+
Output: output.Table{
43+
Columns: []output.TableColumn{
44+
{
45+
Header: "Address",
46+
Key: "address",
47+
Colour: ui.DefaultAddressColours,
48+
},
49+
{
50+
Header: "Access",
51+
Key: "access",
52+
},
53+
{
54+
Header: "Family",
55+
Key: "family",
56+
},
57+
{
58+
Header: "Part of Plan",
59+
Key: "part_of_plan",
60+
Format: format.Boolean,
61+
},
62+
{
63+
Header: "PTR Record",
64+
Key: "ptr_record",
65+
},
66+
{
67+
Header: "Server",
68+
Key: "server",
69+
Colour: ui.DefaultUUUIDColours,
70+
},
71+
{
72+
Header: "Floating",
73+
Key: "floating",
74+
Format: format.Boolean,
75+
},
76+
{
77+
Header: "Zone",
78+
Key: "zone",
79+
},
7680
},
81+
Rows: rows,
7782
},
78-
Rows: rows,
7983
}, nil
8084
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package ipaddress
2+
3+
import (
4+
"testing"
5+
6+
"github.com/UpCloudLtd/upcloud-cli/v2/internal/commands"
7+
"github.com/UpCloudLtd/upcloud-cli/v2/internal/config"
8+
smock "github.com/UpCloudLtd/upcloud-cli/v2/internal/mock"
9+
"github.com/UpCloudLtd/upcloud-cli/v2/internal/mockexecute"
10+
"github.com/UpCloudLtd/upcloud-cli/v2/internal/testutils"
11+
"github.com/stretchr/testify/assert"
12+
13+
"github.com/UpCloudLtd/upcloud-go-api/v6/upcloud"
14+
)
15+
16+
func TestList_MarshaledOutput(t *testing.T) {
17+
ipAddress := upcloud.IPAddress{
18+
Address: "94.237.117.150",
19+
Access: "public",
20+
Family: "IPv4",
21+
PartOfPlan: upcloud.FromBool(true),
22+
PTRRecord: "94-237-117-150.fi-hel1.upcloud.host",
23+
ServerUUID: "005ab220-7ff6-42c9-8615-e4c02eb4104e",
24+
MAC: "ee:1b:db:ca:6b:80",
25+
Floating: upcloud.FromBool(false),
26+
Zone: "fi-hel1",
27+
}
28+
ipAddresses := upcloud.IPAddresses{
29+
IPAddresses: []upcloud.IPAddress{
30+
ipAddress,
31+
},
32+
}
33+
34+
mService := smock.Service{}
35+
mService.On("GetIPAddresses").Return(&ipAddresses, nil)
36+
37+
conf := config.New()
38+
conf.Viper().Set(config.KeyOutput, config.ValueOutputJSON)
39+
40+
command := commands.BuildCommand(ListCommand(), nil, conf)
41+
42+
output, err := mockexecute.MockExecute(command, &mService, conf)
43+
44+
assert.Nil(t, err)
45+
testutils.AssertOutputHasType(t, output, &upcloud.IPAddressSlice{})
46+
}

internal/commands/ipaddress/show.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,31 @@ func (s *showCommand) Execute(exec commands.Executor, arg string) (output.Output
3939
if err != nil {
4040
return nil, err
4141
}
42-
return output.Details{
42+
43+
details := output.Details{
4344
Sections: []output.DetailSection{
4445
{
4546
Rows: []output.DetailRow{
4647
{Title: "Address:", Key: "address", Value: ipAddress.Address, Colour: ui.DefaultAddressColours},
4748
{Title: "Access:", Key: "access", Value: ipAddress.Access},
48-
{Title: "Family:", Key: "access", Value: ipAddress.Family},
49-
{Title: "Part of Plan:", Key: "access", Value: ipAddress.PartOfPlan, Format: format.Boolean},
50-
{Title: "PTR Record:", Key: "access", Value: ipAddress.PTRRecord},
49+
{Title: "Family:", Key: "family", Value: ipAddress.Family},
50+
{Title: "Part of Plan:", Key: "part_of_plan", Value: ipAddress.PartOfPlan, Format: format.Boolean},
51+
{Title: "PTR Record:", Key: "ptr_record", Value: ipAddress.PTRRecord},
5152
{
5253
Title: "Server UUID:",
53-
Key: "access", Value: ipAddress.ServerUUID,
54+
Key: "server", Value: ipAddress.ServerUUID,
5455
Colour: ui.DefaultUUUIDColours,
5556
},
56-
{Title: "MAC:", Key: "credits", Value: ipAddress.MAC},
57-
{Title: "Floating:", Key: "credits", Value: ipAddress.Floating, Format: format.Boolean},
57+
{Title: "MAC:", Key: "mac", Value: ipAddress.MAC},
58+
{Title: "Floating:", Key: "floating", Value: ipAddress.Floating, Format: format.Boolean},
5859
{Title: "Zone:", Key: "zone", Value: ipAddress.Zone},
5960
},
6061
},
6162
},
63+
}
64+
65+
return output.MarshaledWithHumanOutput{
66+
Value: ipAddress,
67+
Output: details,
6268
}, nil
6369
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package kubernetes
2+
3+
import (
4+
"testing"
5+
6+
"github.com/UpCloudLtd/upcloud-cli/v2/internal/commands"
7+
"github.com/UpCloudLtd/upcloud-cli/v2/internal/config"
8+
smock "github.com/UpCloudLtd/upcloud-cli/v2/internal/mock"
9+
"github.com/UpCloudLtd/upcloud-cli/v2/internal/mockexecute"
10+
"github.com/UpCloudLtd/upcloud-cli/v2/internal/testutils"
11+
12+
"github.com/UpCloudLtd/upcloud-go-api/v6/upcloud"
13+
"github.com/stretchr/testify/assert"
14+
"github.com/stretchr/testify/mock"
15+
)
16+
17+
func TestList_MarshaledOutput(t *testing.T) {
18+
mService := smock.Service{}
19+
mService.On("GetKubernetesClusters", mock.Anything).Return([]upcloud.KubernetesCluster{testCluster}, nil)
20+
21+
conf := config.New()
22+
conf.Viper().Set(config.KeyOutput, config.ValueOutputJSON)
23+
24+
command := commands.BuildCommand(ListCommand(), nil, conf)
25+
26+
output, err := mockexecute.MockExecute(command, &mService, conf)
27+
28+
assert.Nil(t, err)
29+
testutils.AssertOutputIsList(t, output)
30+
}

0 commit comments

Comments
 (0)