move unit tests into 'testing' directories
diff --git a/openstack/identity/v2/extensions/admin/roles/testing/doc.go b/openstack/identity/v2/extensions/admin/roles/testing/doc.go
new file mode 100644
index 0000000..7603f83
--- /dev/null
+++ b/openstack/identity/v2/extensions/admin/roles/testing/doc.go
@@ -0,0 +1 @@
+package testing
diff --git a/openstack/identity/v2/extensions/admin/roles/fixtures.go b/openstack/identity/v2/extensions/admin/roles/testing/fixtures.go
similarity index 97%
rename from openstack/identity/v2/extensions/admin/roles/fixtures.go
rename to openstack/identity/v2/extensions/admin/roles/testing/fixtures.go
index 6b11f5c..498c161 100644
--- a/openstack/identity/v2/extensions/admin/roles/fixtures.go
+++ b/openstack/identity/v2/extensions/admin/roles/testing/fixtures.go
@@ -1,6 +1,4 @@
-// +build fixtures
-
-package roles
+package testing
import (
"fmt"
diff --git a/openstack/identity/v2/extensions/admin/roles/requests_test.go b/openstack/identity/v2/extensions/admin/roles/testing/requests_test.go
similarity index 65%
rename from openstack/identity/v2/extensions/admin/roles/requests_test.go
rename to openstack/identity/v2/extensions/admin/roles/testing/requests_test.go
index cf3402d..8cf5395 100644
--- a/openstack/identity/v2/extensions/admin/roles/requests_test.go
+++ b/openstack/identity/v2/extensions/admin/roles/testing/requests_test.go
@@ -1,8 +1,9 @@
-package roles
+package testing
import (
"testing"
+ "github.com/gophercloud/gophercloud/openstack/identity/v2/extensions/admin/roles"
"github.com/gophercloud/gophercloud/pagination"
th "github.com/gophercloud/gophercloud/testhelper"
"github.com/gophercloud/gophercloud/testhelper/client"
@@ -16,16 +17,16 @@
count := 0
- err := List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
+ err := roles.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
count++
- actual, err := ExtractRoles(page)
+ actual, err := roles.ExtractRoles(page)
if err != nil {
t.Errorf("Failed to extract users: %v", err)
return false, err
}
- expected := []Role{
- Role{
+ expected := []roles.Role{
+ {
ID: "123",
Name: "compute:admin",
Description: "Nova Administrator",
@@ -47,7 +48,7 @@
MockAddUserRoleResponse(t)
- err := AddUser(client.ServiceClient(), "{tenant_id}", "{user_id}", "{role_id}").ExtractErr()
+ err := roles.AddUser(client.ServiceClient(), "{tenant_id}", "{user_id}", "{role_id}").ExtractErr()
th.AssertNoErr(t, err)
}
@@ -58,7 +59,7 @@
MockDeleteUserRoleResponse(t)
- err := DeleteUser(client.ServiceClient(), "{tenant_id}", "{user_id}", "{role_id}").ExtractErr()
+ err := roles.DeleteUser(client.ServiceClient(), "{tenant_id}", "{user_id}", "{role_id}").ExtractErr()
th.AssertNoErr(t, err)
}
diff --git a/openstack/identity/v2/extensions/delegate_test.go b/openstack/identity/v2/extensions/testing/delegate_test.go
similarity index 69%
rename from openstack/identity/v2/extensions/delegate_test.go
rename to openstack/identity/v2/extensions/testing/delegate_test.go
index b425130..e7869d8 100644
--- a/openstack/identity/v2/extensions/delegate_test.go
+++ b/openstack/identity/v2/extensions/testing/delegate_test.go
@@ -1,9 +1,10 @@
-package extensions
+package testing
import (
"testing"
- common "github.com/gophercloud/gophercloud/openstack/common/extensions"
+ common "github.com/gophercloud/gophercloud/openstack/common/extensions/testing"
+ "github.com/gophercloud/gophercloud/openstack/identity/v2/extensions"
"github.com/gophercloud/gophercloud/pagination"
th "github.com/gophercloud/gophercloud/testhelper"
"github.com/gophercloud/gophercloud/testhelper/client"
@@ -15,9 +16,9 @@
HandleListExtensionsSuccessfully(t)
count := 0
- err := List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
+ err := extensions.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
count++
- actual, err := ExtractExtensions(page)
+ actual, err := extensions.ExtractExtensions(page)
th.AssertNoErr(t, err)
th.CheckDeepEquals(t, common.ExpectedExtensions, actual)
@@ -32,7 +33,7 @@
defer th.TeardownHTTP()
common.HandleGetExtensionSuccessfully(t)
- actual, err := Get(client.ServiceClient(), "agent").Extract()
+ actual, err := extensions.Get(client.ServiceClient(), "agent").Extract()
th.AssertNoErr(t, err)
th.CheckDeepEquals(t, common.SingleExtension, actual)
}
diff --git a/openstack/identity/v2/extensions/testing/doc.go b/openstack/identity/v2/extensions/testing/doc.go
new file mode 100644
index 0000000..7603f83
--- /dev/null
+++ b/openstack/identity/v2/extensions/testing/doc.go
@@ -0,0 +1 @@
+package testing
diff --git a/openstack/identity/v2/extensions/fixtures.go b/openstack/identity/v2/extensions/testing/fixtures.go
similarity index 97%
rename from openstack/identity/v2/extensions/fixtures.go
rename to openstack/identity/v2/extensions/testing/fixtures.go
index 3fd5ad9..60afb74 100644
--- a/openstack/identity/v2/extensions/fixtures.go
+++ b/openstack/identity/v2/extensions/testing/fixtures.go
@@ -1,6 +1,4 @@
-// +build fixtures
-
-package extensions
+package testing
import (
"fmt"
diff --git a/openstack/identity/v2/tenants/testing/doc.go b/openstack/identity/v2/tenants/testing/doc.go
new file mode 100644
index 0000000..7603f83
--- /dev/null
+++ b/openstack/identity/v2/tenants/testing/doc.go
@@ -0,0 +1 @@
+package testing
diff --git a/openstack/identity/v2/tenants/fixtures.go b/openstack/identity/v2/tenants/testing/fixtures.go
similarity index 86%
rename from openstack/identity/v2/tenants/fixtures.go
rename to openstack/identity/v2/tenants/testing/fixtures.go
index 3ccc791..7ddba45 100644
--- a/openstack/identity/v2/tenants/fixtures.go
+++ b/openstack/identity/v2/tenants/testing/fixtures.go
@@ -1,12 +1,11 @@
-// +build fixtures
-
-package tenants
+package testing
import (
"fmt"
"net/http"
"testing"
+ "github.com/gophercloud/gophercloud/openstack/identity/v2/tenants"
th "github.com/gophercloud/gophercloud/testhelper"
"github.com/gophercloud/gophercloud/testhelper/client"
)
@@ -32,7 +31,7 @@
`
// RedTeam is a Tenant fixture.
-var RedTeam = Tenant{
+var RedTeam = tenants.Tenant{
ID: "1234",
Name: "Red Team",
Description: "The team that is red",
@@ -40,7 +39,7 @@
}
// BlueTeam is a Tenant fixture.
-var BlueTeam = Tenant{
+var BlueTeam = tenants.Tenant{
ID: "9876",
Name: "Blue Team",
Description: "The team that is blue",
@@ -48,7 +47,7 @@
}
// ExpectedTenantSlice is the slice of tenants expected to be returned from ListOutput.
-var ExpectedTenantSlice = []Tenant{RedTeam, BlueTeam}
+var ExpectedTenantSlice = []tenants.Tenant{RedTeam, BlueTeam}
// HandleListTenantsSuccessfully creates an HTTP handler at `/tenants` on the test handler mux that
// responds with a list of two tenants.
diff --git a/openstack/identity/v2/tenants/requests_test.go b/openstack/identity/v2/tenants/testing/requests_test.go
similarity index 67%
rename from openstack/identity/v2/tenants/requests_test.go
rename to openstack/identity/v2/tenants/testing/requests_test.go
index d7a4db0..2a9b71c 100644
--- a/openstack/identity/v2/tenants/requests_test.go
+++ b/openstack/identity/v2/tenants/testing/requests_test.go
@@ -1,8 +1,9 @@
-package tenants
+package testing
import (
"testing"
+ "github.com/gophercloud/gophercloud/openstack/identity/v2/tenants"
"github.com/gophercloud/gophercloud/pagination"
th "github.com/gophercloud/gophercloud/testhelper"
"github.com/gophercloud/gophercloud/testhelper/client"
@@ -14,10 +15,10 @@
HandleListTenantsSuccessfully(t)
count := 0
- err := List(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) {
+ err := tenants.List(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) {
count++
- actual, err := ExtractTenants(page)
+ actual, err := tenants.ExtractTenants(page)
th.AssertNoErr(t, err)
th.CheckDeepEquals(t, ExpectedTenantSlice, actual)
diff --git a/openstack/identity/v2/tokens/testing/doc.go b/openstack/identity/v2/tokens/testing/doc.go
new file mode 100644
index 0000000..7603f83
--- /dev/null
+++ b/openstack/identity/v2/tokens/testing/doc.go
@@ -0,0 +1 @@
+package testing
diff --git a/openstack/identity/v2/tokens/fixtures.go b/openstack/identity/v2/tokens/testing/fixtures.go
similarity index 86%
rename from openstack/identity/v2/tokens/fixtures.go
rename to openstack/identity/v2/tokens/testing/fixtures.go
index 85a9571..d3a8f24 100644
--- a/openstack/identity/v2/tokens/fixtures.go
+++ b/openstack/identity/v2/tokens/testing/fixtures.go
@@ -1,6 +1,4 @@
-// +build fixtures
-
-package tokens
+package testing
import (
"fmt"
@@ -9,12 +7,13 @@
"time"
"github.com/gophercloud/gophercloud/openstack/identity/v2/tenants"
+ "github.com/gophercloud/gophercloud/openstack/identity/v2/tokens"
th "github.com/gophercloud/gophercloud/testhelper"
thclient "github.com/gophercloud/gophercloud/testhelper/client"
)
// ExpectedToken is the token that should be parsed from TokenCreationResponse.
-var ExpectedToken = &Token{
+var ExpectedToken = &tokens.Token{
ID: "aaaabbbbccccdddd",
ExpiresAt: time.Date(2014, time.January, 31, 15, 30, 58, 0, time.UTC),
Tenant: tenants.Tenant{
@@ -26,27 +25,27 @@
}
// ExpectedServiceCatalog is the service catalog that should be parsed from TokenCreationResponse.
-var ExpectedServiceCatalog = &ServiceCatalog{
- Entries: []CatalogEntry{
- CatalogEntry{
+var ExpectedServiceCatalog = &tokens.ServiceCatalog{
+ Entries: []tokens.CatalogEntry{
+ {
Name: "inscrutablewalrus",
Type: "something",
- Endpoints: []Endpoint{
- Endpoint{
+ Endpoints: []tokens.Endpoint{
+ {
PublicURL: "http://something0:1234/v2/",
Region: "region0",
},
- Endpoint{
+ {
PublicURL: "http://something1:1234/v2/",
Region: "region1",
},
},
},
- CatalogEntry{
+ {
Name: "arbitrarypenguin",
Type: "else",
- Endpoints: []Endpoint{
- Endpoint{
+ Endpoints: []tokens.Endpoint{
+ {
PublicURL: "http://else0:4321/v3/",
Region: "region0",
},
@@ -56,10 +55,10 @@
}
// ExpectedUser is the token that should be parsed from TokenGetResponse.
-var ExpectedUser = &User{
+var ExpectedUser = &tokens.User{
ID: "a530fefc3d594c4ba2693a4ecd6be74e",
Name: "apiserver",
- Roles: []Role{{"member"}, {"service"}},
+ Roles: []tokens.Role{{"member"}, {"service"}},
UserName: "apiserver",
}
@@ -123,19 +122,19 @@
"name": "test"
}
},
- "serviceCatalog": [],
+ "serviceCatalog": [],
"user": {
- "id": "a530fefc3d594c4ba2693a4ecd6be74e",
- "name": "apiserver",
+ "id": "a530fefc3d594c4ba2693a4ecd6be74e",
+ "name": "apiserver",
"roles": [
{
"name": "member"
- },
+ },
{
"name": "service"
}
- ],
- "roles_links": [],
+ ],
+ "roles_links": [],
"username": "apiserver"
}
}
@@ -172,7 +171,7 @@
// IsSuccessful ensures that a CreateResult was successful and contains the correct token and
// service catalog.
-func IsSuccessful(t *testing.T, result CreateResult) {
+func IsSuccessful(t *testing.T, result tokens.CreateResult) {
token, err := result.ExtractToken()
th.AssertNoErr(t, err)
th.CheckDeepEquals(t, ExpectedToken, token)
@@ -184,7 +183,7 @@
// GetIsSuccessful ensures that a GetResult was successful and contains the correct token and
// User Info.
-func GetIsSuccessful(t *testing.T, result GetResult) {
+func GetIsSuccessful(t *testing.T, result tokens.GetResult) {
token, err := result.ExtractToken()
th.AssertNoErr(t, err)
th.CheckDeepEquals(t, ExpectedToken, token)
diff --git a/openstack/identity/v2/tokens/requests_test.go b/openstack/identity/v2/tokens/testing/requests_test.go
similarity index 84%
rename from openstack/identity/v2/tokens/requests_test.go
rename to openstack/identity/v2/tokens/testing/requests_test.go
index a6d16f3..b687a92 100644
--- a/openstack/identity/v2/tokens/requests_test.go
+++ b/openstack/identity/v2/tokens/testing/requests_test.go
@@ -1,19 +1,20 @@
-package tokens
+package testing
import (
"testing"
"github.com/gophercloud/gophercloud"
+ "github.com/gophercloud/gophercloud/openstack/identity/v2/tokens"
th "github.com/gophercloud/gophercloud/testhelper"
"github.com/gophercloud/gophercloud/testhelper/client"
)
-func tokenPost(t *testing.T, options gophercloud.AuthOptions, requestJSON string) CreateResult {
+func tokenPost(t *testing.T, options gophercloud.AuthOptions, requestJSON string) tokens.CreateResult {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleTokenPost(t, requestJSON)
- return Create(client.ServiceClient(), options)
+ return tokens.Create(client.ServiceClient(), options)
}
func tokenPostErr(t *testing.T, options gophercloud.AuthOptions, expectedErr error) {
@@ -21,7 +22,7 @@
defer th.TeardownHTTP()
HandleTokenPost(t, "")
- actualErr := Create(client.ServiceClient(), options).Err
+ actualErr := tokens.Create(client.ServiceClient(), options).Err
th.CheckDeepEquals(t, expectedErr, actualErr)
}
@@ -91,11 +92,11 @@
tokenPostErr(t, options, gophercloud.ErrMissingInput{Argument: "Username"})
}
-func tokenGet(t *testing.T, tokenId string) GetResult {
+func tokenGet(t *testing.T, tokenId string) tokens.GetResult {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleTokenGet(t, tokenId)
- return Get(client.ServiceClient(), tokenId)
+ return tokens.Get(client.ServiceClient(), tokenId)
}
func TestGetWithToken(t *testing.T) {
diff --git a/openstack/identity/v2/users/testing/doc.go b/openstack/identity/v2/users/testing/doc.go
new file mode 100644
index 0000000..7603f83
--- /dev/null
+++ b/openstack/identity/v2/users/testing/doc.go
@@ -0,0 +1 @@
+package testing
diff --git a/openstack/identity/v2/users/fixtures.go b/openstack/identity/v2/users/testing/fixtures.go
similarity index 98%
rename from openstack/identity/v2/users/fixtures.go
rename to openstack/identity/v2/users/testing/fixtures.go
index 7b0bc4c..c1c3b89 100644
--- a/openstack/identity/v2/users/fixtures.go
+++ b/openstack/identity/v2/users/testing/fixtures.go
@@ -1,6 +1,4 @@
-// +build fixtures
-
-package users
+package testing
import (
"fmt"
diff --git a/openstack/identity/v2/users/requests_test.go b/openstack/identity/v2/users/testing/requests_test.go
similarity index 71%
rename from openstack/identity/v2/users/requests_test.go
rename to openstack/identity/v2/users/testing/requests_test.go
index 0e6da37..3cb047e 100644
--- a/openstack/identity/v2/users/requests_test.go
+++ b/openstack/identity/v2/users/testing/requests_test.go
@@ -1,9 +1,10 @@
-package users
+package testing
import (
"testing"
"github.com/gophercloud/gophercloud"
+ "github.com/gophercloud/gophercloud/openstack/identity/v2/users"
"github.com/gophercloud/gophercloud/pagination"
th "github.com/gophercloud/gophercloud/testhelper"
"github.com/gophercloud/gophercloud/testhelper/client"
@@ -17,13 +18,13 @@
count := 0
- err := List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
+ err := users.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
count++
- actual, err := ExtractUsers(page)
+ actual, err := users.ExtractUsers(page)
th.AssertNoErr(t, err)
- expected := []User{
- User{
+ expected := []users.User{
+ {
ID: "u1000",
Name: "John Smith",
Username: "jqsmith",
@@ -31,7 +32,7 @@
Enabled: true,
TenantID: "12345",
},
- User{
+ {
ID: "u1001",
Name: "Jane Smith",
Username: "jqsmith",
@@ -53,18 +54,18 @@
mockCreateUserResponse(t)
- opts := CreateOpts{
+ opts := users.CreateOpts{
Name: "new_user",
TenantID: "12345",
Enabled: gophercloud.Disabled,
Email: "new_user@foo.com",
}
- user, err := Create(client.ServiceClient(), opts).Extract()
+ user, err := users.Create(client.ServiceClient(), opts).Extract()
th.AssertNoErr(t, err)
- expected := &User{
+ expected := &users.User{
Name: "new_user",
ID: "c39e3de9be2d4c779f1dfd6abacc176d",
Email: "new_user@foo.com",
@@ -81,10 +82,10 @@
mockGetUserResponse(t)
- user, err := Get(client.ServiceClient(), "new_user").Extract()
+ user, err := users.Get(client.ServiceClient(), "new_user").Extract()
th.AssertNoErr(t, err)
- expected := &User{
+ expected := &users.User{
Name: "new_user",
ID: "c39e3de9be2d4c779f1dfd6abacc176d",
Email: "new_user@foo.com",
@@ -102,17 +103,17 @@
mockUpdateUserResponse(t)
id := "c39e3de9be2d4c779f1dfd6abacc176d"
- opts := UpdateOpts{
+ opts := users.UpdateOpts{
Name: "new_name",
Enabled: gophercloud.Enabled,
Email: "new_email@foo.com",
}
- user, err := Update(client.ServiceClient(), id, opts).Extract()
+ user, err := users.Update(client.ServiceClient(), id, opts).Extract()
th.AssertNoErr(t, err)
- expected := &User{
+ expected := &users.User{
Name: "new_name",
ID: id,
Email: "new_email@foo.com",
@@ -129,7 +130,7 @@
mockDeleteUserResponse(t)
- res := Delete(client.ServiceClient(), "c39e3de9be2d4c779f1dfd6abacc176d")
+ res := users.Delete(client.ServiceClient(), "c39e3de9be2d4c779f1dfd6abacc176d")
th.AssertNoErr(t, res.Err)
}
@@ -142,13 +143,13 @@
tenantID := "1d8b6120dcc640fda4fc9194ffc80273"
userID := "c39e3de9be2d4c779f1dfd6abacc176d"
- err := ListRoles(client.ServiceClient(), tenantID, userID).EachPage(func(page pagination.Page) (bool, error) {
- actual, err := ExtractRoles(page)
+ err := users.ListRoles(client.ServiceClient(), tenantID, userID).EachPage(func(page pagination.Page) (bool, error) {
+ actual, err := users.ExtractRoles(page)
th.AssertNoErr(t, err)
- expected := []Role{
- Role{ID: "9fe2ff9ee4384b1894a90878d3e92bab", Name: "foo_role"},
- Role{ID: "1ea3d56793574b668e85960fbf651e13", Name: "admin"},
+ expected := []users.Role{
+ {ID: "9fe2ff9ee4384b1894a90878d3e92bab", Name: "foo_role"},
+ {ID: "1ea3d56793574b668e85960fbf651e13", Name: "admin"},
}
th.CheckDeepEquals(t, expected, actual)
diff --git a/openstack/identity/v3/endpoints/testing/doc.go b/openstack/identity/v3/endpoints/testing/doc.go
new file mode 100644
index 0000000..7603f83
--- /dev/null
+++ b/openstack/identity/v3/endpoints/testing/doc.go
@@ -0,0 +1 @@
+package testing
diff --git a/openstack/identity/v3/endpoints/requests_test.go b/openstack/identity/v3/endpoints/testing/requests_test.go
similarity index 88%
rename from openstack/identity/v3/endpoints/requests_test.go
rename to openstack/identity/v3/endpoints/testing/requests_test.go
index 14bbe6a..53d8488 100644
--- a/openstack/identity/v3/endpoints/requests_test.go
+++ b/openstack/identity/v3/endpoints/testing/requests_test.go
@@ -1,4 +1,4 @@
-package endpoints
+package testing
import (
"fmt"
@@ -6,6 +6,7 @@
"testing"
"github.com/gophercloud/gophercloud"
+ "github.com/gophercloud/gophercloud/openstack/identity/v3/endpoints"
"github.com/gophercloud/gophercloud/pagination"
th "github.com/gophercloud/gophercloud/testhelper"
"github.com/gophercloud/gophercloud/testhelper/client"
@@ -48,7 +49,7 @@
`)
})
- actual, err := Create(client.ServiceClient(), CreateOpts{
+ actual, err := endpoints.Create(client.ServiceClient(), endpoints.CreateOpts{
Availability: gophercloud.AvailabilityPublic,
Name: "the-endiest-of-points",
Region: "underground",
@@ -57,7 +58,7 @@
}).Extract()
th.AssertNoErr(t, err)
- expected := &Endpoint{
+ expected := &endpoints.Endpoint{
ID: "12",
Availability: gophercloud.AvailabilityPublic,
Name: "the-endiest-of-points",
@@ -113,16 +114,16 @@
})
count := 0
- List(client.ServiceClient(), ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
+ endpoints.List(client.ServiceClient(), endpoints.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
count++
- actual, err := ExtractEndpoints(page)
+ actual, err := endpoints.ExtractEndpoints(page)
if err != nil {
t.Errorf("Failed to extract endpoints: %v", err)
return false, err
}
- expected := []Endpoint{
- Endpoint{
+ expected := []endpoints.Endpoint{
+ {
ID: "12",
Availability: gophercloud.AvailabilityPublic,
Name: "the-endiest-of-points",
@@ -130,7 +131,7 @@
ServiceID: "asdfasdfasdfasdf",
URL: "https://1.2.3.4:9000/",
},
- Endpoint{
+ {
ID: "13",
Availability: gophercloud.AvailabilityInternal,
Name: "shhhh",
@@ -178,7 +179,7 @@
`)
})
- actual, err := Update(client.ServiceClient(), "12", UpdateOpts{
+ actual, err := endpoints.Update(client.ServiceClient(), "12", endpoints.UpdateOpts{
Name: "renamed",
Region: "somewhere-else",
}).Extract()
@@ -186,7 +187,7 @@
t.Fatalf("Unexpected error from Update: %v", err)
}
- expected := &Endpoint{
+ expected := &endpoints.Endpoint{
ID: "12",
Availability: gophercloud.AvailabilityPublic,
Name: "renamed",
@@ -208,6 +209,6 @@
w.WriteHeader(http.StatusNoContent)
})
- res := Delete(client.ServiceClient(), "34")
+ res := endpoints.Delete(client.ServiceClient(), "34")
th.AssertNoErr(t, res.Err)
}
diff --git a/openstack/identity/v3/roles/testing/doc.go b/openstack/identity/v3/roles/testing/doc.go
new file mode 100644
index 0000000..7603f83
--- /dev/null
+++ b/openstack/identity/v3/roles/testing/doc.go
@@ -0,0 +1 @@
+package testing
diff --git a/openstack/identity/v3/roles/requests_test.go b/openstack/identity/v3/roles/testing/requests_test.go
similarity index 79%
rename from openstack/identity/v3/roles/requests_test.go
rename to openstack/identity/v3/roles/testing/requests_test.go
index ec6531c..dd9b704 100644
--- a/openstack/identity/v3/roles/requests_test.go
+++ b/openstack/identity/v3/roles/testing/requests_test.go
@@ -1,4 +1,4 @@
-package roles
+package testing
import (
"fmt"
@@ -6,6 +6,7 @@
"reflect"
"testing"
+ "github.com/gophercloud/gophercloud/openstack/identity/v3/roles"
"github.com/gophercloud/gophercloud/pagination"
"github.com/gophercloud/gophercloud/testhelper"
"github.com/gophercloud/gophercloud/testhelper/client"
@@ -67,25 +68,25 @@
})
count := 0
- err := ListAssignments(client.ServiceClient(), ListAssignmentsOpts{}).EachPage(func(page pagination.Page) (bool, error) {
+ err := roles.ListAssignments(client.ServiceClient(), roles.ListAssignmentsOpts{}).EachPage(func(page pagination.Page) (bool, error) {
count++
- actual, err := ExtractRoleAssignments(page)
+ actual, err := roles.ExtractRoleAssignments(page)
if err != nil {
return false, err
}
- expected := []RoleAssignment{
- RoleAssignment{
- Role: Role{ID: "123456"},
- Scope: Scope{Domain: Domain{ID: "161718"}},
- User: User{ID: "313233"},
- Group: Group{},
+ expected := []roles.RoleAssignment{
+ {
+ Role: roles.Role{ID: "123456"},
+ Scope: roles.Scope{Domain: roles.Domain{ID: "161718"}},
+ User: roles.User{ID: "313233"},
+ Group: roles.Group{},
},
- RoleAssignment{
- Role: Role{ID: "123456"},
- Scope: Scope{Project: Project{ID: "456789"}},
- User: User{ID: "313233"},
- Group: Group{},
+ {
+ Role: roles.Role{ID: "123456"},
+ Scope: roles.Scope{Project: roles.Project{ID: "456789"}},
+ User: roles.User{ID: "313233"},
+ Group: roles.Group{},
},
}
diff --git a/openstack/identity/v3/services/testing/doc.go b/openstack/identity/v3/services/testing/doc.go
new file mode 100644
index 0000000..7603f83
--- /dev/null
+++ b/openstack/identity/v3/services/testing/doc.go
@@ -0,0 +1 @@
+package testing
diff --git a/openstack/identity/v3/services/requests_test.go b/openstack/identity/v3/services/testing/requests_test.go
similarity index 84%
rename from openstack/identity/v3/services/requests_test.go
rename to openstack/identity/v3/services/testing/requests_test.go
index aa19bcc..0a065a2 100644
--- a/openstack/identity/v3/services/requests_test.go
+++ b/openstack/identity/v3/services/testing/requests_test.go
@@ -1,10 +1,11 @@
-package services
+package testing
import (
"fmt"
"net/http"
"testing"
+ "github.com/gophercloud/gophercloud/openstack/identity/v3/services"
"github.com/gophercloud/gophercloud/pagination"
th "github.com/gophercloud/gophercloud/testhelper"
"github.com/gophercloud/gophercloud/testhelper/client"
@@ -31,14 +32,14 @@
}`)
})
- expected := &Service{
+ expected := &services.Service{
Description: "Here's your service",
ID: "1234",
Name: "InscrutableOpenStackProjectName",
Type: "compute",
}
- actual, err := Create(client.ServiceClient(), "compute").Extract()
+ actual, err := services.Create(client.ServiceClient(), "compute").Extract()
if err != nil {
t.Fatalf("Unexpected error from Create: %v", err)
}
@@ -79,21 +80,21 @@
})
count := 0
- err := List(client.ServiceClient(), ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
+ err := services.List(client.ServiceClient(), services.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
count++
- actual, err := ExtractServices(page)
+ actual, err := services.ExtractServices(page)
if err != nil {
return false, err
}
- expected := []Service{
- Service{
+ expected := []services.Service{
+ {
Description: "Service One",
ID: "1234",
Name: "service-one",
Type: "identity",
},
- Service{
+ {
Description: "Service Two",
ID: "9876",
Name: "service-two",
@@ -128,10 +129,10 @@
`)
})
- actual, err := Get(client.ServiceClient(), "12345").Extract()
+ actual, err := services.Get(client.ServiceClient(), "12345").Extract()
th.AssertNoErr(t, err)
- expected := &Service{
+ expected := &services.Service{
ID: "12345",
Description: "Service One",
Name: "service-one",
@@ -161,12 +162,12 @@
`)
})
- expected := &Service{
+ expected := &services.Service{
ID: "12345",
Type: "lasermagic",
}
- actual, err := Update(client.ServiceClient(), "12345", "lasermagic").Extract()
+ actual, err := services.Update(client.ServiceClient(), "12345", "lasermagic").Extract()
th.AssertNoErr(t, err)
th.AssertDeepEquals(t, expected, actual)
}
@@ -181,6 +182,6 @@
w.WriteHeader(http.StatusNoContent)
})
- res := Delete(client.ServiceClient(), "12345")
+ res := services.Delete(client.ServiceClient(), "12345")
th.AssertNoErr(t, res.Err)
}
diff --git a/openstack/identity/v3/tokens/testing/doc.go b/openstack/identity/v3/tokens/testing/doc.go
new file mode 100644
index 0000000..7603f83
--- /dev/null
+++ b/openstack/identity/v3/tokens/testing/doc.go
@@ -0,0 +1 @@
+package testing
diff --git a/openstack/identity/v3/tokens/requests_test.go b/openstack/identity/v3/tokens/testing/requests_test.go
similarity index 66%
rename from openstack/identity/v3/tokens/requests_test.go
rename to openstack/identity/v3/tokens/testing/requests_test.go
index faa79e0..cbb675f 100644
--- a/openstack/identity/v3/tokens/requests_test.go
+++ b/openstack/identity/v3/tokens/testing/requests_test.go
@@ -1,4 +1,4 @@
-package tokens
+package testing
import (
"fmt"
@@ -7,11 +7,12 @@
"time"
"github.com/gophercloud/gophercloud"
+ "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens"
"github.com/gophercloud/gophercloud/testhelper"
)
// authTokenPost verifies that providing certain AuthOptions and Scope results in an expected JSON structure.
-func authTokenPost(t *testing.T, options AuthOptions, scope *Scope, requestJSON string) {
+func authTokenPost(t *testing.T, options tokens.AuthOptions, scope *tokens.Scope, requestJSON string) {
testhelper.SetupHTTP()
defer testhelper.TeardownHTTP()
@@ -34,13 +35,13 @@
}`)
})
- _, err := Create(&client, options, scope).Extract()
+ _, err := tokens.Create(&client, options, scope).Extract()
if err != nil {
t.Errorf("Create returned an error: %v", err)
}
}
-func authTokenPostErr(t *testing.T, options AuthOptions, scope *Scope, includeToken bool, expectedErr error) {
+func authTokenPostErr(t *testing.T, options tokens.AuthOptions, scope *tokens.Scope, includeToken bool, expectedErr error) {
testhelper.SetupHTTP()
defer testhelper.TeardownHTTP()
@@ -52,7 +53,7 @@
client.TokenID = "abcdef123456"
}
- _, err := Create(&client, options, scope).Extract()
+ _, err := tokens.Create(&client, options, scope).Extract()
if err == nil {
t.Errorf("Create did NOT return an error")
}
@@ -62,7 +63,7 @@
}
func TestCreateUserIDAndPassword(t *testing.T) {
- authTokenPost(t, AuthOptions{UserID: "me", Password: "squirrel!"}, nil, `
+ authTokenPost(t, tokens.AuthOptions{UserID: "me", Password: "squirrel!"}, nil, `
{
"auth": {
"identity": {
@@ -77,7 +78,7 @@
}
func TestCreateUsernameDomainIDPassword(t *testing.T) {
- authTokenPost(t, AuthOptions{Username: "fakey", Password: "notpassword", DomainID: "abc123"}, nil, `
+ authTokenPost(t, tokens.AuthOptions{Username: "fakey", Password: "notpassword", DomainID: "abc123"}, nil, `
{
"auth": {
"identity": {
@@ -98,7 +99,7 @@
}
func TestCreateUsernameDomainNamePassword(t *testing.T) {
- authTokenPost(t, AuthOptions{Username: "frank", Password: "swordfish", DomainName: "spork.net"}, nil, `
+ authTokenPost(t, tokens.AuthOptions{Username: "frank", Password: "swordfish", DomainName: "spork.net"}, nil, `
{
"auth": {
"identity": {
@@ -119,7 +120,7 @@
}
func TestCreateTokenID(t *testing.T) {
- authTokenPost(t, AuthOptions{TokenID: "12345abcdef"}, nil, `
+ authTokenPost(t, tokens.AuthOptions{TokenID: "12345abcdef"}, nil, `
{
"auth": {
"identity": {
@@ -134,8 +135,8 @@
}
func TestCreateProjectIDScope(t *testing.T) {
- options := AuthOptions{UserID: "fenris", Password: "g0t0h311"}
- scope := &Scope{ProjectID: "123456"}
+ options := tokens.AuthOptions{UserID: "fenris", Password: "g0t0h311"}
+ scope := &tokens.Scope{ProjectID: "123456"}
authTokenPost(t, options, scope, `
{
"auth": {
@@ -159,8 +160,8 @@
}
func TestCreateDomainIDScope(t *testing.T) {
- options := AuthOptions{UserID: "fenris", Password: "g0t0h311"}
- scope := &Scope{DomainID: "1000"}
+ options := tokens.AuthOptions{UserID: "fenris", Password: "g0t0h311"}
+ scope := &tokens.Scope{DomainID: "1000"}
authTokenPost(t, options, scope, `
{
"auth": {
@@ -184,8 +185,8 @@
}
func TestCreateProjectNameAndDomainIDScope(t *testing.T) {
- options := AuthOptions{UserID: "fenris", Password: "g0t0h311"}
- scope := &Scope{ProjectName: "world-domination", DomainID: "1000"}
+ options := tokens.AuthOptions{UserID: "fenris", Password: "g0t0h311"}
+ scope := &tokens.Scope{ProjectName: "world-domination", DomainID: "1000"}
authTokenPost(t, options, scope, `
{
"auth": {
@@ -212,8 +213,8 @@
}
func TestCreateProjectNameAndDomainNameScope(t *testing.T) {
- options := AuthOptions{UserID: "fenris", Password: "g0t0h311"}
- scope := &Scope{ProjectName: "world-domination", DomainName: "evil-plans"}
+ options := tokens.AuthOptions{UserID: "fenris", Password: "g0t0h311"}
+ scope := &tokens.Scope{ProjectName: "world-domination", DomainName: "evil-plans"}
authTokenPost(t, options, scope, `
{
"auth": {
@@ -259,8 +260,8 @@
}`)
})
- options := AuthOptions{UserID: "me", Password: "shhh"}
- token, err := Create(&client, options, nil).Extract()
+ options := tokens.AuthOptions{UserID: "me", Password: "shhh"}
+ token, err := tokens.Create(&client, options, nil).Extract()
if err != nil {
t.Fatalf("Create returned an error: %v", err)
}
@@ -271,123 +272,123 @@
}
func TestCreateFailureEmptyAuth(t *testing.T) {
- authTokenPostErr(t, AuthOptions{}, nil, false, ErrMissingPassword{})
+ authTokenPostErr(t, tokens.AuthOptions{}, nil, false, tokens.ErrMissingPassword{})
}
func TestCreateFailureTenantID(t *testing.T) {
- authTokenPostErr(t, AuthOptions{TenantID: "something"}, nil, false, ErrTenantIDProvided{})
+ authTokenPostErr(t, tokens.AuthOptions{TenantID: "something"}, nil, false, tokens.ErrTenantIDProvided{})
}
func TestCreateFailureTenantName(t *testing.T) {
- authTokenPostErr(t, AuthOptions{TenantName: "something"}, nil, false, ErrTenantNameProvided{})
+ authTokenPostErr(t, tokens.AuthOptions{TenantName: "something"}, nil, false, tokens.ErrTenantNameProvided{})
}
func TestCreateFailureTokenIDUsername(t *testing.T) {
- authTokenPostErr(t, AuthOptions{Username: "something", TokenID: "12345"}, nil, true, ErrUsernameWithToken{})
+ authTokenPostErr(t, tokens.AuthOptions{Username: "something", TokenID: "12345"}, nil, true, tokens.ErrUsernameWithToken{})
}
func TestCreateFailureTokenIDUserID(t *testing.T) {
- authTokenPostErr(t, AuthOptions{UserID: "something", TokenID: "12345"}, nil, true, ErrUserIDWithToken{})
+ authTokenPostErr(t, tokens.AuthOptions{UserID: "something", TokenID: "12345"}, nil, true, tokens.ErrUserIDWithToken{})
}
func TestCreateFailureTokenIDDomainID(t *testing.T) {
- authTokenPostErr(t, AuthOptions{DomainID: "something", TokenID: "12345"}, nil, true, ErrDomainIDWithToken{})
+ authTokenPostErr(t, tokens.AuthOptions{DomainID: "something", TokenID: "12345"}, nil, true, tokens.ErrDomainIDWithToken{})
}
func TestCreateFailureTokenIDDomainName(t *testing.T) {
- authTokenPostErr(t, AuthOptions{DomainName: "something", TokenID: "12345"}, nil, true, ErrDomainNameWithToken{})
+ authTokenPostErr(t, tokens.AuthOptions{DomainName: "something", TokenID: "12345"}, nil, true, tokens.ErrDomainNameWithToken{})
}
func TestCreateFailureMissingUser(t *testing.T) {
- options := AuthOptions{Password: "supersecure"}
- authTokenPostErr(t, options, nil, false, ErrUsernameOrUserID{})
+ options := tokens.AuthOptions{Password: "supersecure"}
+ authTokenPostErr(t, options, nil, false, tokens.ErrUsernameOrUserID{})
}
func TestCreateFailureBothUser(t *testing.T) {
- options := AuthOptions{
+ options := tokens.AuthOptions{
Password: "supersecure",
Username: "oops",
UserID: "redundancy",
}
- authTokenPostErr(t, options, nil, false, ErrUsernameOrUserID{})
+ authTokenPostErr(t, options, nil, false, tokens.ErrUsernameOrUserID{})
}
func TestCreateFailureMissingDomain(t *testing.T) {
- options := AuthOptions{
+ options := tokens.AuthOptions{
Password: "supersecure",
Username: "notuniqueenough",
}
- authTokenPostErr(t, options, nil, false, ErrDomainIDOrDomainName{})
+ authTokenPostErr(t, options, nil, false, tokens.ErrDomainIDOrDomainName{})
}
func TestCreateFailureBothDomain(t *testing.T) {
- options := AuthOptions{
+ options := tokens.AuthOptions{
Password: "supersecure",
Username: "someone",
DomainID: "hurf",
DomainName: "durf",
}
- authTokenPostErr(t, options, nil, false, ErrDomainIDOrDomainName{})
+ authTokenPostErr(t, options, nil, false, tokens.ErrDomainIDOrDomainName{})
}
func TestCreateFailureUserIDDomainID(t *testing.T) {
- options := AuthOptions{
+ options := tokens.AuthOptions{
UserID: "100",
Password: "stuff",
DomainID: "oops",
}
- authTokenPostErr(t, options, nil, false, ErrDomainIDWithUserID{})
+ authTokenPostErr(t, options, nil, false, tokens.ErrDomainIDWithUserID{})
}
func TestCreateFailureUserIDDomainName(t *testing.T) {
- options := AuthOptions{
+ options := tokens.AuthOptions{
UserID: "100",
Password: "sssh",
DomainName: "oops",
}
- authTokenPostErr(t, options, nil, false, ErrDomainNameWithUserID{})
+ authTokenPostErr(t, options, nil, false, tokens.ErrDomainNameWithUserID{})
}
func TestCreateFailureScopeProjectNameAlone(t *testing.T) {
- options := AuthOptions{UserID: "myself", Password: "swordfish"}
- scope := &Scope{ProjectName: "notenough"}
- authTokenPostErr(t, options, scope, false, ErrScopeDomainIDOrDomainName{})
+ options := tokens.AuthOptions{UserID: "myself", Password: "swordfish"}
+ scope := &tokens.Scope{ProjectName: "notenough"}
+ authTokenPostErr(t, options, scope, false, tokens.ErrScopeDomainIDOrDomainName{})
}
func TestCreateFailureScopeProjectNameAndID(t *testing.T) {
- options := AuthOptions{UserID: "myself", Password: "swordfish"}
- scope := &Scope{ProjectName: "whoops", ProjectID: "toomuch", DomainID: "1234"}
- authTokenPostErr(t, options, scope, false, ErrScopeProjectIDOrProjectName{})
+ options := tokens.AuthOptions{UserID: "myself", Password: "swordfish"}
+ scope := &tokens.Scope{ProjectName: "whoops", ProjectID: "toomuch", DomainID: "1234"}
+ authTokenPostErr(t, options, scope, false, tokens.ErrScopeProjectIDOrProjectName{})
}
func TestCreateFailureScopeProjectIDAndDomainID(t *testing.T) {
- options := AuthOptions{UserID: "myself", Password: "swordfish"}
- scope := &Scope{ProjectID: "toomuch", DomainID: "notneeded"}
- authTokenPostErr(t, options, scope, false, ErrScopeProjectIDAlone{})
+ options := tokens.AuthOptions{UserID: "myself", Password: "swordfish"}
+ scope := &tokens.Scope{ProjectID: "toomuch", DomainID: "notneeded"}
+ authTokenPostErr(t, options, scope, false, tokens.ErrScopeProjectIDAlone{})
}
func TestCreateFailureScopeProjectIDAndDomainNAme(t *testing.T) {
- options := AuthOptions{UserID: "myself", Password: "swordfish"}
- scope := &Scope{ProjectID: "toomuch", DomainName: "notneeded"}
- authTokenPostErr(t, options, scope, false, ErrScopeProjectIDAlone{})
+ options := tokens.AuthOptions{UserID: "myself", Password: "swordfish"}
+ scope := &tokens.Scope{ProjectID: "toomuch", DomainName: "notneeded"}
+ authTokenPostErr(t, options, scope, false, tokens.ErrScopeProjectIDAlone{})
}
func TestCreateFailureScopeDomainIDAndDomainName(t *testing.T) {
- options := AuthOptions{UserID: "myself", Password: "swordfish"}
- scope := &Scope{DomainID: "toomuch", DomainName: "notneeded"}
- authTokenPostErr(t, options, scope, false, ErrScopeDomainIDOrDomainName{})
+ options := tokens.AuthOptions{UserID: "myself", Password: "swordfish"}
+ scope := &tokens.Scope{DomainID: "toomuch", DomainName: "notneeded"}
+ authTokenPostErr(t, options, scope, false, tokens.ErrScopeDomainIDOrDomainName{})
}
func TestCreateFailureScopeDomainNameAlone(t *testing.T) {
- options := AuthOptions{UserID: "myself", Password: "swordfish"}
- scope := &Scope{DomainName: "notenough"}
- authTokenPostErr(t, options, scope, false, ErrScopeDomainName{})
+ options := tokens.AuthOptions{UserID: "myself", Password: "swordfish"}
+ scope := &tokens.Scope{DomainName: "notenough"}
+ authTokenPostErr(t, options, scope, false, tokens.ErrScopeDomainName{})
}
func TestCreateFailureEmptyScope(t *testing.T) {
- options := AuthOptions{UserID: "myself", Password: "swordfish"}
- scope := &Scope{}
- authTokenPostErr(t, options, scope, false, ErrScopeEmpty{})
+ options := tokens.AuthOptions{UserID: "myself", Password: "swordfish"}
+ scope := &tokens.Scope{}
+ authTokenPostErr(t, options, scope, false, tokens.ErrScopeEmpty{})
}
func TestGetRequest(t *testing.T) {
@@ -414,7 +415,7 @@
`)
})
- token, err := Get(&client, "abcdef12345").Extract()
+ token, err := tokens.Get(&client, "abcdef12345").Extract()
if err != nil {
t.Errorf("Info returned an error: %v", err)
}
@@ -451,7 +452,7 @@
defer testhelper.TeardownHTTP()
client := prepareAuthTokenHandler(t, "HEAD", http.StatusNoContent)
- ok, err := Validate(&client, "abcdef12345")
+ ok, err := tokens.Validate(&client, "abcdef12345")
if err != nil {
t.Errorf("Unexpected error from Validate: %v", err)
}
@@ -466,7 +467,7 @@
defer testhelper.TeardownHTTP()
client := prepareAuthTokenHandler(t, "HEAD", http.StatusNotFound)
- ok, err := Validate(&client, "abcdef12345")
+ ok, err := tokens.Validate(&client, "abcdef12345")
if err != nil {
t.Errorf("Unexpected error from Validate: %v", err)
}
@@ -481,7 +482,7 @@
defer testhelper.TeardownHTTP()
client := prepareAuthTokenHandler(t, "HEAD", http.StatusUnauthorized)
- _, err := Validate(&client, "abcdef12345")
+ _, err := tokens.Validate(&client, "abcdef12345")
if err == nil {
t.Errorf("Missing expected error from Validate")
}
@@ -492,7 +493,7 @@
defer testhelper.TeardownHTTP()
client := prepareAuthTokenHandler(t, "DELETE", http.StatusNoContent)
- res := Revoke(&client, "abcdef12345")
+ res := tokens.Revoke(&client, "abcdef12345")
testhelper.AssertNoErr(t, res.Err)
}
@@ -501,7 +502,7 @@
defer testhelper.TeardownHTTP()
client := prepareAuthTokenHandler(t, "DELETE", http.StatusNotFound)
- res := Revoke(&client, "abcdef12345")
+ res := tokens.Revoke(&client, "abcdef12345")
if res.Err == nil {
t.Errorf("Missing expected error from Revoke")
}