This repository has been archived by the owner on Oct 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscope_test.go
102 lines (87 loc) · 2.22 KB
/
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package aci
import (
"fmt"
"testing"
)
func TestScope(t *testing.T) {
var sc SearchScope
_ = sc.Eq()
for idx, raw := range []string{
`baSe`,
`oNe`,
`sub`,
} {
if sc := Scope(raw); sc == noScope {
t.Errorf("%s failed; failed to parse scope name '%s'",
t.Name(), raw)
return
}
if sc := Scope(idx); sc == noScope {
t.Errorf("%s failed; failed to parse scope index '%d'",
t.Name(), idx)
return
}
}
}
func TestScope_targetRules(t *testing.T) {
for idx, raw := range []string{
`baSe`,
`oNelevEL`,
`subTREe`,
`subORdinate`,
} {
oper := `=`
want := sprintf("( targetscope %s %q )", oper, lc(raw))
tscope := Scope(raw)
sEq := tscope.Eq()
if sEq.IsZero() {
t.Errorf("%s failed; failed to create TargetRule with scope '%s'",
t.Name(), tscope)
return
}
if sc := Scope(idx); sc.Target() != lc(raw) {
t.Errorf("%s failed; failed to parse scope index '%d'\nwant: '%s'\n got: '%s'",
t.Name(), idx, lc(raw), sc.Target())
return
}
if sEq.String() != want {
t.Errorf("%s failed; failed to create equality TargetRule: want '%s', got '%s'",
t.Name(), want, sEq)
return
}
// negated targetscope rule is illegal per ACIv3 syntax.
// Make sure we can't generate that particular scope, but
// are able to generate all others.
oper = `!` + oper
want = sprintf("( targetscope %s %q )", oper, lc(raw))
if sNe := tscope.Ne(); sNe != badTargetRule {
t.Errorf("%s failed; created illegal targetscope rule '%s' (%s)",
t.Name(), sNe, want)
return
}
}
}
func ExampleSearchScope_Compare() {
fmt.Printf("%s == %s: %t", SingleLevel, BaseObject, SingleLevel.Compare(BaseObject))
// Output: onelevel == base: false
}
func ExampleSearchScope_Keyword() {
fmt.Printf("%s", SingleLevel.Keyword())
// Output: targetscope
}
func ExampleSearchScope_String() {
fmt.Printf("%s", SingleLevel)
// Output: onelevel
}
func ExampleSearchScope_Target() {
fmt.Printf("%s", Subordinate) // only valid for target rule scenarios, never URIs!
// Output: subordinate
}
func ExampleSearchScope_TRM() {
fmt.Printf("Allows Ne: %t", SingleLevel.TRM().Contains(Ne))
// Output: Allows Ne: false
}
func ExampleSearchScope_Ne() {
fmt.Printf("%s", SingleLevel.Ne()) // ILLEGAL!!!!
// Output:
}