@@ -13,34 +13,51 @@ import (
13
13
"github.com/xeipuuv/gojsonschema"
14
14
)
15
15
16
- var compiledSchema * gojsonschema.Schema
16
+ var compiledFlagDefinitionSchema * gojsonschema.Schema
17
+ var compiledTargetingSchema * gojsonschema.Schema
17
18
18
19
func init () {
19
- schemaLoader := gojsonschema .NewSchemaLoader ()
20
- schemaLoader .AddSchemas (gojsonschema .NewStringLoader (flagd_definitions .TargetingSchema ))
20
+ flagDefinitionSchemaLoader := gojsonschema .NewSchemaLoader ()
21
+ flagDefinitionSchemaLoader .AddSchemas (gojsonschema .NewStringLoader (flagd_definitions .TargetingSchema ))
22
+ targetingSchemaLoader := gojsonschema .NewSchemaLoader ()
21
23
var err error
22
- compiledSchema , err = schemaLoader .Compile (gojsonschema .NewStringLoader (flagd_definitions .FlagSchema ))
24
+ compiledFlagDefinitionSchema , err = flagDefinitionSchemaLoader .Compile (gojsonschema .NewStringLoader (flagd_definitions .FlagSchema ))
25
+ compiledTargetingSchema , err = targetingSchemaLoader .Compile (gojsonschema .NewStringLoader (flagd_definitions .TargetingSchema ))
23
26
if err != nil {
24
27
message := fmt .Errorf ("err: %v" , err )
25
28
log .Fatal (message )
26
29
}
27
30
}
28
31
29
32
func TestPositiveParsing (t * testing.T ) {
30
- if err := walkPath (true , "./test/positive" ); err != nil {
33
+ if err := walkPath (true , "./test/positive" , compiledFlagDefinitionSchema ); err != nil {
31
34
t .Error (err )
32
35
t .FailNow ()
33
36
}
34
37
}
35
38
36
39
func TestNegativeParsing (t * testing.T ) {
37
- if err := walkPath (false , "./test/negative" ); err != nil {
40
+ if err := walkPath (false , "./test/negative" , compiledFlagDefinitionSchema ); err != nil {
38
41
t .Error (err )
39
42
t .FailNow ()
40
43
}
41
44
}
42
45
43
- func walkPath (shouldPass bool , root string ) error {
46
+ func TestPositiveTargetingParsing (t * testing.T ) {
47
+ if err := walkPath (true , "./test/targeting-only/positive" , compiledTargetingSchema ); err != nil {
48
+ t .Error (err )
49
+ t .FailNow ()
50
+ }
51
+ }
52
+
53
+ func TestNegativeTargetingParsing (t * testing.T ) {
54
+ if err := walkPath (false , "./test/targeting-only/negative" , compiledTargetingSchema ); err != nil {
55
+ t .Error (err )
56
+ t .FailNow ()
57
+ }
58
+ }
59
+
60
+ func walkPath (shouldPass bool , root string , schema * gojsonschema.Schema ) error {
44
61
return filepath .Walk (root , func (path string , info os.FileInfo , err error ) error {
45
62
if err != nil {
46
63
return err
@@ -56,7 +73,7 @@ func walkPath(shouldPass bool, root string) error {
56
73
57
74
flagStringLoader := gojsonschema .NewStringLoader (string (file ))
58
75
59
- p , err := compiledSchema .Validate (flagStringLoader )
76
+ p , err := schema .Validate (flagStringLoader )
60
77
if err != nil {
61
78
return err
62
79
}
0 commit comments