@@ -19,12 +19,11 @@ import (
19
19
"strings"
20
20
"testing"
21
21
22
- "github.com/pkg/errors"
23
-
24
- "github.com/helm/chart-testing/pkg/util"
25
-
26
22
"github.com/helm/chart-testing/pkg/config"
23
+ "github.com/helm/chart-testing/pkg/util"
24
+ "github.com/pkg/errors"
27
25
"github.com/stretchr/testify/assert"
26
+ "github.com/stretchr/testify/mock"
28
27
)
29
28
30
29
type fakeGit struct {}
@@ -94,10 +93,18 @@ func (v fakeAccountValidator) Validate(repoDomain string, account string) error
94
93
return errors .New (fmt .Sprintf ("Error validating account: %s" , account ))
95
94
}
96
95
97
- type fakeLinter struct {}
96
+ type fakeLinter struct {
97
+ mock.Mock
98
+ }
98
99
99
- func (l fakeLinter ) YamlLint (yamlFile , configFile string ) error { return nil }
100
- func (l fakeLinter ) Yamale (yamlFile , schemaFile string ) error { return nil }
100
+ func (l * fakeLinter ) YamlLint (yamlFile , configFile string ) error {
101
+ l .Called (yamlFile , configFile )
102
+ return nil
103
+ }
104
+ func (l * fakeLinter ) Yamale (yamlFile , schemaFile string ) error {
105
+ l .Called (yamlFile , schemaFile )
106
+ return nil
107
+ }
101
108
102
109
type fakeHelm struct {}
103
110
@@ -120,13 +127,16 @@ func init() {
120
127
ExcludedCharts : []string {"excluded" },
121
128
ChartDirs : []string {"stable" , "incubator" },
122
129
}
130
+
131
+ fakeMockLinter := new (fakeLinter )
132
+
123
133
ct = Testing {
124
134
config : cfg ,
125
135
directoryLister : fakeDirLister {},
126
136
git : fakeGit {},
127
137
chartUtils : fakeChartUtils {},
128
138
accountValidator : fakeAccountValidator {},
129
- linter : fakeLinter {} ,
139
+ linter : fakeMockLinter ,
130
140
helm : fakeHelm {},
131
141
}
132
142
}
@@ -200,3 +210,90 @@ func TestLintChartMaintainerValidation(t *testing.T) {
200
210
runTests (true )
201
211
runTests (false )
202
212
}
213
+
214
+ func TestLintChartSchemaValidation (t * testing.T ) {
215
+ type testData struct {
216
+ name string
217
+ chartDir string
218
+ expected bool
219
+ }
220
+
221
+ runTests := func (validate bool , callsYamlLint int , callsYamale int ) {
222
+ fakeMockLinter := new (fakeLinter )
223
+
224
+ fakeMockLinter .On ("Yamale" , mock .Anything , mock .Anything ).Return (true )
225
+ fakeMockLinter .On ("YamlLint" , mock .Anything , mock .Anything ).Return (true )
226
+
227
+ ct .linter = fakeMockLinter
228
+ ct .config .ValidateChartSchema = validate
229
+ ct .config .ValidateMaintainers = false
230
+ ct .config .ValidateYaml = false
231
+
232
+ var suffix string
233
+ if validate {
234
+ suffix = "with-validation"
235
+ } else {
236
+ suffix = "without-validation"
237
+ }
238
+
239
+ testCases := []testData {
240
+ {fmt .Sprintf ("schema-%s" , suffix ), "testdata/test_lints" , true },
241
+ }
242
+
243
+ for _ , testData := range testCases {
244
+ t .Run (testData .name , func (t * testing.T ) {
245
+ result := ct .LintChart (testData .chartDir , []string {})
246
+ assert .Equal (t , testData .expected , result .Error == nil )
247
+ fakeMockLinter .AssertNumberOfCalls (t , "Yamale" , callsYamale )
248
+ fakeMockLinter .AssertNumberOfCalls (t , "YamlLint" , callsYamlLint )
249
+ })
250
+ }
251
+ }
252
+
253
+ runTests (true , 0 , 1 )
254
+ runTests (false , 0 , 0 )
255
+
256
+ }
257
+
258
+ func TestLintYamlValidation (t * testing.T ) {
259
+ type testData struct {
260
+ name string
261
+ chartDir string
262
+ expected bool
263
+ }
264
+
265
+ runTests := func (validate bool , callsYamlLint int , callsYamale int ) {
266
+ fakeMockLinter := new (fakeLinter )
267
+
268
+ fakeMockLinter .On ("Yamale" , mock .Anything , mock .Anything ).Return (true )
269
+ fakeMockLinter .On ("YamlLint" , mock .Anything , mock .Anything ).Return (true )
270
+
271
+ ct .linter = fakeMockLinter
272
+ ct .config .ValidateYaml = validate
273
+ ct .config .ValidateChartSchema = false
274
+ ct .config .ValidateMaintainers = false
275
+
276
+ var suffix string
277
+ if validate {
278
+ suffix = "with-validation"
279
+ } else {
280
+ suffix = "without-validation"
281
+ }
282
+
283
+ testCases := []testData {
284
+ {fmt .Sprintf ("lint-%s" , suffix ), "testdata/test_lints" , true },
285
+ }
286
+
287
+ for _ , testData := range testCases {
288
+ t .Run (testData .name , func (t * testing.T ) {
289
+ result := ct .LintChart (testData .chartDir , []string {})
290
+ assert .Equal (t , testData .expected , result .Error == nil )
291
+ fakeMockLinter .AssertNumberOfCalls (t , "Yamale" , callsYamale )
292
+ fakeMockLinter .AssertNumberOfCalls (t , "YamlLint" , callsYamlLint )
293
+ })
294
+ }
295
+ }
296
+
297
+ runTests (true , 2 , 0 )
298
+ runTests (false , 0 , 0 )
299
+ }
0 commit comments