@@ -13,7 +13,9 @@ import (
1313
1414func  TestValidateBlankInput (t  * testing.T ) {
1515	blank  :=  []byte ("" )
16- 	_ , err  :=  Validate (blank , "sample" )
16+ 	config  :=  NewDefaultConfig ()
17+ 	config .FileName  =  "blank" 
18+ 	_ , err  :=  Validate (blank , config )
1719	if  err  !=  nil  {
1820		t .Errorf ("Validate should pass when passed a blank string" )
1921	}
@@ -36,7 +38,9 @@ func TestValidateValidInputs(t *testing.T) {
3638	for  _ , test  :=  range  tests  {
3739		filePath , _  :=  filepath .Abs ("../fixtures/"  +  test )
3840		fileContents , _  :=  ioutil .ReadFile (filePath )
39- 		_ , err  :=  Validate (fileContents , test )
41+ 		config  :=  NewDefaultConfig ()
42+ 		config .FileName  =  test 
43+ 		_ , err  :=  Validate (fileContents , config )
4044		if  err  !=  nil  {
4145			t .Errorf ("Validate should pass when testing valid configuration in "  +  test )
4246		}
@@ -62,7 +66,9 @@ func TestValidateValidInputsWithCache(t *testing.T) {
6266	for  _ , test  :=  range  tests  {
6367		filePath , _  :=  filepath .Abs ("../fixtures/"  +  test )
6468		fileContents , _  :=  ioutil .ReadFile (filePath )
65- 		_ , err  :=  ValidateWithCache (fileContents , test , schemaCache )
69+ 		config  :=  NewDefaultConfig ()
70+ 		config .FileName  =  test 
71+ 		_ , err  :=  ValidateWithCache (fileContents , schemaCache , config )
6672		if  err  !=  nil  {
6773			t .Errorf ("Validate should pass when testing valid configuration in "  +  test )
6874		}
@@ -77,7 +83,9 @@ func TestValidateInvalidInputs(t *testing.T) {
7783	for  _ , test  :=  range  tests  {
7884		filePath , _  :=  filepath .Abs ("../fixtures/"  +  test )
7985		fileContents , _  :=  ioutil .ReadFile (filePath )
80- 		_ , err  :=  Validate (fileContents , test )
86+ 		config  :=  NewDefaultConfig ()
87+ 		config .FileName  =  test 
88+ 		_ , err  :=  Validate (fileContents , config )
8189		if  err  ==  nil  {
8290			t .Errorf ("Validate should not pass when testing invalid configuration in "  +  test )
8391		}
@@ -97,7 +105,9 @@ func TestValidateSourceExtraction(t *testing.T) {
97105	}
98106	filePath , _  :=  filepath .Abs ("../fixtures/multi_valid_source.yaml" )
99107	fileContents , _  :=  ioutil .ReadFile (filePath )
100- 	results , err  :=  Validate (fileContents , "multi_valid_source.yaml" )
108+ 	config  :=  NewDefaultConfig ()
109+ 	config .FileName  =  "multi_valid_source.yaml" 
110+ 	results , err  :=  Validate (fileContents , config )
101111	if  err  !=  nil  {
102112		t .Fatalf ("Unexpected error while validating source: %v" , err )
103113	}
@@ -111,9 +121,10 @@ func TestValidateSourceExtraction(t *testing.T) {
111121func  TestStrictCatchesAdditionalErrors (t  * testing.T ) {
112122	config  :=  NewDefaultConfig ()
113123	config .Strict  =  true 
124+ 	config .FileName  =  "extra_property.yaml" 
114125	filePath , _  :=  filepath .Abs ("../fixtures/extra_property.yaml" )
115126	fileContents , _  :=  ioutil .ReadFile (filePath )
116- 	results , _  :=  Validate (fileContents , "extra_property.yaml" ,  config )
127+ 	results , _  :=  Validate (fileContents , config )
117128	if  len (results [0 ].Errors ) ==  0  {
118129		t .Errorf ("Validate should not pass when testing for additional properties not in schema" )
119130	}
@@ -122,10 +133,11 @@ func TestStrictCatchesAdditionalErrors(t *testing.T) {
122133func  TestValidateMultipleVersions (t  * testing.T ) {
123134	config  :=  NewDefaultConfig ()
124135	config .Strict  =  true 
136+ 	config .FileName  =  "valid_version.yaml" 
125137	config .KubernetesVersion  =  "1.14.0" 
126138	filePath , _  :=  filepath .Abs ("../fixtures/valid_version.yaml" )
127139	fileContents , _  :=  ioutil .ReadFile (filePath )
128- 	results , err  :=  Validate (fileContents , "valid_version.yaml" ,  config )
140+ 	results , err  :=  Validate (fileContents , config )
129141	if  err  !=  nil  ||  len (results [0 ].Errors ) >  0  {
130142		t .Errorf ("Validate should pass when testing valid configuration with multiple versions: %v" , err )
131143	}
@@ -139,7 +151,9 @@ func TestValidateInputsWithErrors(t *testing.T) {
139151	for  _ , test  :=  range  tests  {
140152		filePath , _  :=  filepath .Abs ("../fixtures/"  +  test )
141153		fileContents , _  :=  ioutil .ReadFile (filePath )
142- 		results , _  :=  Validate (fileContents , test )
154+ 		config  :=  NewDefaultConfig ()
155+ 		config .FileName  =  test 
156+ 		results , _  :=  Validate (fileContents , config )
143157		if  len (results [0 ].Errors ) ==  0  {
144158			t .Errorf ("Validate should not pass when testing invalid configuration in "  +  test )
145159		}
@@ -155,7 +169,8 @@ func TestValidateMultipleResourcesWithErrors(t *testing.T) {
155169		filePath , _  :=  filepath .Abs ("../fixtures/"  +  test )
156170		fileContents , _  :=  ioutil .ReadFile (filePath )
157171		config .ExitOnError  =  true 
158- 		_ , err  :=  Validate (fileContents , test , config )
172+ 		config .FileName  =  test 
173+ 		_ , err  :=  Validate (fileContents , config )
159174		if  err  ==  nil  {
160175			t .Errorf ("Validate should not pass when testing invalid configuration in "  +  test )
161176		} else  if  merr , ok  :=  err .(* multierror.Error ); ok  {
@@ -164,7 +179,7 @@ func TestValidateMultipleResourcesWithErrors(t *testing.T) {
164179			}
165180		}
166181		config .ExitOnError  =  false 
167- 		_ , err  =  Validate (fileContents , test ,  config )
182+ 		_ , err  =  Validate (fileContents , config )
168183		if  err  ==  nil  {
169184			t .Errorf ("Validate should not pass when testing invalid configuration in "  +  test )
170185		} else  if  merr , ok  :=  err .(* multierror.Error ); ok  {
@@ -284,23 +299,24 @@ func TestGetString(t *testing.T) {
284299}
285300
286301func  TestSkipCrdSchemaMiss (t  * testing.T ) {
302+ 	config  :=  NewDefaultConfig ()
303+ 	config .FileName  =  "test_crd.yaml" 
287304	filePath , _  :=  filepath .Abs ("../fixtures/test_crd.yaml" )
288305	fileContents , _  :=  ioutil .ReadFile (filePath )
289- 	_ , err  :=  Validate (fileContents ,  "test_crd.yaml" )
306+ 	_ , err  :=  Validate (fileContents )
290307	if  err  ==  nil  {
291308		t .Errorf ("For custom CRD's with schema missing we should error without IgnoreMissingSchemas flag" )
292309	}
293310
294- 	config  :=  NewDefaultConfig ()
295311	config .IgnoreMissingSchemas  =  true 
296- 	results , _  :=  Validate (fileContents , "test_crd.yaml" ,  config )
312+ 	results , _  :=  Validate (fileContents , config )
297313	if  len (results [0 ].Errors ) !=  0  {
298314		t .Errorf ("For custom CRD's with schema missing we should skip with IgnoreMissingSchemas flag" )
299315	}
300316
301317	config .IgnoreMissingSchemas  =  false 
302318	config .KindsToSkip  =  []string {"SealedSecret" }
303- 	results , _  =  Validate (fileContents , "test_crd.yaml" ,  config )
319+ 	results , _  =  Validate (fileContents , config )
304320	if  len (results [0 ].Errors ) !=  0  {
305321		t .Errorf ("We should skip resources listed in KindsToSkip" )
306322	}
0 commit comments