move unit tests into 'testing' directories
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")
}