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
|
package kong
import (
"testing"
uuid "github.com/satori/go.uuid"
"github.com/stretchr/testify/assert"
)
func TestRBACRoleService(T *testing.T) {
runWhenEnterprise(T, ">=0.33.0", true)
assert := assert.New(T)
client, err := NewTestClient(nil, nil)
assert.Nil(err)
assert.NotNil(client)
role := &RBACRole{
Name: String("roleA"),
}
createdRole, err := client.RBACRoles.Create(defaultCtx, role)
assert.Nil(err)
assert.NotNil(createdRole)
role, err = client.RBACRoles.Get(defaultCtx, createdRole.ID)
assert.Nil(err)
assert.NotNil(role)
role.Comment = String("new comment")
role, err = client.RBACRoles.Update(defaultCtx, role)
assert.Nil(err)
assert.NotNil(role)
assert.Equal("roleA", *role.Name)
err = client.RBACRoles.Delete(defaultCtx, createdRole.ID)
assert.Nil(err)
// ID can be specified
id := uuid.NewV4().String()
role = &RBACRole{
Name: String("teamB"),
ID: String(id),
}
createdRole, err = client.RBACRoles.Create(defaultCtx, role)
assert.Nil(err)
assert.NotNil(createdRole)
assert.Equal(id, *createdRole.ID)
err = client.RBACRoles.Delete(defaultCtx, createdRole.ID)
assert.Nil(err)
}
func TestRBACRoleServiceList(T *testing.T) {
runWhenEnterprise(T, ">=0.33.0", true)
assert := assert.New(T)
client, err := NewTestClient(nil, nil)
assert.Nil(err)
assert.NotNil(client)
roleA := &RBACRole{
Name: String("roleA"),
}
roleB := &RBACRole{
Name: String("roleB"),
}
createdRoleA, err := client.RBACRoles.Create(defaultCtx, roleA)
assert.Nil(err)
createdRoleB, err := client.RBACRoles.Create(defaultCtx, roleB)
assert.Nil(err)
roles, err := client.RBACRoles.List(defaultCtx)
assert.Nil(err)
assert.NotNil(roles)
// Counts default roles (super-admin, admin, read-only)
assert.Equal(5, len(roles))
err = client.RBACRoles.Delete(defaultCtx, createdRoleA.ID)
assert.Nil(err)
err = client.RBACRoles.Delete(defaultCtx, createdRoleB.ID)
assert.Nil(err)
}
|