talos/pkg/machinery/role/role_test.go
Alexey Palazhchenko f63ab9dd9b feat: implement talosctl config new command
Refs #3421.

Signed-off-by: Alexey Palazhchenko <alexey.palazhchenko@gmail.com>
2021-06-17 09:06:43 -07:00

35 lines
1.2 KiB
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package role_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/talos-systems/talos/pkg/machinery/role"
)
func TestSet(t *testing.T) {
t.Parallel()
roles, unknownRoles := role.Parse([]string{"os:admin", "os:reader", "os:future", "os:impersonator", "", " "})
assert.Equal(t, []string{"os:future"}, unknownRoles)
assert.Equal(t, role.MakeSet(role.Admin, role.Reader, role.Role("os:future"), role.Impersonator), roles)
assert.Equal(t, []string{"os:admin", "os:future", "os:impersonator", "os:reader"}, roles.Strings())
assert.Equal(t, []string{}, role.MakeSet().Strings())
assert.True(t, roles.Includes(role.Admin))
assert.False(t, roles.Includes(role.Role("wrong")))
assert.True(t, roles.IncludesAny(role.MakeSet(role.Admin)))
assert.False(t, roles.IncludesAny(role.MakeSet(role.Role("wrong"))))
assert.False(t, roles.IncludesAny(role.MakeSet()))
assert.False(t, role.MakeSet().IncludesAny(roles))
assert.False(t, role.MakeSet().IncludesAny(role.MakeSet()))
}