move unit tests into 'testing' directories
diff --git a/openstack/blockstorage/v1/apiversions/testing/doc.go b/openstack/blockstorage/v1/apiversions/testing/doc.go
new file mode 100644
index 0000000..7603f83
--- /dev/null
+++ b/openstack/blockstorage/v1/apiversions/testing/doc.go
@@ -0,0 +1 @@
+package testing
diff --git a/openstack/blockstorage/v1/apiversions/requests_test.go b/openstack/blockstorage/v1/apiversions/testing/fixtures.go
similarity index 63%
rename from openstack/blockstorage/v1/apiversions/requests_test.go
rename to openstack/blockstorage/v1/apiversions/testing/fixtures.go
index 3a14c99..885fdf6 100644
--- a/openstack/blockstorage/v1/apiversions/requests_test.go
+++ b/openstack/blockstorage/v1/apiversions/testing/fixtures.go
@@ -1,19 +1,15 @@
-package apiversions
+package testing
import (
"fmt"
"net/http"
"testing"
- "github.com/gophercloud/gophercloud/pagination"
th "github.com/gophercloud/gophercloud/testhelper"
"github.com/gophercloud/gophercloud/testhelper/client"
)
-func TestListVersions(t *testing.T) {
- th.SetupHTTP()
- defer th.TeardownHTTP()
-
+func MockListResponse(t *testing.T) {
th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
@@ -48,39 +44,9 @@
]
}`)
})
-
- count := 0
-
- List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
- count++
- actual, err := ExtractAPIVersions(page)
- th.AssertNoErr(t, err)
-
- expected := []APIVersion{
- APIVersion{
- ID: "v1.0",
- Status: "CURRENT",
- Updated: "2012-01-04T11:33:21Z",
- },
- APIVersion{
- ID: "v2.0",
- Status: "CURRENT",
- Updated: "2012-11-21T11:33:21Z",
- },
- }
-
- th.AssertDeepEquals(t, expected, actual)
-
- return true, nil
- })
-
- th.AssertEquals(t, 1, count)
}
-func TestAPIInfo(t *testing.T) {
- th.SetupHTTP()
- defer th.TeardownHTTP()
-
+func MockGetResponse(t *testing.T) {
th.Mux.HandleFunc("/v1/", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
@@ -122,17 +88,4 @@
}
}`)
})
-
- actual, err := Get(client.ServiceClient(), "v1").Extract()
- th.AssertNoErr(t, err)
-
- expected := APIVersion{
- ID: "v1.0",
- Status: "CURRENT",
- Updated: "2012-01-04T11:33:21Z",
- }
-
- th.AssertEquals(t, actual.ID, expected.ID)
- th.AssertEquals(t, actual.Status, expected.Status)
- th.AssertEquals(t, actual.Updated, expected.Updated)
}
diff --git a/openstack/blockstorage/v1/apiversions/testing/requests_test.go b/openstack/blockstorage/v1/apiversions/testing/requests_test.go
new file mode 100644
index 0000000..3103497
--- /dev/null
+++ b/openstack/blockstorage/v1/apiversions/testing/requests_test.go
@@ -0,0 +1,64 @@
+package testing
+
+import (
+ "testing"
+
+ "github.com/gophercloud/gophercloud/openstack/blockstorage/v1/apiversions"
+ "github.com/gophercloud/gophercloud/pagination"
+ th "github.com/gophercloud/gophercloud/testhelper"
+ "github.com/gophercloud/gophercloud/testhelper/client"
+)
+
+func TestListVersions(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ MockListResponse(t)
+
+ count := 0
+
+ apiversions.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
+ count++
+ actual, err := apiversions.ExtractAPIVersions(page)
+ th.AssertNoErr(t, err)
+
+ expected := []apiversions.APIVersion{
+ {
+ ID: "v1.0",
+ Status: "CURRENT",
+ Updated: "2012-01-04T11:33:21Z",
+ },
+ {
+ ID: "v2.0",
+ Status: "CURRENT",
+ Updated: "2012-11-21T11:33:21Z",
+ },
+ }
+
+ th.AssertDeepEquals(t, expected, actual)
+
+ return true, nil
+ })
+
+ th.AssertEquals(t, 1, count)
+}
+
+func TestAPIInfo(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ MockGetResponse(t)
+
+ actual, err := apiversions.Get(client.ServiceClient(), "v1").Extract()
+ th.AssertNoErr(t, err)
+
+ expected := apiversions.APIVersion{
+ ID: "v1.0",
+ Status: "CURRENT",
+ Updated: "2012-01-04T11:33:21Z",
+ }
+
+ th.AssertEquals(t, actual.ID, expected.ID)
+ th.AssertEquals(t, actual.Status, expected.Status)
+ th.AssertEquals(t, actual.Updated, expected.Updated)
+}
diff --git a/openstack/blockstorage/v1/snapshots/testing/doc.go b/openstack/blockstorage/v1/snapshots/testing/doc.go
new file mode 100644
index 0000000..7603f83
--- /dev/null
+++ b/openstack/blockstorage/v1/snapshots/testing/doc.go
@@ -0,0 +1 @@
+package testing
diff --git a/openstack/blockstorage/v1/snapshots/fixtures.go b/openstack/blockstorage/v1/snapshots/testing/fixtures.go
similarity index 98%
rename from openstack/blockstorage/v1/snapshots/fixtures.go
rename to openstack/blockstorage/v1/snapshots/testing/fixtures.go
index 1dcdfca..7bdc782 100644
--- a/openstack/blockstorage/v1/snapshots/fixtures.go
+++ b/openstack/blockstorage/v1/snapshots/testing/fixtures.go
@@ -1,6 +1,4 @@
-// +build fixtures
-
-package snapshots
+package testing
import (
"fmt"
diff --git a/openstack/blockstorage/v1/snapshots/requests_test.go b/openstack/blockstorage/v1/snapshots/testing/requests_test.go
similarity index 67%
rename from openstack/blockstorage/v1/snapshots/requests_test.go
rename to openstack/blockstorage/v1/snapshots/testing/requests_test.go
index 410b753..cfb206b 100644
--- a/openstack/blockstorage/v1/snapshots/requests_test.go
+++ b/openstack/blockstorage/v1/snapshots/testing/requests_test.go
@@ -1,8 +1,9 @@
-package snapshots
+package testing
import (
"testing"
+ "github.com/gophercloud/gophercloud/openstack/blockstorage/v1/snapshots"
"github.com/gophercloud/gophercloud/pagination"
th "github.com/gophercloud/gophercloud/testhelper"
"github.com/gophercloud/gophercloud/testhelper/client"
@@ -16,20 +17,20 @@
count := 0
- List(client.ServiceClient(), &ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
+ snapshots.List(client.ServiceClient(), &snapshots.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
count++
- actual, err := ExtractSnapshots(page)
+ actual, err := snapshots.ExtractSnapshots(page)
if err != nil {
t.Errorf("Failed to extract snapshots: %v", err)
return false, err
}
- expected := []Snapshot{
- Snapshot{
+ expected := []snapshots.Snapshot{
+ {
ID: "289da7f8-6440-407c-9fb4-7db01ec49164",
Name: "snapshot-001",
},
- Snapshot{
+ {
ID: "96c3bda7-c82a-4f50-be73-ca7621794835",
Name: "snapshot-002",
},
@@ -51,7 +52,7 @@
MockGetResponse(t)
- v, err := Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").Extract()
+ v, err := snapshots.Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, v.Name, "snapshot-001")
@@ -64,8 +65,8 @@
MockCreateResponse(t)
- options := CreateOpts{VolumeID: "1234", Name: "snapshot-001"}
- n, err := Create(client.ServiceClient(), options).Extract()
+ options := snapshots.CreateOpts{VolumeID: "1234", Name: "snapshot-001"}
+ n, err := snapshots.Create(client.ServiceClient(), options).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, n.VolumeID, "1234")
@@ -81,13 +82,13 @@
expected := map[string]interface{}{"key": "v1"}
- options := &UpdateMetadataOpts{
+ options := &snapshots.UpdateMetadataOpts{
Metadata: map[string]interface{}{
"key": "v1",
},
}
- actual, err := UpdateMetadata(client.ServiceClient(), "123", options).ExtractMetadata()
+ actual, err := snapshots.UpdateMetadata(client.ServiceClient(), "123", options).ExtractMetadata()
th.AssertNoErr(t, err)
th.AssertDeepEquals(t, actual, expected)
@@ -99,6 +100,6 @@
MockDeleteResponse(t)
- res := Delete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22")
+ res := snapshots.Delete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22")
th.AssertNoErr(t, res.Err)
}
diff --git a/openstack/blockstorage/v1/volumes/testing/doc.go b/openstack/blockstorage/v1/volumes/testing/doc.go
index 60fc22a..2f66ba5 100644
--- a/openstack/blockstorage/v1/volumes/testing/doc.go
+++ b/openstack/blockstorage/v1/volumes/testing/doc.go
@@ -2,6 +2,6 @@
This is package created is to hold fixtures (which imports testing),
so that importing volumes package does not inadvertently import testing into production code
More information here:
-https://github.com/gophercloud/gophercloud/issues/473
+https://github.com/rackspace/gophercloud/issues/473
*/
package testing
diff --git a/openstack/blockstorage/v1/volumes/testing/fixtures.go b/openstack/blockstorage/v1/volumes/testing/fixtures.go
index 0d34d5e..421cbf4 100644
--- a/openstack/blockstorage/v1/volumes/testing/fixtures.go
+++ b/openstack/blockstorage/v1/volumes/testing/fixtures.go
@@ -1,5 +1,3 @@
-// +build fixtures
-
package testing
import (
diff --git a/openstack/blockstorage/v1/volumes/requests_test.go b/openstack/blockstorage/v1/volumes/testing/requests_test.go
similarity index 69%
rename from openstack/blockstorage/v1/volumes/requests_test.go
rename to openstack/blockstorage/v1/volumes/testing/requests_test.go
index 436cfdc..85a6cd8 100644
--- a/openstack/blockstorage/v1/volumes/requests_test.go
+++ b/openstack/blockstorage/v1/volumes/testing/requests_test.go
@@ -1,11 +1,11 @@
-package volumes
+package testing
import (
"testing"
"time"
"github.com/gophercloud/gophercloud"
- fixtures "github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes/testing"
+ "github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes"
"github.com/gophercloud/gophercloud/pagination"
th "github.com/gophercloud/gophercloud/testhelper"
"github.com/gophercloud/gophercloud/testhelper/client"
@@ -15,24 +15,24 @@
th.SetupHTTP()
defer th.TeardownHTTP()
- fixtures.MockListResponse(t)
+ MockListResponse(t)
count := 0
- List(client.ServiceClient(), &ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
+ volumes.List(client.ServiceClient(), &volumes.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
count++
- actual, err := ExtractVolumes(page)
+ actual, err := volumes.ExtractVolumes(page)
if err != nil {
t.Errorf("Failed to extract volumes: %v", err)
return false, err
}
- expected := []Volume{
- Volume{
+ expected := []volumes.Volume{
+ {
ID: "289da7f8-6440-407c-9fb4-7db01ec49164",
Name: "vol-001",
},
- Volume{
+ {
ID: "96c3bda7-c82a-4f50-be73-ca7621794835",
Name: "vol-002",
},
@@ -52,19 +52,19 @@
th.SetupHTTP()
defer th.TeardownHTTP()
- fixtures.MockListResponse(t)
+ MockListResponse(t)
- allPages, err := List(client.ServiceClient(), &ListOpts{}).AllPages()
+ allPages, err := volumes.List(client.ServiceClient(), &volumes.ListOpts{}).AllPages()
th.AssertNoErr(t, err)
- actual, err := ExtractVolumes(allPages)
+ actual, err := volumes.ExtractVolumes(allPages)
th.AssertNoErr(t, err)
- expected := []Volume{
- Volume{
+ expected := []volumes.Volume{
+ {
ID: "289da7f8-6440-407c-9fb4-7db01ec49164",
Name: "vol-001",
},
- Volume{
+ {
ID: "96c3bda7-c82a-4f50-be73-ca7621794835",
Name: "vol-002",
},
@@ -78,12 +78,12 @@
th.SetupHTTP()
defer th.TeardownHTTP()
- fixtures.MockGetResponse(t)
+ MockGetResponse(t)
- actual, err := Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").Extract()
+ actual, err := volumes.Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").Extract()
th.AssertNoErr(t, err)
- expected := &Volume{
+ expected := &volumes.Volume{
Status: "active",
Name: "vol-001",
Attachments: []map[string]interface{}{
@@ -117,10 +117,10 @@
th.SetupHTTP()
defer th.TeardownHTTP()
- fixtures.MockCreateResponse(t)
+ MockCreateResponse(t)
- options := &CreateOpts{Size: 75}
- n, err := Create(client.ServiceClient(), options).Extract()
+ options := &volumes.CreateOpts{Size: 75}
+ n, err := volumes.Create(client.ServiceClient(), options).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, n.Size, 4)
@@ -131,9 +131,9 @@
th.SetupHTTP()
defer th.TeardownHTTP()
- fixtures.MockDeleteResponse(t)
+ MockDeleteResponse(t)
- res := Delete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22")
+ res := volumes.Delete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22")
th.AssertNoErr(t, res.Err)
}
@@ -141,10 +141,10 @@
th.SetupHTTP()
defer th.TeardownHTTP()
- fixtures.MockUpdateResponse(t)
+ MockUpdateResponse(t)
- options := UpdateOpts{Name: "vol-002"}
- v, err := Update(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22", options).Extract()
+ options := volumes.UpdateOpts{Name: "vol-002"}
+ v, err := volumes.Update(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22", options).Extract()
th.AssertNoErr(t, err)
th.CheckEquals(t, "vol-002", v.Name)
}
diff --git a/openstack/blockstorage/v1/volumetypes/testing/doc.go b/openstack/blockstorage/v1/volumetypes/testing/doc.go
new file mode 100644
index 0000000..7603f83
--- /dev/null
+++ b/openstack/blockstorage/v1/volumetypes/testing/doc.go
@@ -0,0 +1 @@
+package testing
diff --git a/openstack/blockstorage/v1/volumetypes/fixtures.go b/openstack/blockstorage/v1/volumetypes/testing/fixtures.go
similarity index 96%
rename from openstack/blockstorage/v1/volumetypes/fixtures.go
rename to openstack/blockstorage/v1/volumetypes/testing/fixtures.go
index cb6fadf..0e2715a 100644
--- a/openstack/blockstorage/v1/volumetypes/fixtures.go
+++ b/openstack/blockstorage/v1/volumetypes/testing/fixtures.go
@@ -1,6 +1,4 @@
-// +build fixtures
-
-package volumetypes
+package testing
import (
"fmt"
diff --git a/openstack/blockstorage/v1/volumetypes/requests_test.go b/openstack/blockstorage/v1/volumetypes/testing/requests_test.go
similarity index 78%
rename from openstack/blockstorage/v1/volumetypes/requests_test.go
rename to openstack/blockstorage/v1/volumetypes/testing/requests_test.go
index 72113ec..4244615 100644
--- a/openstack/blockstorage/v1/volumetypes/requests_test.go
+++ b/openstack/blockstorage/v1/volumetypes/testing/requests_test.go
@@ -1,10 +1,11 @@
-package volumetypes
+package testing
import (
"fmt"
"net/http"
"testing"
+ "github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumetypes"
"github.com/gophercloud/gophercloud/pagination"
th "github.com/gophercloud/gophercloud/testhelper"
"github.com/gophercloud/gophercloud/testhelper/client"
@@ -18,23 +19,23 @@
count := 0
- List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
+ volumetypes.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
count++
- actual, err := ExtractVolumeTypes(page)
+ actual, err := volumetypes.ExtractVolumeTypes(page)
if err != nil {
t.Errorf("Failed to extract volume types: %v", err)
return false, err
}
- expected := []VolumeType{
- VolumeType{
+ expected := []volumetypes.VolumeType{
+ {
ID: "289da7f8-6440-407c-9fb4-7db01ec49164",
Name: "vol-type-001",
ExtraSpecs: map[string]interface{}{
"capabilities": "gpu",
},
},
- VolumeType{
+ {
ID: "96c3bda7-c82a-4f50-be73-ca7621794835",
Name: "vol-type-002",
ExtraSpecs: map[string]interface{}{},
@@ -57,7 +58,7 @@
MockGetResponse(t)
- vt, err := Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").Extract()
+ vt, err := volumetypes.Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").Extract()
th.AssertNoErr(t, err)
th.AssertDeepEquals(t, vt.ExtraSpecs, map[string]interface{}{"serverNumber": "2"})
@@ -95,8 +96,8 @@
`)
})
- options := &CreateOpts{Name: "vol-type-001"}
- n, err := Create(client.ServiceClient(), options).Extract()
+ options := &volumetypes.CreateOpts{Name: "vol-type-001"}
+ n, err := volumetypes.Create(client.ServiceClient(), options).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, n.Name, "vol-type-001")
@@ -113,6 +114,6 @@
w.WriteHeader(http.StatusAccepted)
})
- err := Delete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").ExtractErr()
+ err := volumetypes.Delete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").ExtractErr()
th.AssertNoErr(t, err)
}