-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrbac_create_subject_test.go
More file actions
59 lines (44 loc) · 1.65 KB
/
rbac_create_subject_test.go
File metadata and controls
59 lines (44 loc) · 1.65 KB
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
package rbac
import (
"fmt"
"testing"
"github.com/stackvista/stackstate-cli/generated/stackstate_api"
"github.com/stackvista/stackstate-cli/internal/di"
"github.com/stretchr/testify/assert"
)
const (
SomeSubject = "subject"
SomeScope = "withNeighboursOf(components = (id = '*'), levels = '14534564576475675671', direction = 'both')"
)
func TestCreateSubjectJson(t *testing.T) {
cli := di.NewMockDeps(t)
cmd := CreateSubjectCommand(&cli.Deps)
di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "--subject", SomeSubject, "-o", "json")
calls := *cli.MockClient.ApiMocks.SubjectApi.CreateSubjectCalls
assert.Len(t, calls, 1)
assert.Equal(t, SomeSubject, calls[0].Psubject)
expectedSubject := stackstate_api.NewCreateSubject()
assert.Equal(t, expectedSubject, calls[0].PcreateSubject)
expectedJson := []map[string]interface{}{
{
"created-subject": SomeSubject,
},
}
assert.Equal(t, expectedJson, *cli.MockPrinter.PrintJsonCalls)
}
func TestCreateSubject(t *testing.T) {
cli := di.NewMockDeps(t)
cmd := CreateSubjectCommand(&cli.Deps)
di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "--subject", SomeOtherSubject, "--scope", SomeScope)
calls := *cli.MockClient.ApiMocks.SubjectApi.CreateSubjectCalls
assert.Len(t, calls, 1)
assert.Equal(t, SomeOtherSubject, calls[0].Psubject)
otherExpectedSubject := stackstate_api.NewCreateSubject()
otherExpectedSubject.SetQuery(SomeScope)
otherExpectedSubject.SetVersion("0.0.1")
assert.Equal(t, otherExpectedSubject, calls[0].PcreateSubject)
expectedStrings := []string{
fmt.Sprintf("Created subject '%s'", SomeOtherSubject),
}
assert.Equal(t, expectedStrings, *cli.MockPrinter.SuccessCalls)
}