Select Git revision
role_test.go
role_test.go 4.59 KiB
package roles
import (
"context"
"testing"
"git.perx.ru/perxis/perxis-go/pkg/environments"
mocksenvs "git.perx.ru/perxis/perxis-go/pkg/environments/mocks"
"github.com/stretchr/testify/mock"
)
func TestRoleCanAccessEnvironment(t *testing.T) {
type args struct {
ctx context.Context
envscall func(envsservice *mocksenvs.Environments)
role *Role
env *environments.Environment
}
tests := []struct {
name string
args args
want bool
}{
{
name: "simple",
args: args{
ctx: context.Background(),
role: &Role{
ID: "1",
SpaceID: "space",
Description: "Current",
Environments: []string{"env1", "env2"},
},
env: &environments.Environment{ID: "env1", SpaceID: "sp"},
},
want: true,
},
{
name: "glob env in role test: e*",
args: args{
ctx: context.Background(),
envscall: func(envsservice *mocksenvs.Environments) {
envsservice.On("Get", mock.Anything, mock.Anything, mock.Anything).Return(&environments.Environment{
ID: "env1",
SpaceID: "space",
Aliases: []string{"master"},
}, nil).Once()
},
role: &Role{
ID: "1",
SpaceID: "space",
Description: "Current",
Environments: []string{"e*"},
},
env: &environments.Environment{ID: "env", SpaceID: "sp"},
},
want: true,
},
{
name: "glob env in role test: *n*",
args: args{
ctx: context.Background(),
envscall: func(envsservice *mocksenvs.Environments) {
envsservice.On("Get", mock.Anything, mock.Anything, mock.Anything).Return(&environments.Environment{
ID: "env1",
SpaceID: "space",
Aliases: []string{"master"},
}, nil).Once()
},
role: &Role{