move unit tests into 'testing' directories
diff --git a/openstack/networking/v2/subnets/errors.go b/openstack/networking/v2/subnets/errors.go
deleted file mode 100644
index d2f7b46..0000000
--- a/openstack/networking/v2/subnets/errors.go
+++ /dev/null
@@ -1,14 +0,0 @@
-package subnets
-
-import "fmt"
-
-func err(str string) error {
- return fmt.Errorf("%s", str)
-}
-
-var (
- errNetworkIDRequired = err("A network ID is required")
- errCIDRRequired = err("A valid CIDR is required")
- errInvalidIPType = err("An IP type must either be 4 or 6")
- errInvalidGatewayConfig = err("Both disabling the gateway and specifying a gateway is not allowed")
-)
diff --git a/openstack/networking/v2/subnets/testing/doc.go b/openstack/networking/v2/subnets/testing/doc.go
new file mode 100644
index 0000000..7603f83
--- /dev/null
+++ b/openstack/networking/v2/subnets/testing/doc.go
@@ -0,0 +1 @@
+package testing
diff --git a/openstack/networking/v2/subnets/requests_test.go b/openstack/networking/v2/subnets/testing/requests_test.go
similarity index 85%
rename from openstack/networking/v2/subnets/requests_test.go
rename to openstack/networking/v2/subnets/testing/requests_test.go
index 4241c63..13fa9df 100644
--- a/openstack/networking/v2/subnets/requests_test.go
+++ b/openstack/networking/v2/subnets/testing/requests_test.go
@@ -1,4 +1,4 @@
-package subnets
+package testing
import (
"fmt"
@@ -6,6 +6,7 @@
"testing"
fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common"
+ "github.com/gophercloud/gophercloud/openstack/networking/v2/subnets"
"github.com/gophercloud/gophercloud/pagination"
th "github.com/gophercloud/gophercloud/testhelper"
)
@@ -85,64 +86,64 @@
count := 0
- List(fake.ServiceClient(), ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
+ subnets.List(fake.ServiceClient(), subnets.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
count++
- actual, err := ExtractSubnets(page)
+ actual, err := subnets.ExtractSubnets(page)
if err != nil {
t.Errorf("Failed to extract subnets: %v", err)
return false, nil
}
- expected := []Subnet{
- Subnet{
+ expected := []subnets.Subnet{
+ {
Name: "private-subnet",
EnableDHCP: true,
NetworkID: "db193ab3-96e3-4cb3-8fc5-05f4296d0324",
TenantID: "26a7980765d0414dbc1fc1f88cdb7e6e",
DNSNameservers: []string{},
- AllocationPools: []AllocationPool{
- AllocationPool{
+ AllocationPools: []subnets.AllocationPool{
+ {
Start: "10.0.0.2",
End: "10.0.0.254",
},
},
- HostRoutes: []HostRoute{},
+ HostRoutes: []subnets.HostRoute{},
IPVersion: 4,
GatewayIP: "10.0.0.1",
CIDR: "10.0.0.0/24",
ID: "08eae331-0402-425a-923c-34f7cfe39c1b",
},
- Subnet{
+ {
Name: "my_subnet",
EnableDHCP: true,
NetworkID: "d32019d3-bc6e-4319-9c1d-6722fc136a22",
TenantID: "4fd44f30292945e481c7b8a0c8908869",
DNSNameservers: []string{},
- AllocationPools: []AllocationPool{
- AllocationPool{
+ AllocationPools: []subnets.AllocationPool{
+ {
Start: "192.0.0.2",
End: "192.255.255.254",
},
},
- HostRoutes: []HostRoute{},
+ HostRoutes: []subnets.HostRoute{},
IPVersion: 4,
GatewayIP: "192.0.0.1",
CIDR: "192.0.0.0/8",
ID: "54d6f61d-db07-451c-9ab3-b9609b6b6f0b",
},
- Subnet{
+ subnets.Subnet{
Name: "my_gatewayless_subnet",
EnableDHCP: true,
NetworkID: "d32019d3-bc6e-4319-9c1d-6722fc136a23",
TenantID: "4fd44f30292945e481c7b8a0c8908869",
DNSNameservers: []string{},
- AllocationPools: []AllocationPool{
- AllocationPool{
+ AllocationPools: []subnets.AllocationPool{
+ {
Start: "192.168.1.2",
End: "192.168.1.254",
},
},
- HostRoutes: []HostRoute{},
+ HostRoutes: []subnets.HostRoute{},
IPVersion: 4,
GatewayIP: "",
CIDR: "192.168.1.0/24",
@@ -195,7 +196,7 @@
`)
})
- s, err := Get(fake.ServiceClient(), "54d6f61d-db07-451c-9ab3-b9609b6b6f0b").Extract()
+ s, err := subnets.Get(fake.ServiceClient(), "54d6f61d-db07-451c-9ab3-b9609b6b6f0b").Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, s.Name, "my_subnet")
@@ -203,13 +204,13 @@
th.AssertEquals(t, s.NetworkID, "d32019d3-bc6e-4319-9c1d-6722fc136a22")
th.AssertEquals(t, s.TenantID, "4fd44f30292945e481c7b8a0c8908869")
th.AssertDeepEquals(t, s.DNSNameservers, []string{})
- th.AssertDeepEquals(t, s.AllocationPools, []AllocationPool{
- AllocationPool{
+ th.AssertDeepEquals(t, s.AllocationPools, []subnets.AllocationPool{
+ {
Start: "192.0.0.2",
End: "192.255.255.254",
},
})
- th.AssertDeepEquals(t, s.HostRoutes, []HostRoute{})
+ th.AssertDeepEquals(t, s.HostRoutes, []subnets.HostRoute{})
th.AssertEquals(t, s.IPVersion, 4)
th.AssertEquals(t, s.GatewayIP, "192.0.0.1")
th.AssertEquals(t, s.CIDR, "192.0.0.0/8")
@@ -271,22 +272,22 @@
`)
})
- opts := CreateOpts{
+ opts := subnets.CreateOpts{
NetworkID: "d32019d3-bc6e-4319-9c1d-6722fc136a22",
IPVersion: 4,
CIDR: "192.168.199.0/24",
- AllocationPools: []AllocationPool{
- AllocationPool{
+ AllocationPools: []subnets.AllocationPool{
+ {
Start: "192.168.199.2",
End: "192.168.199.254",
},
},
DNSNameservers: []string{"foo"},
- HostRoutes: []HostRoute{
- HostRoute{NextHop: "bar"},
+ HostRoutes: []subnets.HostRoute{
+ {NextHop: "bar"},
},
}
- s, err := Create(fake.ServiceClient(), opts).Extract()
+ s, err := subnets.Create(fake.ServiceClient(), opts).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, s.Name, "")
@@ -294,13 +295,13 @@
th.AssertEquals(t, s.NetworkID, "d32019d3-bc6e-4319-9c1d-6722fc136a22")
th.AssertEquals(t, s.TenantID, "4fd44f30292945e481c7b8a0c8908869")
th.AssertDeepEquals(t, s.DNSNameservers, []string{})
- th.AssertDeepEquals(t, s.AllocationPools, []AllocationPool{
- AllocationPool{
+ th.AssertDeepEquals(t, s.AllocationPools, []subnets.AllocationPool{
+ {
Start: "192.168.199.2",
End: "192.168.199.254",
},
})
- th.AssertDeepEquals(t, s.HostRoutes, []HostRoute{})
+ th.AssertDeepEquals(t, s.HostRoutes, []subnets.HostRoute{})
th.AssertEquals(t, s.IPVersion, 4)
th.AssertEquals(t, s.GatewayIP, "192.168.199.1")
th.AssertEquals(t, s.CIDR, "192.168.199.0/24")
@@ -359,32 +360,32 @@
`)
})
- opts := CreateOpts{
+ opts := subnets.CreateOpts{
NetworkID: "d32019d3-bc6e-4319-9c1d-6722fc136a23",
IPVersion: 4,
CIDR: "192.168.1.0/24",
- AllocationPools: []AllocationPool{
- AllocationPool{
+ AllocationPools: []subnets.AllocationPool{
+ {
Start: "192.168.1.2",
End: "192.168.1.254",
},
},
DNSNameservers: []string{},
}
- s, err := Create(fake.ServiceClient(), opts).Extract()
+ s, err := subnets.Create(fake.ServiceClient(), opts).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, s.Name, "")
th.AssertEquals(t, s.EnableDHCP, true)
th.AssertEquals(t, s.NetworkID, "d32019d3-bc6e-4319-9c1d-6722fc136a23")
th.AssertEquals(t, s.TenantID, "4fd44f30292945e481c7b8a0c8908869")
- th.AssertDeepEquals(t, s.AllocationPools, []AllocationPool{
- AllocationPool{
+ th.AssertDeepEquals(t, s.AllocationPools, []subnets.AllocationPool{
+ {
Start: "192.168.1.2",
End: "192.168.1.254",
},
})
- th.AssertDeepEquals(t, s.HostRoutes, []HostRoute{})
+ th.AssertDeepEquals(t, s.HostRoutes, []subnets.HostRoute{})
th.AssertEquals(t, s.IPVersion, 4)
th.AssertEquals(t, s.GatewayIP, "")
th.AssertEquals(t, s.CIDR, "192.168.1.0/24")
@@ -392,17 +393,17 @@
}
func TestRequiredCreateOpts(t *testing.T) {
- res := Create(fake.ServiceClient(), CreateOpts{})
+ res := subnets.Create(fake.ServiceClient(), subnets.CreateOpts{})
if res.Err == nil {
t.Fatalf("Expected error, got none")
}
- res = Create(fake.ServiceClient(), CreateOpts{NetworkID: "foo"})
+ res = subnets.Create(fake.ServiceClient(), subnets.CreateOpts{NetworkID: "foo"})
if res.Err == nil {
t.Fatalf("Expected error, got none")
}
- res = Create(fake.ServiceClient(), CreateOpts{NetworkID: "foo", CIDR: "bar", IPVersion: 40})
+ res = subnets.Create(fake.ServiceClient(), subnets.CreateOpts{NetworkID: "foo", CIDR: "bar", IPVersion: 40})
if res.Err == nil {
t.Fatalf("Expected error, got none")
}
@@ -454,14 +455,14 @@
`)
})
- opts := UpdateOpts{
+ opts := subnets.UpdateOpts{
Name: "my_new_subnet",
DNSNameservers: []string{"foo"},
- HostRoutes: []HostRoute{
- HostRoute{NextHop: "bar"},
+ HostRoutes: []subnets.HostRoute{
+ {NextHop: "bar"},
},
}
- s, err := Update(fake.ServiceClient(), "08eae331-0402-425a-923c-34f7cfe39c1b", opts).Extract()
+ s, err := subnets.Update(fake.ServiceClient(), "08eae331-0402-425a-923c-34f7cfe39c1b", opts).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, s.Name, "my_new_subnet")
@@ -478,6 +479,6 @@
w.WriteHeader(http.StatusNoContent)
})
- res := Delete(fake.ServiceClient(), "08eae331-0402-425a-923c-34f7cfe39c1b")
+ res := subnets.Delete(fake.ServiceClient(), "08eae331-0402-425a-923c-34f7cfe39c1b")
th.AssertNoErr(t, res.Err)
}
diff --git a/openstack/networking/v2/subnets/results_test.go b/openstack/networking/v2/subnets/testing/results_test.go
similarity index 77%
rename from openstack/networking/v2/subnets/results_test.go
rename to openstack/networking/v2/subnets/testing/results_test.go
index ce71a46..a227ccd 100644
--- a/openstack/networking/v2/subnets/results_test.go
+++ b/openstack/networking/v2/subnets/testing/results_test.go
@@ -1,10 +1,12 @@
-package subnets
+package testing
import (
"encoding/json"
- "github.com/gophercloud/gophercloud"
- th "github.com/gophercloud/gophercloud/testhelper"
"testing"
+
+ "github.com/gophercloud/gophercloud"
+ "github.com/gophercloud/gophercloud/openstack/networking/v2/subnets"
+ th "github.com/gophercloud/gophercloud/testhelper"
)
func TestHostRoute(t *testing.T) {
@@ -26,7 +28,7 @@
"host_routes": [
{
"destination": "172.20.1.0/24",
- "nexthop": "172.16.0.2"
+ "nexthop": "172.16.0.2"
}
],
"ip_version": 4,
@@ -43,12 +45,15 @@
t.Fatalf("%s", err)
}
- resp := commonResult{gophercloud.Result{Body: dejson}}
- subnet, err := resp.Extract()
+ resp := gophercloud.Result{Body: dejson}
+ var subnetWrapper struct {
+ Subnet subnets.Subnet `json:"subnet"`
+ }
+ err = resp.ExtractInto(&subnetWrapper)
if err != nil {
t.Fatalf("%s", err)
}
- route := subnet.HostRoutes[0]
+ route := subnetWrapper.Subnet.HostRoutes[0]
th.AssertEquals(t, route.NextHop, "172.16.0.2")
th.AssertEquals(t, route.DestinationCIDR, "172.20.1.0/24")
}