github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/identity/v2/tenants/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "testing" 5 6 "github.com/huaweicloud/golangsdk" 7 "github.com/huaweicloud/golangsdk/openstack/identity/v2/tenants" 8 "github.com/huaweicloud/golangsdk/pagination" 9 th "github.com/huaweicloud/golangsdk/testhelper" 10 "github.com/huaweicloud/golangsdk/testhelper/client" 11 ) 12 13 func TestListTenants(t *testing.T) { 14 th.SetupHTTP() 15 defer th.TeardownHTTP() 16 HandleListTenantsSuccessfully(t) 17 18 count := 0 19 err := tenants.List(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) { 20 count++ 21 22 actual, err := tenants.ExtractTenants(page) 23 th.AssertNoErr(t, err) 24 25 th.CheckDeepEquals(t, ExpectedTenantSlice, actual) 26 27 return true, nil 28 }) 29 th.AssertNoErr(t, err) 30 th.CheckEquals(t, count, 1) 31 } 32 33 func TestCreateTenant(t *testing.T) { 34 th.SetupHTTP() 35 defer th.TeardownHTTP() 36 37 mockCreateTenantResponse(t) 38 39 opts := tenants.CreateOpts{ 40 Name: "new_tenant", 41 Description: "This is new tenant", 42 Enabled: golangsdk.Enabled, 43 } 44 45 tenant, err := tenants.Create(client.ServiceClient(), opts).Extract() 46 47 th.AssertNoErr(t, err) 48 49 expected := &tenants.Tenant{ 50 Name: "new_tenant", 51 Description: "This is new tenant", 52 Enabled: true, 53 ID: "5c62ef576dc7444cbb73b1fe84b97648", 54 } 55 56 th.AssertDeepEquals(t, expected, tenant) 57 } 58 59 func TestDeleteTenant(t *testing.T) { 60 th.SetupHTTP() 61 defer th.TeardownHTTP() 62 63 mockDeleteTenantResponse(t) 64 65 err := tenants.Delete(client.ServiceClient(), "2466f69cd4714d89a548a68ed97ffcd4").ExtractErr() 66 th.AssertNoErr(t, err) 67 } 68 69 func TestUpdateTenant(t *testing.T) { 70 th.SetupHTTP() 71 defer th.TeardownHTTP() 72 73 mockUpdateTenantResponse(t) 74 75 id := "5c62ef576dc7444cbb73b1fe84b97648" 76 opts := tenants.UpdateOpts{ 77 Name: "new_name", 78 Description: "This is new name", 79 Enabled: golangsdk.Enabled, 80 } 81 82 tenant, err := tenants.Update(client.ServiceClient(), id, opts).Extract() 83 84 th.AssertNoErr(t, err) 85 86 expected := &tenants.Tenant{ 87 Name: "new_name", 88 ID: id, 89 Description: "This is new name", 90 Enabled: true, 91 } 92 93 th.AssertDeepEquals(t, expected, tenant) 94 } 95 96 func TestGetTenant(t *testing.T) { 97 th.SetupHTTP() 98 defer th.TeardownHTTP() 99 100 mockGetTenantResponse(t) 101 102 tenant, err := tenants.Get(client.ServiceClient(), "5c62ef576dc7444cbb73b1fe84b97648").Extract() 103 th.AssertNoErr(t, err) 104 105 expected := &tenants.Tenant{ 106 Name: "new_tenant", 107 ID: "5c62ef576dc7444cbb73b1fe84b97648", 108 Description: "This is new tenant", 109 Enabled: true, 110 } 111 112 th.AssertDeepEquals(t, expected, tenant) 113 }