-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcourse_module_restriction_test.go
83 lines (70 loc) · 2.73 KB
/
course_module_restriction_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
79
80
81
82
83
package moodle
import (
"fmt"
"os"
"testing"
)
func TestRestriction(t *testing.T) {
// Simply a basic: Must be in audit group
// {"op":"&","c":[{"type":"group","id":191}],"showc":[true]}
rules := &Restriction{}
rules.OP = "&"
rules.C = append(rules.C, RestrictionC{Type: "group", Id: 10})
rules.ShowC = append(rules.ShowC, true)
groups := []CourseGroup{CourseGroup{Id: 10}, CourseGroup{Id: 20}}
rules.IsRestricted(groups)
if rules.IsRestricted(groups) { // Should see (not restricted)
t.Errorf("Restriction rule failure: %v %v", rules, groups)
}
groups = []CourseGroup{CourseGroup{Id: 5}, CourseGroup{Id: 15}}
rules.IsRestricted(groups)
if !rules.IsRestricted(groups) { // Should not see (restricted)
t.Errorf("Restriction rule failure: %v %v", rules, groups)
}
//Must be in both groups:
// {"op":"&","c":[{"type":"group","id":191},{"type":"group","id":192}],"showc":[true,true]}"
rules = &Restriction{}
rules.OP = "&"
rules.C = append(rules.C, RestrictionC{Type: "group", Id: 10})
rules.C = append(rules.C, RestrictionC{Type: "group", Id: 20})
rules.ShowC = append(rules.ShowC, true)
rules.ShowC = append(rules.ShowC, true)
//Must not be in audit group:
// {"op":"!&","c":[{"type":"group","id":191}],"show":true}
rules = &Restriction{}
rules.OP = "!&"
rules.C = append(rules.C, RestrictionC{Type: "group", Id: 10})
rules.Show = true
//Must be in either group:
// {"op":"|","c":[{"type":"group","id":191},{"type":"group","id":192}],"show":true}
rules = &Restriction{}
rules.OP = "|"
rules.C = append(rules.C, RestrictionC{Type: "group", Id: 10})
rules.C = append(rules.C, RestrictionC{Type: "group", Id: 20})
rules.ShowC = append(rules.ShowC, true)
rules.ShowC = append(rules.ShowC, true)
//Must not be in both groups:
// {"op":"!&","c":[{"type":"group","id":191},{"type":"group","id":192}],"show":true}
rules = &Restriction{}
rules.OP = "!&"
rules.C = append(rules.C, RestrictionC{Type: "group", Id: 10})
rules.C = append(rules.C, RestrictionC{Type: "group", Id: 20})
rules.Show = true
//Must not be in 191, or must not be in 192:
// {"op":"!|","c":[{"type":"group","id":191},{"type":"group","id":192}],"showc":[true,true]}
rules = &Restriction{}
rules.OP = "!|"
rules.C = append(rules.C, RestrictionC{Type: "group", Id: 10})
rules.C = append(rules.C, RestrictionC{Type: "group", Id: 20})
rules.ShowC = append(rules.ShowC, true)
rules.ShowC = append(rules.ShowC, true)
//Must not be in any of these groups
// {"op":"!&","c":[{"type":"group","id":191},{"type":"group","id":192},{"type":"date","d":">=","t":1541682000}],"show":true}"
}
func requireEnv(name string, t *testing.T) string {
value := os.Getenv(name)
if value == "" {
t.Fatalf(fmt.Sprintf("Environment variable required: %s", name))
}
return value
}