66 "path/filepath"
77 "testing"
88
9- "gopkg.in /yaml.v3 "
9+ "sigs.k8s.io /yaml"
1010)
1111
1212// loadFile reads a test JSON file from the project root testdata directory.
@@ -45,7 +45,7 @@ func TestValidImage(t *testing.T) {
4545 t .Errorf ("yml parsing error: %v" , err )
4646 }
4747
48- // 3) Re‐marshal to JSON bytes
48+ // Re‐marshal to JSON bytes
4949 dataJSON , err := json .Marshal (raw )
5050 if err != nil {
5151 t .Errorf ("json marshaling error: %v" , err )
@@ -64,7 +64,7 @@ func TestInvalidImage(t *testing.T) {
6464 t .Errorf ("yml parsing error: %v" , err )
6565 }
6666
67- // 3) Re‐marshal to JSON bytes
67+ // Re‐marshal to JSON bytes
6868 dataJSON , err := json .Marshal (raw )
6969 if err != nil {
7070 t .Errorf ("json marshaling error: %v" , err )
@@ -73,3 +73,42 @@ func TestInvalidImage(t *testing.T) {
7373 t .Errorf ("expected testdata/invalid-image.yml to pass, but got: %v" , err )
7474 }
7575}
76+
77+ func TestValidConfig (t * testing.T ) {
78+ v := loadFile (t , "testdata/valid-config.yml" )
79+
80+ if v == nil {
81+ t .Fatal ("failed to load testdata/valid-config.yml" )
82+ }
83+ dataJSON , err := yaml .YAMLToJSON (v )
84+
85+ if err != nil {
86+ t .Fatalf ("YAML→JSON conversion failed: %v" , err )
87+ }
88+ if err := ValidateConfigJSON (dataJSON ); err != nil {
89+ t .Errorf ("validation failed: %v" , err )
90+ }
91+ }
92+
93+ func TestInvalidConfig (t * testing.T ) {
94+ v := loadFile (t , "testdata/invalid-config.yml" )
95+
96+ // Parse to generic JSON interface
97+ var raw interface {}
98+ if err := yaml .Unmarshal (v , & raw ); err != nil {
99+ t .Errorf ("yml parsing error: %v" , err )
100+ }
101+
102+ // Re‐marshal to JSON bytes
103+ dataJSON , err := yaml .YAMLToJSON (v )
104+ if err != nil {
105+ t .Errorf ("json marshaling error: %v" , err )
106+ }
107+
108+ if err := ValidateConfigJSON (dataJSON ); err == nil {
109+ t .Errorf ("expected invalid-config.json to fail validation: %v" , err )
110+ } else {
111+ t .Logf ("expected validation error: %v" , err )
112+ }
113+
114+ }
0 commit comments