-
Notifications
You must be signed in to change notification settings - Fork 0
/
request_test.go
74 lines (71 loc) · 1.39 KB
/
request_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
package leges_test
import (
"github.com/siadat/leges"
"github.com/stretchr/testify/require"
"testing"
)
func TestRequest_Validate(t *testing.T) {
tests := []struct {
name string
request leges.Request
err error
}{
{
name: "valid request",
request: leges.Request{
Action: "UPDATE",
Subject: leges.Attributes{
"id": "user1",
},
Object: leges.Attributes{
"type": "account",
"owner_id": "user1",
},
},
err: nil,
},
{
name: "empty object - invalid request",
request: leges.Request{
Action: "UPDATE",
Subject: leges.Attributes{
"id": "user1",
},
Object: leges.Attributes{},
},
err: leges.ErrEmptyObjectAttrs,
},
{
name: "empty subject - invalid request",
request: leges.Request{
Action: "UPDATE",
Subject: leges.Attributes{},
Object: leges.Attributes{
"type": "account",
"owner_id": "user1",
},
},
err: leges.ErrEmptySubjectAttrs,
},
{
name: "empty action - invalid request",
request: leges.Request{
Action: "",
Subject: leges.Attributes{
"id": "user1",
},
Object: leges.Attributes{
"type": "account",
"owner_id": "user1",
},
},
err: leges.ErrEmptyAction,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
err := test.request.Validate()
require.Equal(t, err, test.err)
})
}
}