@@ -11,62 +11,85 @@ import (
11
11
)
12
12
13
13
func TestRoundTrip (t * testing.T ) {
14
+ tests := []struct {
15
+ note string
16
+ modules map [string ]string
17
+ }{
18
+ {
19
+ note : "simple" ,
20
+ modules : map [string ]string {
21
+ "test.rego" : `
22
+ package test
23
+ p if {
24
+ input.foo == 7
25
+ }
26
+ ` ,
27
+ },
28
+ },
29
+ {
30
+ note : "every" ,
31
+ modules : map [string ]string {
32
+ "test.rego" : `
33
+ package test
34
+ p if {
35
+ every i in input.foo { i > 0 }
36
+ }
37
+ ` ,
38
+ },
39
+ },
40
+ }
14
41
15
- // Note: v1 module
16
- c , err := ast . CompileModules ( map [ string ] string {
17
- "test.rego" : `
18
- package test
42
+ for _ , tc := range tests {
43
+ t . Run ( tc . note , func ( t * testing. T ) {
44
+ // Note: v1 module
45
+ c , err := ast . CompileModules ( tc . modules )
19
46
20
- p if {
21
- input.foo == 7
47
+ if err != nil {
48
+ t . Fatal ( err )
22
49
}
23
- ` ,
24
- })
25
-
26
- if err != nil {
27
- t .Fatal (err )
28
- }
29
50
30
- modules := []* ast.Module {}
51
+ modules := []* ast.Module {}
31
52
32
- for _ , m := range c .Modules {
33
- modules = append (modules , m )
34
- }
53
+ for _ , m := range c .Modules {
54
+ modules = append (modules , m )
55
+ }
35
56
36
- planner := planner .New ().
37
- WithQueries ([]planner.QuerySet {
38
- {
39
- Name : "main" ,
40
- Queries : []ast.Body {
41
- ast .MustParseBody ("data.test.p = true" ),
42
- },
43
- },
44
- }).
45
- WithModules (modules ).
46
- WithBuiltinDecls (ast .BuiltinMap )
57
+ planner := planner .New ().
58
+ WithQueries ([]planner.QuerySet {
59
+ {
60
+ Name : "main" ,
61
+ Queries : []ast.Body {
62
+ ast .MustParseBody ("data.test.p = true" ),
63
+ },
64
+ },
65
+ }).
66
+ WithModules (modules ).
67
+ WithBuiltinDecls (ast .BuiltinMap )
47
68
48
- plan , err := planner .Plan ()
49
- if err != nil {
50
- t .Fatal (err )
51
- }
69
+ plan , err := planner .Plan ()
70
+ if err != nil {
71
+ t .Fatal (err )
72
+ }
52
73
53
- bs , err := json .MarshalIndent (plan , "" , " " )
54
- if err != nil {
55
- t .Fatal (err )
56
- }
74
+ bs , err := json .MarshalIndent (plan , "" , " " )
75
+ if err != nil {
76
+ t .Fatal (err )
77
+ }
57
78
58
- var cpy ir.Policy
59
- err = json .Unmarshal (bs , & cpy )
60
- if err != nil {
61
- t .Fatal (err )
62
- }
79
+ var cpy ir.Policy
80
+ err = json .Unmarshal (bs , & cpy )
81
+ if err != nil {
82
+ t .Fatal (err )
83
+ }
63
84
64
- bs2 , err := json .MarshalIndent (plan , "" , " " )
65
- if err != nil {
66
- t .Fatal (err )
67
- }
85
+ bs2 , err := json .MarshalIndent (plan , "" , " " )
86
+ if err != nil {
87
+ t .Fatal (err )
88
+ }
68
89
69
- if ! bytes .Equal (bs , bs2 ) {
70
- t .Fatal ("expected bytes to be equal" )
90
+ if ! bytes .Equal (bs , bs2 ) {
91
+ t .Fatal ("expected bytes to be equal" )
92
+ }
93
+ })
71
94
}
72
95
}
0 commit comments