Exemplo n.º 1
0
func TestCreateUser(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	mockCreateUserResponse(t)

	opts := users.CreateOpts{
		Name:     "new_user",
		TenantID: "12345",
		Enabled:  gophercloud.Disabled,
		Email:    "*****@*****.**",
	}

	user, err := users.Create(client.ServiceClient(), opts).Extract()

	th.AssertNoErr(t, err)

	expected := &users.User{
		Name:     "new_user",
		ID:       "c39e3de9be2d4c779f1dfd6abacc176d",
		Email:    "*****@*****.**",
		Enabled:  false,
		TenantID: "12345",
	}

	th.AssertDeepEquals(t, expected, user)
}
Exemplo n.º 2
0
// CreateUser will create a user with a random name and adds them to the given
// tenant. An error will be returned if the user was unable to be created.
func CreateUser(t *testing.T, client *gophercloud.ServiceClient, tenant *tenants.Tenant) (*users.User, error) {
	userName := tools.RandomString("user_", 5)
	userEmail := userName + "@foo.com"
	t.Logf("Creating user: %s", userName)

	createOpts := users.CreateOpts{
		Name:     userName,
		Enabled:  gophercloud.Disabled,
		TenantID: tenant.ID,
		Email:    userEmail,
	}

	user, err := users.Create(client, createOpts).Extract()
	if err != nil {
		return user, err
	}

	return user, nil
}