github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/identity/v2/extensions/admin/roles/testing/requests_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/huaweicloud/golangsdk/openstack/identity/v2/extensions/admin/roles"
     7  	"github.com/huaweicloud/golangsdk/pagination"
     8  	th "github.com/huaweicloud/golangsdk/testhelper"
     9  	"github.com/huaweicloud/golangsdk/testhelper/client"
    10  )
    11  
    12  func TestRole(t *testing.T) {
    13  	th.SetupHTTP()
    14  	defer th.TeardownHTTP()
    15  
    16  	MockListRoleResponse(t)
    17  
    18  	count := 0
    19  
    20  	err := roles.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
    21  		count++
    22  		actual, err := roles.ExtractRoles(page)
    23  		if err != nil {
    24  			t.Errorf("Failed to extract users: %v", err)
    25  			return false, err
    26  		}
    27  
    28  		expected := []roles.Role{
    29  			{
    30  				ID:          "123",
    31  				Name:        "compute:admin",
    32  				Description: "Nova Administrator",
    33  			},
    34  		}
    35  
    36  		th.CheckDeepEquals(t, expected, actual)
    37  
    38  		return true, nil
    39  	})
    40  
    41  	th.AssertNoErr(t, err)
    42  	th.AssertEquals(t, 1, count)
    43  }
    44  
    45  func TestAddUser(t *testing.T) {
    46  	th.SetupHTTP()
    47  	defer th.TeardownHTTP()
    48  
    49  	MockAddUserRoleResponse(t)
    50  
    51  	err := roles.AddUser(client.ServiceClient(), "{tenant_id}", "{user_id}", "{role_id}").ExtractErr()
    52  
    53  	th.AssertNoErr(t, err)
    54  }
    55  
    56  func TestDeleteUser(t *testing.T) {
    57  	th.SetupHTTP()
    58  	defer th.TeardownHTTP()
    59  
    60  	MockDeleteUserRoleResponse(t)
    61  
    62  	err := roles.DeleteUser(client.ServiceClient(), "{tenant_id}", "{user_id}", "{role_id}").ExtractErr()
    63  
    64  	th.AssertNoErr(t, err)
    65  }