@@ -6,17 +6,69 @@ import (
66 "reflect"
77 "testing"
88
9+ "github.com/cloudquery/plugin-sdk/v4/plugin"
910 "github.com/cloudquery/plugin-sdk/v4/scheduler"
1011 "github.com/invopop/jsonschema"
1112 "github.com/stretchr/testify/require"
1213)
1314
14- //go:embed strategy.json
15- var jsonSchema string
16-
1715func TestStrategy_JSONSchema (t * testing.T ) {
1816 sc := (& jsonschema.Reflector {RequiredFromJSONSchemaTags : true }).ReflectFromType (reflect .TypeOf (scheduler .StrategyDFS ))
19- data , err := json .MarshalIndent (sc , "" , " " )
17+ schema , err := json .MarshalIndent (sc , "" , " " )
18+ require .NoError (t , err )
19+
20+ validator , err := plugin .JSONSchemaValidator (string (schema ))
2021 require .NoError (t , err )
21- require .JSONEq (t , string (data )+ "\n " , jsonSchema )
22+
23+ type testCase struct {
24+ Name string
25+ Spec string
26+ Err bool
27+ }
28+
29+ for _ , tc := range []testCase {
30+ {
31+ Name : "dfs scheduler" ,
32+ Spec : `"dfs"` ,
33+ },
34+ {
35+ Name : "round-robin scheduler" ,
36+ Spec : `"round-robin"` ,
37+ },
38+ {
39+ Name : "shuffle scheduler" ,
40+ Spec : `"shuffle"` ,
41+ },
42+ {
43+ Name : "empty scheduler" ,
44+ Err : true ,
45+ Spec : `""` ,
46+ },
47+ {
48+ Name : "bad scheduler" ,
49+ Err : true ,
50+ Spec : `"bad"` ,
51+ },
52+ {
53+ Name : "bad scheduler type" ,
54+ Err : true ,
55+ Spec : `123` ,
56+ },
57+ {
58+ Name : "null scheduler type" ,
59+ Err : true ,
60+ Spec : `null` ,
61+ },
62+ } {
63+ t .Run (tc .Name , func (t * testing.T ) {
64+ var val any
65+ err := json .Unmarshal ([]byte (tc .Spec ), & val )
66+ require .NoError (t , err )
67+ if tc .Err {
68+ require .Error (t , validator .Validate (val ))
69+ } else {
70+ require .NoError (t , validator .Validate (val ))
71+ }
72+ })
73+ }
2274}
0 commit comments