@@ -31,6 +31,21 @@ const testCreateSubnetOutputJSON = `
31
31
}
32
32
`
33
33
34
+ var testCreateFirstFreeSubnetInput = Subnet {
35
+ Description : "Subnet1" ,
36
+ }
37
+
38
+ const testCreateFirstFreeSubnetOutputExpected = "10.10.4.0/25"
39
+ const testCreateFirstFreeSubnetOutputJSON = `
40
+ {
41
+ "code": 201,
42
+ "success": true,
43
+ "message": "Subnet created",
44
+ "id": "10",
45
+ "data": "10.10.4.0/25"
46
+ }
47
+ `
48
+
34
49
var testGetSubnetByIDOutputExpected = Subnet {
35
50
ID : 8 ,
36
51
SubnetAddress : "10.10.3.0" ,
@@ -189,6 +204,15 @@ const testGetSubnetsByCIDROutputJSON = `
189
204
}
190
205
`
191
206
207
+ const testGetFirstFreeSubnetOutputExpected = "10.10.4.0/25"
208
+ const testGetFirstFreeSubnetOutputJSON = `
209
+ {
210
+ "code": 200,
211
+ "success": true,
212
+ "data": "10.10.4.0/25"
213
+ }
214
+ `
215
+
192
216
const testGetFirstFreeAddressOutputExpected = "10.10.1.1"
193
217
const testGetFirstFreeAddressOutputJSON = `
194
218
{
@@ -503,6 +527,27 @@ func TestCreateSubnet(t *testing.T) {
503
527
}
504
528
}
505
529
530
+ func TestCreateFirstFreeSubnet (t * testing.T ){
531
+ ts := httpCreatedTestServer (testCreateFirstFreeSubnetOutputJSON )
532
+ defer ts .Close ()
533
+ sess := fullSessionConfig ()
534
+ sess .Config .Endpoint = ts .URL
535
+ client := NewController (sess )
536
+
537
+ in := testCreateFirstFreeSubnetInput
538
+ mask := 25
539
+ id := 2
540
+ expected := testCreateFirstFreeSubnetOutputExpected
541
+ actual , err := client .CreateFirstFreeSubnet (id , mask , in )
542
+ if err != nil {
543
+ t .Fatalf ("Bad: %s" , err )
544
+ }
545
+
546
+ if ! reflect .DeepEqual (expected , actual ) {
547
+ t .Fatalf ("Expected %#v, got %#v" , expected , actual )
548
+ }
549
+ }
550
+
506
551
func TestGetSubnetByID (t * testing.T ) {
507
552
ts := httpOKTestServer (testGetSubnetByIDOutputJSON )
508
553
defer ts .Close ()
@@ -539,6 +584,26 @@ func TestGetSubnetsByCIDR(t *testing.T) {
539
584
}
540
585
}
541
586
587
+ func TestGetFirstFreeSubnet (t * testing.T ) {
588
+ ts := httpOKTestServer (testGetFirstFreeSubnetOutputJSON )
589
+ defer ts .Close ()
590
+ sess := fullSessionConfig ()
591
+ sess .Config .Endpoint = ts .URL
592
+ client := NewController (sess )
593
+
594
+ id := 2
595
+ mask := 25
596
+ expected := testGetFirstFreeSubnetOutputExpected
597
+ actual , err := client .GetFirstFreeSubnet (id , mask )
598
+ if err != nil {
599
+ t .Fatalf ("Bad: %s" , err )
600
+ }
601
+
602
+ if ! reflect .DeepEqual (expected , actual ) {
603
+ t .Fatalf ("Expected %#v, got %#v" , expected , actual )
604
+ }
605
+ }
606
+
542
607
func TestGetFirstFreeAddress (t * testing.T ) {
543
608
ts := httpOKTestServer (testGetFirstFreeAddressOutputJSON )
544
609
defer ts .Close ()
0 commit comments