Skip to content

Commit 091dadf

Browse files
committed
extend unit tests
1 parent 52713b9 commit 091dadf

File tree

1 file changed

+102
-2
lines changed

1 file changed

+102
-2
lines changed

internal/cmd/beta/network/create/create_test.go

Lines changed: 102 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ func TestParseInput(t *testing.T) {
285285
}
286286

287287
func TestBuildRequest(t *testing.T) {
288-
tests := []struct {
288+
var tests = []struct {
289289
description string
290290
model *inputModel
291291
expectedRequest iaas.ApiCreateNetworkRequest
@@ -306,8 +306,108 @@ func TestBuildRequest(t *testing.T) {
306306
},
307307
expectedRequest: fixtureRequiredRequest(),
308308
},
309+
{
310+
description: "non-routed network",
311+
model: &inputModel{
312+
GlobalFlagModel: &globalflags.GlobalFlagModel{
313+
ProjectId: testProjectId,
314+
Verbosity: globalflags.VerbosityDefault,
315+
},
316+
Name: utils.Ptr("example-network-name"),
317+
NonRouted: true,
318+
},
319+
expectedRequest: testClient.CreateNetwork(testCtx, testProjectId).CreateNetworkPayload(iaas.CreateNetworkPayload{
320+
Name: utils.Ptr("example-network-name"),
321+
Routed: utils.Ptr(false),
322+
}),
323+
},
324+
{
325+
description: "use dns servers, prefix, gateway and prefix length",
326+
model: &inputModel{
327+
GlobalFlagModel: &globalflags.GlobalFlagModel{
328+
ProjectId: testProjectId,
329+
Verbosity: globalflags.VerbosityDefault,
330+
},
331+
IPv4DnsNameServers: utils.Ptr([]string{"1.1.1.1"}),
332+
IPv4PrefixLength: utils.Ptr(int64(25)),
333+
IPv4Prefix: utils.Ptr("10.1.2.0/24"),
334+
IPv4Gateway: utils.Ptr("10.1.2.3"),
335+
},
336+
expectedRequest: testClient.CreateNetwork(testCtx, testProjectId).CreateNetworkPayload(iaas.CreateNetworkPayload{
337+
AddressFamily: &iaas.CreateNetworkAddressFamily{
338+
Ipv4: &iaas.CreateNetworkIPv4Body{
339+
Nameservers: utils.Ptr([]string{"1.1.1.1"}),
340+
PrefixLength: utils.Ptr(int64(25)),
341+
Prefix: utils.Ptr("10.1.2.0/24"),
342+
Gateway: iaas.NewNullableString(utils.Ptr("10.1.2.3")),
343+
},
344+
},
345+
Routed: utils.Ptr(true),
346+
}),
347+
},
348+
{
349+
description: "use ipv4 gateway nil",
350+
model: &inputModel{
351+
GlobalFlagModel: &globalflags.GlobalFlagModel{
352+
ProjectId: testProjectId,
353+
Verbosity: globalflags.VerbosityDefault,
354+
},
355+
NoIPv4Gateway: true,
356+
IPv4Gateway: nil,
357+
},
358+
expectedRequest: testClient.CreateNetwork(testCtx, testProjectId).CreateNetworkPayload(iaas.CreateNetworkPayload{
359+
AddressFamily: &iaas.CreateNetworkAddressFamily{
360+
Ipv4: &iaas.CreateNetworkIPv4Body{
361+
Gateway: iaas.NewNullableString(nil),
362+
},
363+
},
364+
Routed: utils.Ptr(true),
365+
}),
366+
},
367+
{
368+
description: "use ipv6 dns servers, prefix, gateway and prefix length",
369+
model: &inputModel{
370+
GlobalFlagModel: &globalflags.GlobalFlagModel{
371+
ProjectId: testProjectId,
372+
Verbosity: globalflags.VerbosityDefault,
373+
},
374+
IPv6DnsNameServers: utils.Ptr([]string{"2001:4860:4860::8888"}),
375+
IPv6PrefixLength: utils.Ptr(int64(25)),
376+
IPv6Prefix: utils.Ptr("2001:4860:4860::8888"),
377+
IPv6Gateway: utils.Ptr("2001:4860:4860::8888"),
378+
},
379+
expectedRequest: testClient.CreateNetwork(testCtx, testProjectId).CreateNetworkPayload(iaas.CreateNetworkPayload{
380+
AddressFamily: &iaas.CreateNetworkAddressFamily{
381+
Ipv6: &iaas.CreateNetworkIPv6Body{
382+
Nameservers: utils.Ptr([]string{"2001:4860:4860::8888"}),
383+
PrefixLength: utils.Ptr(int64(25)),
384+
Prefix: utils.Ptr("2001:4860:4860::8888"),
385+
Gateway: iaas.NewNullableString(utils.Ptr("2001:4860:4860::8888")),
386+
},
387+
},
388+
Routed: utils.Ptr(true),
389+
}),
390+
},
391+
{
392+
description: "use ipv6 gateway nil",
393+
model: &inputModel{
394+
GlobalFlagModel: &globalflags.GlobalFlagModel{
395+
ProjectId: testProjectId,
396+
Verbosity: globalflags.VerbosityDefault,
397+
},
398+
NoIPv6Gateway: true,
399+
IPv6Gateway: nil,
400+
},
401+
expectedRequest: testClient.CreateNetwork(testCtx, testProjectId).CreateNetworkPayload(iaas.CreateNetworkPayload{
402+
AddressFamily: &iaas.CreateNetworkAddressFamily{
403+
Ipv6: &iaas.CreateNetworkIPv6Body{
404+
Gateway: iaas.NewNullableString(nil),
405+
},
406+
},
407+
Routed: utils.Ptr(true),
408+
}),
409+
},
309410
}
310-
311411
for _, tt := range tests {
312412
t.Run(tt.description, func(t *testing.T) {
313413
request := buildRequest(testCtx, tt.model, testClient)

0 commit comments

Comments
 (0)