@@ -31,6 +31,21 @@ const testCreateSubnetOutputJSON = `
3131}
3232`
3333
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+
3449var testGetSubnetByIDOutputExpected = Subnet {
3550 ID : 8 ,
3651 SubnetAddress : "10.10.3.0" ,
@@ -189,6 +204,15 @@ const testGetSubnetsByCIDROutputJSON = `
189204}
190205`
191206
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+
192216const testGetFirstFreeAddressOutputExpected = "10.10.1.1"
193217const testGetFirstFreeAddressOutputJSON = `
194218{
@@ -503,6 +527,27 @@ func TestCreateSubnet(t *testing.T) {
503527 }
504528}
505529
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+
506551func TestGetSubnetByID (t * testing.T ) {
507552 ts := httpOKTestServer (testGetSubnetByIDOutputJSON )
508553 defer ts .Close ()
@@ -539,6 +584,26 @@ func TestGetSubnetsByCIDR(t *testing.T) {
539584 }
540585}
541586
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+
542607func TestGetFirstFreeAddress (t * testing.T ) {
543608 ts := httpOKTestServer (testGetFirstFreeAddressOutputJSON )
544609 defer ts .Close ()
0 commit comments