@@ -25,6 +25,7 @@ import (
25
25
26
26
"github.com/helm/chart-testing/pkg/config"
27
27
"github.com/stretchr/testify/assert"
28
+ "github.com/stretchr/testify/mock"
28
29
)
29
30
30
31
type fakeGit struct {}
@@ -99,6 +100,19 @@ type fakeLinter struct{}
99
100
func (l fakeLinter ) YamlLint (yamlFile , configFile string ) error { return nil }
100
101
func (l fakeLinter ) Yamale (yamlFile , schemaFile string ) error { return nil }
101
102
103
+ type fakeLinter2 struct {
104
+ mock.Mock
105
+ }
106
+
107
+ func (l * fakeLinter2 ) YamlLint (yamlFile , configFile string ) error {
108
+ l .Called (yamlFile , configFile )
109
+ return nil
110
+ }
111
+ func (l * fakeLinter2 ) Yamale (yamlFile , schemaFile string ) error {
112
+ l .Called (yamlFile , schemaFile )
113
+ return nil
114
+ }
115
+
102
116
type fakeHelm struct {}
103
117
104
118
func (h fakeHelm ) Init () error { return nil }
@@ -200,3 +214,95 @@ func TestLintChartMaintainerValidation(t *testing.T) {
200
214
runTests (true )
201
215
runTests (false )
202
216
}
217
+
218
+ func TestLintNoChartSchemaValidation (t * testing.T ) {
219
+ type testData struct {
220
+ name string
221
+ chartDir string
222
+ expected bool
223
+ }
224
+
225
+ runTests := func (noValidation bool , callsYamlLint , callsYamale int ) {
226
+ var fakeMockLinter = new (fakeLinter2 )
227
+
228
+ fakeMockLinter .On ("Yamale" , mock .Anything , mock .Anything ).Return (true )
229
+ fakeMockLinter .On ("YamlLint" , mock .Anything , mock .Anything ).Return (true )
230
+
231
+ ct .linter = fakeMockLinter
232
+ ct .config .NoChartSchemaValidation = noValidation
233
+ ct .config .ValidateMaintainers = false
234
+ ct .config .NoYamlLint = false
235
+
236
+ var suffix string
237
+ if noValidation {
238
+ suffix = "without-validation"
239
+ } else {
240
+ suffix = "with-validation"
241
+ }
242
+
243
+ testCases := []testData {
244
+ {fmt .Sprintf ("schema-%s" , suffix ), "testdata/test_lints" , true },
245
+ }
246
+
247
+ for _ , testData := range testCases {
248
+ t .Run (testData .name , func (t * testing.T ) {
249
+ result := ct .LintChart (testData .chartDir , []string {})
250
+ assert .Equal (t , testData .expected , result .Error == nil )
251
+ fakeMockLinter .AssertNumberOfCalls (t , "Yamale" , callsYamale )
252
+ fakeMockLinter .AssertNumberOfCalls (t , "YamlLint" , callsYamlLint )
253
+ })
254
+ }
255
+ }
256
+
257
+ // will run the schema validation
258
+ runTests (false , 2 , 1 )
259
+ // will not run the schema validation
260
+ runTests (true , 2 , 0 )
261
+
262
+ }
263
+
264
+ func TestLintNoYamlLintValidation (t * testing.T ) {
265
+ type testData struct {
266
+ name string
267
+ chartDir string
268
+ expected bool
269
+ }
270
+
271
+ runTests := func (noValidation bool , callsYamlLint , callsYamale int ) {
272
+
273
+ var fakeMockLinter = new (fakeLinter2 )
274
+
275
+ fakeMockLinter .On ("Yamale" , mock .Anything , mock .Anything ).Return (true )
276
+ fakeMockLinter .On ("YamlLint" , mock .Anything , mock .Anything ).Return (true )
277
+
278
+ ct .linter = fakeMockLinter
279
+ ct .config .NoYamlLint = noValidation
280
+ ct .config .NoChartSchemaValidation = false
281
+ ct .config .ValidateMaintainers = false
282
+
283
+ var suffix string
284
+ if noValidation {
285
+ suffix = "without-yaml-validation"
286
+ } else {
287
+ suffix = "with-yaml-validation"
288
+ }
289
+
290
+ testCases := []testData {
291
+ {fmt .Sprintf ("lint-%s" , suffix ), "testdata/test_lints" , true },
292
+ }
293
+
294
+ for _ , testData := range testCases {
295
+ t .Run (testData .name , func (t * testing.T ) {
296
+ result := ct .LintChart (testData .chartDir , []string {})
297
+ assert .Equal (t , testData .expected , result .Error == nil )
298
+ fakeMockLinter .AssertNumberOfCalls (t , "Yamale" , callsYamale )
299
+ fakeMockLinter .AssertNumberOfCalls (t , "YamlLint" , callsYamlLint )
300
+ })
301
+ }
302
+ }
303
+
304
+ // will run the lint validation
305
+ runTests (false , 2 , 1 )
306
+ // will not run the lint validation
307
+ runTests (true , 0 , 1 )
308
+ }
0 commit comments