github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/db/v1/users/testing/requests_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"testing"
     5  
     6  	db "github.com/huaweicloud/golangsdk/openstack/db/v1/databases"
     7  	"github.com/huaweicloud/golangsdk/openstack/db/v1/users"
     8  	"github.com/huaweicloud/golangsdk/pagination"
     9  	th "github.com/huaweicloud/golangsdk/testhelper"
    10  	fake "github.com/huaweicloud/golangsdk/testhelper/client"
    11  )
    12  
    13  func TestCreate(t *testing.T) {
    14  	th.SetupHTTP()
    15  	defer th.TeardownHTTP()
    16  	HandleCreate(t)
    17  
    18  	opts := users.BatchCreateOpts{
    19  		{
    20  			Databases: db.BatchCreateOpts{
    21  				db.CreateOpts{Name: "databaseA"},
    22  			},
    23  			Name:     "dbuser3",
    24  			Password: "secretsecret",
    25  		},
    26  		{
    27  			Databases: db.BatchCreateOpts{
    28  				{Name: "databaseB"},
    29  				{Name: "databaseC"},
    30  			},
    31  			Name:     "dbuser4",
    32  			Password: "secretsecret",
    33  		},
    34  	}
    35  
    36  	res := users.Create(fake.ServiceClient(), instanceID, opts)
    37  	th.AssertNoErr(t, res.Err)
    38  }
    39  
    40  func TestUserList(t *testing.T) {
    41  	th.SetupHTTP()
    42  	defer th.TeardownHTTP()
    43  	HandleList(t)
    44  
    45  	expectedUsers := []users.User{
    46  		{
    47  			Databases: []db.Database{
    48  				{Name: "databaseA"},
    49  			},
    50  			Name: "dbuser3",
    51  		},
    52  		{
    53  			Databases: []db.Database{
    54  				{Name: "databaseB"},
    55  				{Name: "databaseC"},
    56  			},
    57  			Name: "dbuser4",
    58  		},
    59  	}
    60  
    61  	pages := 0
    62  	err := users.List(fake.ServiceClient(), instanceID).EachPage(func(page pagination.Page) (bool, error) {
    63  		pages++
    64  
    65  		actual, err := users.ExtractUsers(page)
    66  		if err != nil {
    67  			return false, err
    68  		}
    69  
    70  		th.CheckDeepEquals(t, expectedUsers, actual)
    71  		return true, nil
    72  	})
    73  
    74  	th.AssertNoErr(t, err)
    75  	th.AssertEquals(t, 1, pages)
    76  }
    77  
    78  func TestDelete(t *testing.T) {
    79  	th.SetupHTTP()
    80  	defer th.TeardownHTTP()
    81  	HandleDelete(t)
    82  
    83  	res := users.Delete(fake.ServiceClient(), instanceID, "{userName}")
    84  	th.AssertNoErr(t, res.Err)
    85  }