@@ -9,10 +9,10 @@ import (
99 "github.com/google/go-cmp/cmp"
1010 "github.com/google/go-cmp/cmp/cmpopts"
1111 "github.com/google/uuid"
12- "github.com/stackitcloud/stackit-cli/internal/cmd/params"
1312 "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
14- pprint "github.com/stackitcloud/stackit-cli/internal/pkg/print"
13+ "github.com/stackitcloud/stackit-cli/internal/pkg/print"
1514 "github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
15+ "github.com/stackitcloud/stackit-cli/internal/pkg/types"
1616 "github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1717 "github.com/stackitcloud/stackit-sdk-go/services/iaas"
1818)
@@ -29,8 +29,10 @@ var testNetworkAreaId = uuid.NewString()
2929
3030const testRoutingTableName = "test"
3131const testRoutingTableDescription = "test"
32- const systemRoutesDisabled = true
33- const dynamicRoutesDisabled = true
32+
33+ const testNonSystemRoutes = false
34+ const testNonDynamicRoutes = false
35+
3436const testLabelSelectorFlag = "key1=value1,key2=value2"
3537
3638var testLabels = & map [string ]string {
@@ -45,8 +47,8 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st
4547 networkAreaIdFlag : testNetworkAreaId ,
4648 descriptionFlag : testRoutingTableDescription ,
4749 nameFlag : testRoutingTableName ,
48- nonSystemRoutesFlag : strconv .FormatBool (systemRoutesDisabled ),
49- nonDynamicRoutesFlag : strconv .FormatBool (dynamicRoutesDisabled ),
50+ nonSystemRoutesFlag : strconv .FormatBool (testNonSystemRoutes ),
51+ nonDynamicRoutesFlag : strconv .FormatBool (testNonDynamicRoutes ),
5052 labelFlag : testLabelSelectorFlag ,
5153 }
5254 for _ , mod := range mods {
@@ -65,8 +67,8 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6567 NetworkAreaId : testNetworkAreaId ,
6668 Name : testRoutingTableName ,
6769 Description : utils .Ptr (testRoutingTableDescription ),
68- NonSystemRoutes : systemRoutesDisabled ,
69- NonDynamicRoutes : dynamicRoutesDisabled ,
70+ NonSystemRoutes : testNonSystemRoutes ,
71+ NonDynamicRoutes : testNonDynamicRoutes ,
7072 Labels : utils .Ptr (* testLabels ),
7173 }
7274 for _ , mod := range mods {
@@ -85,22 +87,12 @@ func fixtureRequest(mods ...func(request *iaas.ApiAddRoutingTableToAreaRequest))
8587}
8688
8789func fixturePayload (mods ... func (payload * iaas.AddRoutingTableToAreaPayload )) iaas.AddRoutingTableToAreaPayload {
88- systemRoutes := true
89- if dynamicRoutesDisabled {
90- systemRoutes = false
91- }
92-
93- dynamicRoutes := true
94- if systemRoutesDisabled {
95- dynamicRoutes = false
96- }
97-
9890 payload := iaas.AddRoutingTableToAreaPayload {
9991 Description : utils .Ptr (testRoutingTableDescription ),
10092 Name : utils .Ptr (testRoutingTableName ),
10193 Labels : utils .ConvertStringMapToInterfaceMap (testLabels ),
102- SystemRoutes : utils .Ptr (systemRoutes ),
103- DynamicRoutes : utils .Ptr (dynamicRoutes ),
94+ SystemRoutes : utils .Ptr (true ),
95+ DynamicRoutes : utils .Ptr (true ),
10496 }
10597
10698 for _ , mod := range mods {
@@ -124,7 +116,7 @@ func TestParseInput(t *testing.T) {
124116 expectedModel : fixtureInputModel (),
125117 },
126118 {
127- description : "dynamic_routes disabled" ,
119+ description : "dynamic routes disabled" ,
128120 flagValues : fixtureFlagValues (func (flagValues map [string ]string ) {
129121 flagValues [nonDynamicRoutesFlag ] = "true"
130122 }),
@@ -134,7 +126,7 @@ func TestParseInput(t *testing.T) {
134126 }),
135127 },
136128 {
137- description : "system_routes disabled" ,
129+ description : "system routes disabled" ,
138130 flagValues : fixtureFlagValues (func (flagValues map [string ]string ) {
139131 flagValues [nonSystemRoutesFlag ] = "true"
140132 }),
@@ -243,9 +235,11 @@ func TestBuildRequest(t *testing.T) {
243235 model .Labels = nil
244236 }),
245237 expectedRequest : fixtureRequest (func (request * iaas.ApiAddRoutingTableToAreaRequest ) {
246- * request = (* request ).AddRoutingTableToAreaPayload (fixturePayload (func (payload * iaas.AddRoutingTableToAreaPayload ) {
247- payload .Labels = nil
248- }))
238+ * request = (* request ).AddRoutingTableToAreaPayload (
239+ fixturePayload (func (payload * iaas.AddRoutingTableToAreaPayload ) {
240+ payload .Labels = nil
241+ }),
242+ )
249243 }),
250244 },
251245 {
@@ -254,9 +248,11 @@ func TestBuildRequest(t *testing.T) {
254248 model .NonSystemRoutes = true
255249 }),
256250 expectedRequest : fixtureRequest (func (request * iaas.ApiAddRoutingTableToAreaRequest ) {
257- * request = (* request ).AddRoutingTableToAreaPayload (fixturePayload (func (payload * iaas.AddRoutingTableToAreaPayload ) {
258- payload .SystemRoutes = utils .Ptr (false )
259- }))
251+ * request = (* request ).AddRoutingTableToAreaPayload (
252+ fixturePayload (func (payload * iaas.AddRoutingTableToAreaPayload ) {
253+ payload .SystemRoutes = utils .Ptr (false )
254+ }),
255+ )
260256 }),
261257 },
262258 {
@@ -265,9 +261,11 @@ func TestBuildRequest(t *testing.T) {
265261 model .NonDynamicRoutes = true
266262 }),
267263 expectedRequest : fixtureRequest (func (request * iaas.ApiAddRoutingTableToAreaRequest ) {
268- * request = (* request ).AddRoutingTableToAreaPayload (fixturePayload (func (payload * iaas.AddRoutingTableToAreaPayload ) {
269- payload .DynamicRoutes = utils .Ptr (false )
270- }))
264+ * request = (* request ).AddRoutingTableToAreaPayload (
265+ fixturePayload (func (payload * iaas.AddRoutingTableToAreaPayload ) {
266+ payload .DynamicRoutes = utils .Ptr (false )
267+ }),
268+ )
271269 }),
272270 },
273271 }
@@ -314,32 +312,32 @@ func TestOutputResult(t *testing.T) {
314312 },
315313 {
316314 name : "empty routing-table" ,
317- outputFormat : "" ,
315+ outputFormat : print . PrettyOutputFormat ,
318316 routingTable : & iaas.RoutingTable {},
319317 wantErr : true ,
320318 },
321319 {
322- name : "table output routing-table" ,
323- outputFormat : "" ,
320+ name : "pretty output routing-table" ,
321+ outputFormat : print . PrettyOutputFormat ,
324322 routingTable : & dummyRoutingTable ,
325323 wantErr : false ,
326324 },
327325 {
328326 name : "json output routing-table" ,
329- outputFormat : pprint .JSONOutputFormat ,
327+ outputFormat : print .JSONOutputFormat ,
330328 routingTable : & dummyRoutingTable ,
331329 wantErr : false ,
332330 },
333331 {
334332 name : "yaml output routing-table" ,
335- outputFormat : pprint .YAMLOutputFormat ,
333+ outputFormat : print .YAMLOutputFormat ,
336334 routingTable : & dummyRoutingTable ,
337335 wantErr : false ,
338336 },
339337 }
340338
341- p := pprint .NewPrinter ()
342- p .Cmd = NewCmd (& params .CmdParams {Printer : p })
339+ p := print .NewPrinter ()
340+ p .Cmd = NewCmd (& types .CmdParams {Printer : p })
343341 for _ , tt := range tests {
344342 t .Run (tt .name , func (t * testing.T ) {
345343 if err := outputResult (p , tt .outputFormat , tt .routingTable ); (err != nil ) != tt .wantErr {
0 commit comments