File: tenant_test.go

package info (click to toggle)
golang-github-gophercloud-gophercloud 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,416 kB
  • sloc: sh: 99; makefile: 21
file content (67 lines) | stat: -rw-r--r-- 1,508 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//go:build acceptance || identity
// +build acceptance identity

package v2

import (
	"testing"

	"github.com/gophercloud/gophercloud/acceptance/clients"
	"github.com/gophercloud/gophercloud/acceptance/tools"
	"github.com/gophercloud/gophercloud/openstack/identity/v2/tenants"
	th "github.com/gophercloud/gophercloud/testhelper"
)

func TestTenantsList(t *testing.T) {
	clients.RequireIdentityV2(t)
	clients.RequireAdmin(t)

	client, err := clients.NewIdentityV2Client()
	th.AssertNoErr(t, err)

	allPages, err := tenants.List(client, nil).AllPages()
	th.AssertNoErr(t, err)

	allTenants, err := tenants.ExtractTenants(allPages)
	th.AssertNoErr(t, err)

	var found bool
	for _, tenant := range allTenants {
		tools.PrintResource(t, tenant)

		if tenant.Name == "admin" {
			found = true
		}
	}

	th.AssertEquals(t, found, true)
}

func TestTenantsCRUD(t *testing.T) {
	clients.RequireIdentityV2(t)
	clients.RequireAdmin(t)

	client, err := clients.NewIdentityV2AdminClient()
	th.AssertNoErr(t, err)

	tenant, err := CreateTenant(t, client, nil)
	th.AssertNoErr(t, err)
	defer DeleteTenant(t, client, tenant.ID)

	tenant, err = tenants.Get(client, tenant.ID).Extract()
	th.AssertNoErr(t, err)

	tools.PrintResource(t, tenant)

	description := ""
	updateOpts := tenants.UpdateOpts{
		Description: &description,
	}

	newTenant, err := tenants.Update(client, tenant.ID, updateOpts).Extract()
	th.AssertNoErr(t, err)

	tools.PrintResource(t, newTenant)

	th.AssertEquals(t, newTenant.Description, description)
}