diff --git a/app/cmd/lint.go b/app/cmd/lint.go index c52c77fc..c9b253c2 100644 --- a/app/cmd/lint.go +++ b/app/cmd/lint.go @@ -19,7 +19,6 @@ import ( "os" "github.com/MakeNowJust/heredoc" - "github.com/helm/chart-testing/pkg/chart" "github.com/helm/chart-testing/pkg/config" "github.com/spf13/cobra" @@ -65,13 +64,13 @@ func addLintFlags(flags *flag.FlagSet) { is searched in the current directory, '$HOME/.ct', and '/etc/ct', in that order.`)) flags.Bool("validate-maintainers", true, heredoc.Doc(` - Enabled validation of maintainer account names in chart.yml (default: true). + Enable validation of maintainer account names in chart.yml (default: true). Works for GitHub, GitLab, and Bitbucket`)) flags.Bool("check-version-increment", true, "Activates a check for chart version increments (default: true)") flags.Bool("validate-chart-schema", true, heredoc.Doc(` - Enabled validation of the schema (default: true)`)) + Enable schema validation of 'Chart.yaml' using Yamale (default: true)`)) flags.Bool("validate-yaml", true, heredoc.Doc(` - Enabled validation to lint the yaml files (default: true)`)) + Enable linting of 'Chart.yaml' and values files (default: true)`)) } func lint(cmd *cobra.Command, args []string) { diff --git a/doc/ct_lint-and-install.md b/doc/ct_lint-and-install.md index cdac57f2..ececce63 100644 --- a/doc/ct_lint-and-install.md +++ b/doc/ct_lint-and-install.md @@ -46,10 +46,10 @@ ct lint-and-install [flags] This is only used if namespace is specified. (default "app.kubernetes.io/instance") --remote string The name of the Git remote used to identify changed charts (default "origin") --target-branch string The name of the target branch used to identify changed charts (default "master") - --validate-chart-schema Enabled validation of the schema (default: true) (default true) - --validate-maintainers Enabled validation of maintainer account names in chart.yml (default: true). + --validate-chart-schema Enable schema validation of 'Chart.yaml' using Yamale (default: true) (default true) + --validate-maintainers Enable validation of maintainer account names in chart.yml (default: true). Works for GitHub, GitLab, and Bitbucket (default true) - --validate-yaml Enabled validation to lint the yaml files (default: true) (default true) + --validate-yaml Enable linting of 'Chart.yaml' and values files (default: true) (default true) ``` ### SEE ALSO diff --git a/doc/ct_lint.md b/doc/ct_lint.md index 3e629725..97d71532 100644 --- a/doc/ct_lint.md +++ b/doc/ct_lint.md @@ -50,10 +50,10 @@ ct lint [flags] that order --remote string The name of the Git remote used to identify changed charts (default "origin") --target-branch string The name of the target branch used to identify changed charts (default "master") - --validate-chart-schema Enabled validation of the schema (default: true) (default true) - --validate-maintainers Enabled validation of maintainer account names in chart.yml (default: true). + --validate-chart-schema Enable schema validation of 'Chart.yaml' using Yamale (default: true) (default true) + --validate-maintainers Enable validation of maintainer account names in chart.yml (default: true). Works for GitHub, GitLab, and Bitbucket (default true) - --validate-yaml Enabled validation to lint the yaml files (default: true) (default true) + --validate-yaml Enable linting of 'Chart.yaml' and values files (default: true) (default true) ``` ### SEE ALSO diff --git a/pkg/chart/chart_test.go b/pkg/chart/chart_test.go index 2b7e997f..519f5475 100644 --- a/pkg/chart/chart_test.go +++ b/pkg/chart/chart_test.go @@ -19,11 +19,9 @@ import ( "strings" "testing" - "github.com/pkg/errors" - - "github.com/helm/chart-testing/pkg/util" - "github.com/helm/chart-testing/pkg/config" + "github.com/helm/chart-testing/pkg/util" + "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) @@ -95,20 +93,15 @@ func (v fakeAccountValidator) Validate(repoDomain string, account string) error return errors.New(fmt.Sprintf("Error validating account: %s", account)) } -type fakeLinter struct{} - -func (l fakeLinter) YamlLint(yamlFile, configFile string) error { return nil } -func (l fakeLinter) Yamale(yamlFile, schemaFile string) error { return nil } - -type fakeLinter2 struct { +type fakeLinter struct { mock.Mock } -func (l *fakeLinter2) YamlLint(yamlFile, configFile string) error { +func (l *fakeLinter) YamlLint(yamlFile, configFile string) error { l.Called(yamlFile, configFile) return nil } -func (l *fakeLinter2) Yamale(yamlFile, schemaFile string) error { +func (l *fakeLinter) Yamale(yamlFile, schemaFile string) error { l.Called(yamlFile, schemaFile) return nil } @@ -134,13 +127,16 @@ func init() { ExcludedCharts: []string{"excluded"}, ChartDirs: []string{"stable", "incubator"}, } + + fakeMockLinter := new(fakeLinter) + ct = Testing{ config: cfg, directoryLister: fakeDirLister{}, git: fakeGit{}, chartUtils: fakeChartUtils{}, accountValidator: fakeAccountValidator{}, - linter: fakeLinter{}, + linter: fakeMockLinter, helm: fakeHelm{}, } } @@ -222,8 +218,8 @@ func TestLintChartSchemaValidation(t *testing.T) { expected bool } - runTests := func(validate bool, callsYamlLint, callsYamale int) { - var fakeMockLinter = new(fakeLinter2) + runTests := func(validate bool, callsYamlLint int, callsYamale int) { + fakeMockLinter := new(fakeLinter) fakeMockLinter.On("Yamale", mock.Anything, mock.Anything).Return(true) fakeMockLinter.On("YamlLint", mock.Anything, mock.Anything).Return(true) @@ -266,9 +262,8 @@ func TestLintYamlValidation(t *testing.T) { expected bool } - runTests := func(validate bool, callsYamlLint, callsYamale int) { - - var fakeMockLinter = new(fakeLinter2) + runTests := func(validate bool, callsYamlLint int, callsYamale int) { + fakeMockLinter := new(fakeLinter) fakeMockLinter.On("Yamale", mock.Anything, mock.Anything).Return(true) fakeMockLinter.On("YamlLint", mock.Anything, mock.Anything).Return(true)