Skip to content

Commit 7f73a3c

Browse files
authored
Identity: Add description field to roles.
Signed-off-by: Daniel Lawton <dlawton@redhat.com>
1 parent 4a4715c commit 7f73a3c

5 files changed

Lines changed: 47 additions & 21 deletions

File tree

internal/acceptance/openstack/identity/v3/roles_test.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ func TestRolesCRUD(t *testing.T) {
5858
th.AssertNoErr(t, err)
5959

6060
createOpts := roles.CreateOpts{
61-
Name: "testrole",
62-
DomainID: "default",
61+
Name: "role-test",
62+
DomainID: "default",
63+
Description: "test description",
6364
Extra: map[string]any{
64-
"description": "test role description",
65+
"email": "testrole@example.com",
6566
},
6667
Options: map[roles.Option]any{
6768
"immutable": false,
@@ -96,10 +97,11 @@ func TestRolesCRUD(t *testing.T) {
9697
}
9798

9899
th.AssertEquals(t, found, true)
99-
100+
description := "updated role test"
100101
updateOpts := roles.UpdateOpts{
102+
Description: &description,
101103
Extra: map[string]any{
102-
"description": "updated test role description",
104+
"email": "updatedtestrole@example.com",
103105
},
104106
Options: map[roles.Option]any{
105107
"immutable": nil,
@@ -112,7 +114,9 @@ func TestRolesCRUD(t *testing.T) {
112114
tools.PrintResource(t, newRole)
113115
tools.PrintResource(t, newRole.Extra)
114116

115-
th.AssertEquals(t, newRole.Extra["description"], "updated test role description")
117+
th.AssertEquals(t, newRole.Description, description)
118+
th.AssertEquals(t, newRole.Extra["email"], "updatedtestrole@example.com")
119+
116120
}
117121

118122
func TestRolesFilterList(t *testing.T) {

openstack/identity/v3/roles/requests.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ type CreateOpts struct {
9494
// DomainID is the ID of the domain the role belongs to.
9595
DomainID string `json:"domain_id,omitempty"`
9696

97+
// Description is the description of the new role.
98+
Description string `json:"description,omitempty"`
99+
97100
// Extra is free-form extra key/value pairs to describe the role.
98101
Extra map[string]any `json:"-"`
99102

@@ -141,9 +144,12 @@ type UpdateOptsBuilder interface {
141144

142145
// UpdateOpts provides options for updating a role.
143146
type UpdateOpts struct {
144-
// Name is the name of the new role.
147+
// Name is an updated name for the role.
145148
Name string `json:"name,omitempty"`
146149

150+
// Description is an updated description for the role.
151+
Description *string `json:"description,omitempty"`
152+
147153
// Extra is free-form extra key/value pairs to describe the role.
148154
Extra map[string]any `json:"-"`
149155

openstack/identity/v3/roles/results.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ type Role struct {
2121
// Name is the role name
2222
Name string `json:"name"`
2323

24+
// Description is the description of the role.
25+
Description string `json:"description"`
26+
2427
// Extra is a collection of miscellaneous key/values.
2528
Extra map[string]any `json:"-"`
2629

openstack/identity/v3/roles/testing/fixtures_test.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ const ListOutput = `
3434
"self": "https://example.com/identity/v3/roles/9fe1d3"
3535
},
3636
"name": "support",
37+
"description": "read-only support role",
3738
"extra": {
38-
"description": "read-only support role"
39+
"test": "this is for the test"
3940
}
4041
}
4142
]
@@ -52,7 +53,10 @@ const GetOutput = `
5253
"self": "https://example.com/identity/v3/roles/9fe1d3"
5354
},
5455
"name": "support",
55-
"description": "read-only support role"
56+
"description": "read-only support role",
57+
"extra": {
58+
"test": "this is for the test"
59+
}
5660
}
5761
}
5862
`
@@ -70,6 +74,9 @@ const GetOutputWithOptions = `
7074
"description": "read-only support role",
7175
"options": {
7276
"immutable": true
77+
},
78+
"extra": {
79+
"test": "this is for the test"
7380
}
7481
}
7582
}
@@ -81,7 +88,8 @@ const CreateRequest = `
8188
"role": {
8289
"domain_id": "1789d1",
8390
"name": "support",
84-
"description": "read-only support role"
91+
"description": "read-only support role",
92+
"test": "this is for the test"
8593
}
8694
}
8795
`
@@ -93,6 +101,7 @@ const CreateRequestWithOptions = `
93101
"domain_id": "1789d1",
94102
"name": "support",
95103
"description": "read-only support role",
104+
"test": "this is for the test",
96105
"options": {
97106
"immutable": true
98107
}
@@ -354,9 +363,10 @@ var SecondRole = roles.Role{
354363
Links: map[string]any{
355364
"self": "https://example.com/identity/v3/roles/9fe1d3",
356365
},
357-
Name: "support",
366+
Name: "support",
367+
Description: "read-only support role",
358368
Extra: map[string]any{
359-
"description": "read-only support role",
369+
"test": "this is for the test",
360370
},
361371
}
362372

@@ -367,9 +377,10 @@ var SecondRoleWithOptions = roles.Role{
367377
Links: map[string]any{
368378
"self": "https://example.com/identity/v3/roles/9fe1d3",
369379
},
370-
Name: "support",
380+
Name: "support",
381+
Description: "read-only support role",
371382
Extra: map[string]any{
372-
"description": "read-only support role",
383+
"test": "this is for the test",
373384
},
374385
Options: map[roles.Option]any{
375386
roles.Immutable: true,

openstack/identity/v3/roles/testing/requests_test.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestListRolesAllPages(t *testing.T) {
4040
actual, err := roles.ExtractRoles(allPages)
4141
th.AssertNoErr(t, err)
4242
th.CheckDeepEquals(t, ExpectedRolesSlice, actual)
43-
th.AssertEquals(t, ExpectedRolesSlice[1].Extra["description"], "read-only support role")
43+
th.AssertEquals(t, ExpectedRolesSlice[1].Extra["test"], "this is for the test")
4444
}
4545

4646
func TestListUsersFiltersCheck(t *testing.T) {
@@ -92,10 +92,11 @@ func TestCreateRole(t *testing.T) {
9292
HandleCreateRoleSuccessfully(t, fakeServer)
9393

9494
createOpts := roles.CreateOpts{
95-
Name: "support",
96-
DomainID: "1789d1",
95+
Name: "support",
96+
DomainID: "1789d1",
97+
Description: "read-only support role",
9798
Extra: map[string]any{
98-
"description": "read-only support role",
99+
"test": "this is for the test",
99100
},
100101
}
101102

@@ -110,13 +111,14 @@ func TestCreateWithOptionsRole(t *testing.T) {
110111
HandleCreateWithOptionsRoleSuccessfully(t, fakeServer)
111112

112113
createOpts := roles.CreateOpts{
113-
Name: "support",
114-
DomainID: "1789d1",
114+
Name: "support",
115+
DomainID: "1789d1",
116+
Description: "read-only support role",
115117
Options: map[roles.Option]any{
116118
roles.Immutable: true,
117119
},
118120
Extra: map[string]any{
119-
"description": "read-only support role",
121+
"test": "this is for the test",
120122
},
121123
}
122124

0 commit comments

Comments
 (0)