Skip to content

Commit dddaded

Browse files
committed
updates
1 parent 8331abb commit dddaded

22 files changed

Lines changed: 1290 additions & 66 deletions

docs/stackit_beta_routing-table_describe.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ stackit beta routing-table describe ROUTING_TABLE_ID_ARG [flags]
1414

1515
```
1616
Describe a routing-table
17-
$ stackit beta routing-table describe xxxx-xxxx-xxxx-xxxx --organization-id xxx --network-area-id xxx
17+
$ stackit beta routing-table describe xxxx-xxxx-xxxx-xxxx --organization-id xxx --network-area-id yyy
1818
```
1919

2020
### Options

docs/stackit_beta_routing-table_list.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ stackit beta routing-table list [flags]
1414

1515
```
1616
List all routing-tables
17-
$ stackit beta routing-table list --organization-id xxx --network-area-id xxx
17+
$ stackit beta routing-table list --organization-id xxx --network-area-id yyy
1818
1919
List all routing-tables with labels
20-
$ stackit beta routing-table list --label-selector env=dev,env=rc --organization-id xxx --network-area-id xxx
20+
$ stackit beta routing-table list --label-selector env=dev,env=rc --organization-id xxx --network-area-id yyy
2121
2222
List all routing-tables with labels and limit to 10
23-
$ stackit beta routing-table list --label-selector env=dev,env=rc --limit 10 --organization-id xxx --network-area-id xxx
23+
$ stackit beta routing-table list --label-selector env=dev,env=rc --limit 10 --organization-id xxx --network-area-id yyy
2424
```
2525

2626
### Options

docs/stackit_beta_routing-table_route_create.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ stackit beta routing-table route create [flags]
1515
```
1616
Create a route with CIDRv4 destination and IPv4 nexthop
1717
stackit beta routing-tables route create \
18-
--routing-table-id xxx --organization-id xxx --network-area-id xxx \
18+
--routing-table-id xxx --organization-id yyy --network-area-id zzz \
1919
--destination-type cidrv4 --destination-value <ipv4-cidr> \
2020
--nexthop-type ipv4 --nexthop-value <ipv4-address>
2121
2222
Create a route with CIDRv6 destination and IPv6 nexthop
2323
stackit beta routing-tables route create \
24-
--routing-table-id xxx --organization-id xxx --network-area-id xxx \
24+
--routing-table-id xxx --organization-id yyy --network-area-id zzz \
2525
--destination-type cidrv6 --destination-value <ipv6-cidr> \
2626
--nexthop-type ipv6 --nexthop-value <ipv6-address>
2727
2828
Create a route with CIDRv6 destination and Nexthop Internet
2929
stackit beta routing-tables route create \
30-
--routing-table-id xxx --organization-id xxx --network-area-id xxx \
30+
--routing-table-id xxx --organization-id yyy --network-area-id zzz \
3131
--destination-type cidrv6 --destination-value <ipv6-cidr> \
3232
--nexthop-type internet
3333
```

docs/stackit_beta_routing-table_route_delete.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ stackit beta routing-table route delete routing-table-id [flags]
1414

1515
```
1616
Deletes a route within a routing-table
17-
$ stackit beta routing-table route delete xxxx-xxxx-xxxx-xxxx --routing-table-id xxx --organization-id xxx --network-area-id xxx
17+
$ stackit beta routing-table route delete xxxx-xxxx-xxxx-xxxx --routing-table-id xxx --organization-id yyy --network-area-id zzz
1818
```
1919

2020
### Options

docs/stackit_beta_routing-table_route_describe.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ stackit beta routing-table route describe ROUTE_ID_ARG [flags]
1414

1515
```
1616
Describe a route within a routing-table
17-
$ stackit beta routing-table route describe xxxx-xxxx-xxxx-xxxx --routing-table-id xxx --organization-id xxx --network-area-id xxx
17+
$ stackit beta routing-table route describe xxxx-xxxx-xxxx-xxxx --routing-table-id xxx --organization-id yyy --network-area-id zzz
1818
```
1919

2020
### Options

docs/stackit_beta_routing-table_route_list.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ stackit beta routing-table route list [flags]
1414

1515
```
1616
List all routes within a routing-table
17-
$ stackit beta routing-table route list --routing-table-id xxx --organization-id xxx --network-area-id xxx
17+
$ stackit beta routing-table route list --routing-table-id xxx --organization-id yyy --network-area-id zzz
1818
1919
List all routes within a routing-table with labels
20-
$ stackit beta routing-table list --routing-table-id xxx --organization-id xxx --network-area-id xxx --label-selector env=dev,env=rc
20+
$ stackit beta routing-table list --routing-table-id xxx --organization-id yyy --network-area-id zzz --label-selector env=dev,env=rc
2121
2222
List all routes within a routing-tables with labels and limit to 10
23-
$ stackit beta routing-table list --routing-table-id xxx --organization-id xxx --network-area-id xxx --label-selector env=dev,env=rc --limit 10
23+
$ stackit beta routing-table list --routing-table-id xxx --organization-id yyy --network-area-id zzz --label-selector env=dev,env=rc --limit 10
2424
```
2525

2626
### Options

docs/stackit_beta_routing-table_route_update.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ stackit beta routing-table route update ROUTE_ID_ARG [flags]
1414

1515
```
1616
Updates the label(s) of a route with ID "xxx" in a routing-table ID "xxx" in organization with ID "yyy" and network-area with ID "zzz"
17-
$ stackit beta routing-table route update xxx --labels key=value,foo=bar --routing-table-id xxx --organization-id xxx --network-area-id xxx
17+
$ stackit beta routing-table route update xxx --labels key=value,foo=bar --routing-table-id xxx --organization-id yyy --network-area-id zzz
1818
```
1919

2020
### Options

internal/cmd/beta/routingtable/describe/describe.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/spf13/cobra"
1111
"github.com/stackitcloud/stackit-cli/internal/cmd/params"
1212
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
13-
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
1413
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
1514
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
1615
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
@@ -43,7 +42,7 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
4342
Example: examples.Build(
4443
examples.NewExample(
4544
`Describe a routing-table`,
46-
`$ stackit beta routing-table describe xxxx-xxxx-xxxx-xxxx --organization-id xxx --network-area-id xxx`,
45+
`$ stackit beta routing-table describe xxxx-xxxx-xxxx-xxxx --organization-id xxx --network-area-id yyy`,
4746
),
4847
),
4948
RunE: func(cmd *cobra.Command, args []string) error {
@@ -91,9 +90,6 @@ func configureFlags(cmd *cobra.Command) {
9190

9291
func parseInput(p *print.Printer, cmd *cobra.Command, args []string) (*inputModel, error) {
9392
globalFlags := globalflags.Parse(p, cmd)
94-
if globalFlags.ProjectId == "" {
95-
return nil, &errors.ProjectIdError{}
96-
}
9793

9894
if len(args) == 0 {
9995
return nil, fmt.Errorf("at least one argument is required")
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
package describe
2+
3+
import (
4+
"testing"
5+
"time"
6+
7+
"github.com/google/go-cmp/cmp"
8+
"github.com/google/uuid"
9+
"github.com/stackitcloud/stackit-cli/internal/cmd/params"
10+
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
11+
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
12+
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
13+
"github.com/stackitcloud/stackit-sdk-go/services/iaasalpha"
14+
)
15+
16+
var testRegion = "eu01"
17+
var testOrgId = uuid.NewString()
18+
var testNetworkAreaId = uuid.NewString()
19+
var testRoutingTableId = uuid.NewString()
20+
21+
var testLabels = &map[string]string{
22+
"key1": "value1",
23+
"key2": "value2",
24+
}
25+
26+
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
27+
flagValues := map[string]string{
28+
globalflags.RegionFlag: testRegion,
29+
organizationIdFlag: testOrgId,
30+
networkAreaIdFlag: testNetworkAreaId,
31+
}
32+
for _, mod := range mods {
33+
mod(flagValues)
34+
}
35+
return flagValues
36+
}
37+
38+
func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
39+
model := &inputModel{
40+
GlobalFlagModel: &globalflags.GlobalFlagModel{
41+
Verbosity: globalflags.VerbosityDefault,
42+
Region: testRegion,
43+
},
44+
OrganizationId: utils.Ptr(testOrgId),
45+
NetworkAreaId: utils.Ptr(testNetworkAreaId),
46+
RoutingTableId: utils.Ptr(testRoutingTableId),
47+
}
48+
for _, mod := range mods {
49+
mod(model)
50+
}
51+
return model
52+
}
53+
54+
func fixtureArgValues(mods ...func(argValues []string)) []string {
55+
argValues := []string{
56+
testRoutingTableId,
57+
}
58+
for _, mod := range mods {
59+
mod(argValues)
60+
}
61+
return argValues
62+
}
63+
64+
func TestParseInput(t *testing.T) {
65+
tests := []struct {
66+
description string
67+
flagValues map[string]string
68+
argValues []string
69+
isValid bool
70+
expectedModel *inputModel
71+
}{
72+
{
73+
description: "base",
74+
flagValues: fixtureFlagValues(),
75+
argValues: fixtureArgValues(),
76+
isValid: true,
77+
expectedModel: fixtureInputModel(),
78+
},
79+
{
80+
description: "no values",
81+
argValues: []string{},
82+
flagValues: map[string]string{},
83+
isValid: false,
84+
},
85+
{
86+
description: "network-area-id missing",
87+
argValues: fixtureArgValues(),
88+
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
89+
delete(flagValues, networkAreaIdFlag)
90+
}),
91+
isValid: false,
92+
},
93+
{
94+
description: "org-id missing",
95+
argValues: fixtureArgValues(),
96+
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
97+
delete(flagValues, organizationIdFlag)
98+
}),
99+
isValid: false,
100+
},
101+
}
102+
103+
for _, tt := range tests {
104+
t.Run(tt.description, func(t *testing.T) {
105+
p := print.NewPrinter()
106+
cmd := NewCmd(&params.CmdParams{Printer: p})
107+
err := globalflags.Configure(cmd.Flags())
108+
if err != nil {
109+
t.Fatalf("configure global flags: %v", err)
110+
}
111+
112+
for flag, value := range tt.flagValues {
113+
err := cmd.Flags().Set(flag, value)
114+
if err != nil {
115+
if !tt.isValid {
116+
return
117+
}
118+
t.Fatalf("setting flag --%s=%s: %v", flag, value, err)
119+
}
120+
}
121+
122+
err = cmd.ValidateRequiredFlags()
123+
if err != nil {
124+
if !tt.isValid {
125+
return
126+
}
127+
t.Fatalf("error validating flags: %v", err)
128+
}
129+
130+
model, err := parseInput(p, cmd, tt.argValues)
131+
if err != nil {
132+
if !tt.isValid {
133+
return
134+
}
135+
t.Fatalf("error parsing flags: %v", err)
136+
}
137+
138+
if !tt.isValid {
139+
t.Fatalf("did not fail on invalid input")
140+
}
141+
diff := cmp.Diff(model, tt.expectedModel)
142+
if diff != "" {
143+
t.Fatalf("Data does not match: %s", diff)
144+
}
145+
})
146+
}
147+
}
148+
149+
func TestOutputResult(t *testing.T) {
150+
dummyRouteTable := iaasalpha.RoutingTable{
151+
CreatedAt: utils.Ptr(time.Now()),
152+
Default: nil,
153+
Description: utils.Ptr("description"),
154+
Id: utils.Ptr("route-foo"),
155+
Labels: utils.ConvertStringMapToInterfaceMap(testLabels),
156+
Name: utils.Ptr("route-foo"),
157+
SystemRoutes: utils.Ptr(true),
158+
UpdatedAt: utils.Ptr(time.Now()),
159+
}
160+
161+
tests := []struct {
162+
name string
163+
outputFormat string
164+
routingTable iaasalpha.RoutingTable
165+
wantErr bool
166+
}{
167+
{
168+
name: "json output with one route",
169+
outputFormat: print.JSONOutputFormat,
170+
routingTable: dummyRouteTable,
171+
wantErr: false,
172+
},
173+
{
174+
name: "yaml output with one route",
175+
outputFormat: print.YAMLOutputFormat,
176+
routingTable: dummyRouteTable,
177+
wantErr: false,
178+
},
179+
}
180+
181+
p := print.NewPrinter()
182+
p.Cmd = NewCmd(&params.CmdParams{Printer: p})
183+
for _, tt := range tests {
184+
t.Run(tt.name, func(t *testing.T) {
185+
if err := outputResult(p, tt.outputFormat, &tt.routingTable); (err != nil) != tt.wantErr {
186+
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
187+
}
188+
})
189+
}
190+
}

internal/cmd/beta/routingtable/list/list.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ import (
2424
)
2525

2626
const (
27-
limitFlag = "limit"
2827
organizationIdFlag = "organization-id"
2928
networkAreaIdFlag = "network-area-id"
3029
labelSelectorFlag = "label-selector"
30+
limitFlag = "limit"
3131
)
3232

3333
type inputModel struct {
@@ -47,15 +47,15 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
4747
Example: examples.Build(
4848
examples.NewExample(
4949
`List all routing-tables`,
50-
`$ stackit beta routing-table list --organization-id xxx --network-area-id xxx`,
50+
`$ stackit beta routing-table list --organization-id xxx --network-area-id yyy`,
5151
),
5252
examples.NewExample(
5353
`List all routing-tables with labels`,
54-
`$ stackit beta routing-table list --label-selector env=dev,env=rc --organization-id xxx --network-area-id xxx`,
54+
`$ stackit beta routing-table list --label-selector env=dev,env=rc --organization-id xxx --network-area-id yyy`,
5555
),
5656
examples.NewExample(
5757
`List all routing-tables with labels and limit to 10`,
58-
`$ stackit beta routing-table list --label-selector env=dev,env=rc --limit 10 --organization-id xxx --network-area-id xxx`,
58+
`$ stackit beta routing-table list --label-selector env=dev,env=rc --limit 10 --organization-id xxx --network-area-id yyy`,
5959
),
6060
),
6161
RunE: func(cmd *cobra.Command, _ []string) error {
@@ -123,9 +123,6 @@ func configureFlags(cmd *cobra.Command) {
123123

124124
func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
125125
globalFlags := globalflags.Parse(p, cmd)
126-
if globalFlags.ProjectId == "" {
127-
return nil, &errors.ProjectIdError{}
128-
}
129126

130127
limit := flags.FlagToInt64Pointer(p, cmd, limitFlag)
131128
if limit != nil && *limit < 1 {

0 commit comments

Comments
 (0)