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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
// +build acceptance
package v3
import (
"testing"
"github.com/gophercloud/gophercloud/acceptance/clients"
"github.com/gophercloud/gophercloud/acceptance/tools"
"github.com/gophercloud/gophercloud/openstack/identity/v3/groups"
th "github.com/gophercloud/gophercloud/testhelper"
)
func TestGroupCRUD(t *testing.T) {
clients.RequireAdmin(t)
client, err := clients.NewIdentityV3Client()
th.AssertNoErr(t, err)
createOpts := groups.CreateOpts{
Name: "testgroup",
DomainID: "default",
Extra: map[string]interface{}{
"email": "testgroup@example.com",
},
}
// Create Group in the default domain
group, err := CreateGroup(t, client, &createOpts)
th.AssertNoErr(t, err)
defer DeleteGroup(t, client, group.ID)
tools.PrintResource(t, group)
tools.PrintResource(t, group.Extra)
updateOpts := groups.UpdateOpts{
Description: "Test Groups",
Extra: map[string]interface{}{
"email": "thetestgroup@example.com",
},
}
newGroup, err := groups.Update(client, group.ID, updateOpts).Extract()
th.AssertNoErr(t, err)
tools.PrintResource(t, newGroup)
tools.PrintResource(t, newGroup.Extra)
listOpts := groups.ListOpts{
DomainID: "default",
}
// List all Groups in default domain
allPages, err := groups.List(client, listOpts).AllPages()
th.AssertNoErr(t, err)
allGroups, err := groups.ExtractGroups(allPages)
th.AssertNoErr(t, err)
for _, g := range allGroups {
tools.PrintResource(t, g)
tools.PrintResource(t, g.Extra)
}
var found bool
for _, group := range allGroups {
tools.PrintResource(t, group)
tools.PrintResource(t, group.Extra)
if group.Name == newGroup.Name {
found = true
}
}
th.AssertEquals(t, found, true)
listOpts.Filters = map[string]string{
"name__contains": "TEST",
}
allPages, err = groups.List(client, listOpts).AllPages()
th.AssertNoErr(t, err)
allGroups, err = groups.ExtractGroups(allPages)
th.AssertNoErr(t, err)
found = false
for _, group := range allGroups {
tools.PrintResource(t, group)
tools.PrintResource(t, group.Extra)
if group.Name == newGroup.Name {
found = true
}
}
th.AssertEquals(t, found, true)
listOpts.Filters = map[string]string{
"name__contains": "foo",
}
allPages, err = groups.List(client, listOpts).AllPages()
th.AssertNoErr(t, err)
allGroups, err = groups.ExtractGroups(allPages)
th.AssertNoErr(t, err)
found = false
for _, group := range allGroups {
tools.PrintResource(t, group)
tools.PrintResource(t, group.Extra)
if group.Name == newGroup.Name {
found = true
}
}
th.AssertEquals(t, found, false)
// Get the recently created group by ID
p, err := groups.Get(client, group.ID).Extract()
th.AssertNoErr(t, err)
tools.PrintResource(t, p)
}
|