Clean-up dependencies

Signed-off-by: David Gageot <david@gageot.net>
This commit is contained in:
David Gageot
2015-11-12 19:16:27 +01:00
parent 7a4915e999
commit 89675067eb
612 changed files with 1869 additions and 151003 deletions

View File

@@ -1,64 +0,0 @@
package roles
import (
"testing"
"github.com/rackspace/gophercloud/pagination"
th "github.com/rackspace/gophercloud/testhelper"
"github.com/rackspace/gophercloud/testhelper/client"
)
func TestRole(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
MockListRoleResponse(t)
count := 0
err := List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
count++
actual, err := ExtractRoles(page)
if err != nil {
t.Errorf("Failed to extract users: %v", err)
return false, err
}
expected := []Role{
Role{
ID: "123",
Name: "compute:admin",
Description: "Nova Administrator",
},
}
th.CheckDeepEquals(t, expected, actual)
return true, nil
})
th.AssertNoErr(t, err)
th.AssertEquals(t, 1, count)
}
func TestAddUserRole(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
MockAddUserRoleResponse(t)
err := AddUserRole(client.ServiceClient(), "{tenant_id}", "{user_id}", "{role_id}").ExtractErr()
th.AssertNoErr(t, err)
}
func TestDeleteUserRole(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
MockDeleteUserRoleResponse(t)
err := DeleteUserRole(client.ServiceClient(), "{tenant_id}", "{user_id}", "{role_id}").ExtractErr()
th.AssertNoErr(t, err)
}

View File

@@ -1,38 +0,0 @@
package extensions
import (
"testing"
common "github.com/rackspace/gophercloud/openstack/common/extensions"
"github.com/rackspace/gophercloud/pagination"
th "github.com/rackspace/gophercloud/testhelper"
"github.com/rackspace/gophercloud/testhelper/client"
)
func TestList(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleListExtensionsSuccessfully(t)
count := 0
err := List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
count++
actual, err := ExtractExtensions(page)
th.AssertNoErr(t, err)
th.CheckDeepEquals(t, common.ExpectedExtensions, actual)
return true, nil
})
th.AssertNoErr(t, err)
th.CheckEquals(t, 1, count)
}
func TestGet(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
common.HandleGetExtensionSuccessfully(t)
actual, err := Get(client.ServiceClient(), "agent").Extract()
th.AssertNoErr(t, err)
th.CheckDeepEquals(t, common.SingleExtension, actual)
}

View File

@@ -1,29 +0,0 @@
package tenants
import (
"testing"
"github.com/rackspace/gophercloud/pagination"
th "github.com/rackspace/gophercloud/testhelper"
"github.com/rackspace/gophercloud/testhelper/client"
)
func TestListTenants(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleListTenantsSuccessfully(t)
count := 0
err := List(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) {
count++
actual, err := ExtractTenants(page)
th.AssertNoErr(t, err)
th.CheckDeepEquals(t, ExpectedTenantSlice, actual)
return true, nil
})
th.AssertNoErr(t, err)
th.CheckEquals(t, count, 1)
}

View File

@@ -1,140 +0,0 @@
package tokens
import (
"testing"
"github.com/rackspace/gophercloud"
th "github.com/rackspace/gophercloud/testhelper"
"github.com/rackspace/gophercloud/testhelper/client"
)
func tokenPost(t *testing.T, options gophercloud.AuthOptions, requestJSON string) CreateResult {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleTokenPost(t, requestJSON)
return Create(client.ServiceClient(), AuthOptions{options})
}
func tokenPostErr(t *testing.T, options gophercloud.AuthOptions, expectedErr error) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleTokenPost(t, "")
actualErr := Create(client.ServiceClient(), AuthOptions{options}).Err
th.CheckEquals(t, expectedErr, actualErr)
}
func TestCreateWithPassword(t *testing.T) {
options := gophercloud.AuthOptions{
Username: "me",
Password: "swordfish",
}
IsSuccessful(t, tokenPost(t, options, `
{
"auth": {
"passwordCredentials": {
"username": "me",
"password": "swordfish"
}
}
}
`))
}
func TestCreateTokenWithTenantID(t *testing.T) {
options := gophercloud.AuthOptions{
Username: "me",
Password: "opensesame",
TenantID: "fc394f2ab2df4114bde39905f800dc57",
}
IsSuccessful(t, tokenPost(t, options, `
{
"auth": {
"tenantId": "fc394f2ab2df4114bde39905f800dc57",
"passwordCredentials": {
"username": "me",
"password": "opensesame"
}
}
}
`))
}
func TestCreateTokenWithTenantName(t *testing.T) {
options := gophercloud.AuthOptions{
Username: "me",
Password: "opensesame",
TenantName: "demo",
}
IsSuccessful(t, tokenPost(t, options, `
{
"auth": {
"tenantName": "demo",
"passwordCredentials": {
"username": "me",
"password": "opensesame"
}
}
}
`))
}
func TestProhibitUserID(t *testing.T) {
options := gophercloud.AuthOptions{
Username: "me",
UserID: "1234",
Password: "thing",
}
tokenPostErr(t, options, ErrUserIDProvided)
}
func TestProhibitAPIKey(t *testing.T) {
options := gophercloud.AuthOptions{
Username: "me",
Password: "thing",
APIKey: "123412341234",
}
tokenPostErr(t, options, ErrAPIKeyProvided)
}
func TestProhibitDomainID(t *testing.T) {
options := gophercloud.AuthOptions{
Username: "me",
Password: "thing",
DomainID: "1234",
}
tokenPostErr(t, options, ErrDomainIDProvided)
}
func TestProhibitDomainName(t *testing.T) {
options := gophercloud.AuthOptions{
Username: "me",
Password: "thing",
DomainName: "wat",
}
tokenPostErr(t, options, ErrDomainNameProvided)
}
func TestRequireUsername(t *testing.T) {
options := gophercloud.AuthOptions{
Password: "thing",
}
tokenPostErr(t, options, ErrUsernameRequired)
}
func TestRequirePassword(t *testing.T) {
options := gophercloud.AuthOptions{
Username: "me",
}
tokenPostErr(t, options, ErrPasswordRequired)
}

View File

@@ -1,165 +0,0 @@
package users
import (
"testing"
"github.com/rackspace/gophercloud/pagination"
th "github.com/rackspace/gophercloud/testhelper"
"github.com/rackspace/gophercloud/testhelper/client"
)
func TestList(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
MockListUserResponse(t)
count := 0
err := List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
count++
actual, err := ExtractUsers(page)
if err != nil {
t.Errorf("Failed to extract users: %v", err)
return false, err
}
expected := []User{
User{
ID: "u1000",
Name: "John Smith",
Username: "jqsmith",
Email: "john.smith@example.org",
Enabled: true,
TenantID: "12345",
},
User{
ID: "u1001",
Name: "Jane Smith",
Username: "jqsmith",
Email: "jane.smith@example.org",
Enabled: true,
TenantID: "12345",
},
}
th.CheckDeepEquals(t, expected, actual)
return true, nil
})
th.AssertNoErr(t, err)
th.AssertEquals(t, 1, count)
}
func TestCreateUser(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
mockCreateUserResponse(t)
opts := CreateOpts{
Name: "new_user",
TenantID: "12345",
Enabled: Disabled,
Email: "new_user@foo.com",
}
user, err := Create(client.ServiceClient(), opts).Extract()
th.AssertNoErr(t, err)
expected := &User{
Name: "new_user",
ID: "c39e3de9be2d4c779f1dfd6abacc176d",
Email: "new_user@foo.com",
Enabled: false,
TenantID: "12345",
}
th.AssertDeepEquals(t, expected, user)
}
func TestGetUser(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
mockGetUserResponse(t)
user, err := Get(client.ServiceClient(), "new_user").Extract()
th.AssertNoErr(t, err)
expected := &User{
Name: "new_user",
ID: "c39e3de9be2d4c779f1dfd6abacc176d",
Email: "new_user@foo.com",
Enabled: false,
TenantID: "12345",
}
th.AssertDeepEquals(t, expected, user)
}
func TestUpdateUser(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
mockUpdateUserResponse(t)
id := "c39e3de9be2d4c779f1dfd6abacc176d"
opts := UpdateOpts{
Name: "new_name",
Enabled: Enabled,
Email: "new_email@foo.com",
}
user, err := Update(client.ServiceClient(), id, opts).Extract()
th.AssertNoErr(t, err)
expected := &User{
Name: "new_name",
ID: id,
Email: "new_email@foo.com",
Enabled: true,
TenantID: "12345",
}
th.AssertDeepEquals(t, expected, user)
}
func TestDeleteUser(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
mockDeleteUserResponse(t)
res := Delete(client.ServiceClient(), "c39e3de9be2d4c779f1dfd6abacc176d")
th.AssertNoErr(t, res.Err)
}
func TestListingUserRoles(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
mockListRolesResponse(t)
tenantID := "1d8b6120dcc640fda4fc9194ffc80273"
userID := "c39e3de9be2d4c779f1dfd6abacc176d"
err := ListRoles(client.ServiceClient(), tenantID, userID).EachPage(func(page pagination.Page) (bool, error) {
actual, err := ExtractRoles(page)
th.AssertNoErr(t, err)
expected := []Role{
Role{ID: "9fe2ff9ee4384b1894a90878d3e92bab", Name: "foo_role"},
Role{ID: "1ea3d56793574b668e85960fbf651e13", Name: "admin"},
}
th.CheckDeepEquals(t, expected, actual)
return true, nil
})
th.AssertNoErr(t, err)
}