forked from ilijamt/vault-plugin-secrets-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
type_token_scope_test.go
78 lines (75 loc) · 1.81 KB
/
type_token_scope_test.go
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
package gitlab_test
import (
gitlab "github.com/ilijamt/vault-plugin-secrets-gitlab"
"github.com/stretchr/testify/assert"
"testing"
)
func TestTokenScope(t *testing.T) {
var tests = []struct {
expected gitlab.TokenScope
input string
err bool
}{
{
expected: gitlab.TokenScopeApi,
input: gitlab.TokenScopeApi.String(),
},
{
expected: gitlab.TokenScopeReadApi,
input: gitlab.TokenScopeReadApi.String(),
},
{
expected: gitlab.TokenScopeReadRegistry,
input: gitlab.TokenScopeReadRegistry.String(),
},
{
expected: gitlab.TokenScopeWriteRegistry,
input: gitlab.TokenScopeWriteRegistry.String(),
},
{
expected: gitlab.TokenScopeReadRepository,
input: gitlab.TokenScopeReadRepository.String(),
},
{
expected: gitlab.TokenScopeWriteRepository,
input: gitlab.TokenScopeWriteRepository.String(),
},
{
expected: gitlab.TokenScopeCreateRunner,
input: gitlab.TokenScopeCreateRunner.String(),
},
{
expected: gitlab.TokenScopeReadUser,
input: gitlab.TokenScopeReadUser.String(),
},
{
expected: gitlab.TokenScopeSudo,
input: gitlab.TokenScopeSudo.String(),
},
{
expected: gitlab.TokenScopeAdminMode,
input: gitlab.TokenScopeAdminMode.String(),
},
{
expected: gitlab.TokenScopeUnknown,
input: "what",
err: true,
},
{
expected: gitlab.TokenScopeUnknown,
input: "unknown",
err: true,
},
}
for _, test := range tests {
t.Logf("assert parse(%s) = %s (err: %v)", test.input, test.expected, test.err)
val, err := gitlab.TokenScopeParse(test.input)
assert.EqualValues(t, test.expected, val)
assert.EqualValues(t, test.expected.Value(), test.expected.String())
if test.err {
assert.ErrorIs(t, err, gitlab.ErrUnknownTokenScope)
} else {
assert.NoError(t, err)
}
}
}