diff --git a/internal/chartverifier/checks/chart-0.1.0-v3.without-notes.tgz b/internal/chartverifier/checks/chart-0.1.0-v3.without-notes.tgz new file mode 100644 index 00000000..a9867dbd Binary files /dev/null and b/internal/chartverifier/checks/chart-0.1.0-v3.without-notes.tgz differ diff --git a/internal/chartverifier/checks/checks.go b/internal/chartverifier/checks/checks.go index efef631a..887a3203 100644 --- a/internal/chartverifier/checks/checks.go +++ b/internal/chartverifier/checks/checks.go @@ -39,6 +39,8 @@ const ( APIVersion2 = "v2" ReadmeExist = "Chart has a README" ReadmeDoesNotExist = "Chart does not have a README" + NotesExist = "Chart does contain NOTES" + NotesDoesNotExist = "Chart does not contain NOTES" NotHelm3Reason = "API version is not V2, used in Helm 3" Helm3Reason = "API version is V2, used in Helm 3" TestTemplatePrefix = "templates/tests/" @@ -111,6 +113,23 @@ func HasReadme(opts *CheckOptions) (Result, error) { return r, nil } +func HasNotes(opts *CheckOptions) (Result, error) { + c, _, err := LoadChartFromURI(opts) + if err != nil { + return Result{}, err + } + + r := NewResult(false, NotesDoesNotExist) + for _, f := range c.Templates { + fmt.Println(f.Name) + if f.Name == "templates/NOTES.txt" { + r.SetResult(true, NotesExist) + } + } + + return r, nil +} + func ContainsTest(opts *CheckOptions) (Result, error) { c, _, err := LoadChartFromURI(opts) if err != nil { diff --git a/internal/chartverifier/checks/checks_test.go b/internal/chartverifier/checks/checks_test.go index 135184b8..73d52129 100644 --- a/internal/chartverifier/checks/checks_test.go +++ b/internal/chartverifier/checks/checks_test.go @@ -105,6 +105,43 @@ func TestHasReadme(t *testing.T) { } } +func TestHasNotes(t *testing.T) { + type testCase struct { + description string + uri string + } + + positiveTestCases := []testCase{ + {description: "chart with NOTES.txt", uri: "chart-0.1.0-v3.valid.tgz"}, + } + + for _, tc := range positiveTestCases { + t.Run(tc.description, func(t *testing.T) { + config := viper.New() + r, err := HasNotes(&CheckOptions{URI: tc.uri, ViperConfig: config, HelmEnvSettings: cli.New()}) + require.NoError(t, err) + require.NotNil(t, r) + require.True(t, r.Ok) + require.Equal(t, NotesExist, r.Reason) + }) + } + + negativeTestCases := []testCase{ + {description: "chart without NOTES.txt", uri: "chart-0.1.0-v3.without-notes.tgz"}, + } + + for _, tc := range negativeTestCases { + t.Run(tc.description, func(t *testing.T) { + config := viper.New() + r, err := HasNotes(&CheckOptions{URI: tc.uri, ViperConfig: config, HelmEnvSettings: cli.New()}) + require.NoError(t, err) + require.NotNil(t, r) + require.False(t, r.Ok) + require.Equal(t, NotesDoesNotExist, r.Reason) + }) + } +} + func TestContainsTest(t *testing.T) { type testCase struct { description string diff --git a/internal/chartverifier/profiles/default.go b/internal/chartverifier/profiles/default.go index 774d9369..6687bf1a 100644 --- a/internal/chartverifier/profiles/default.go +++ b/internal/chartverifier/profiles/default.go @@ -43,6 +43,7 @@ func getDefaultProfile(msg string) *Profile { {Name: fmt.Sprintf("%s/%s", CheckVersion10, apiChecks.ChartTesting), Type: apiChecks.MandatoryCheckType}, {Name: fmt.Sprintf("%s/%s", CheckVersion10, apiChecks.RequiredAnnotationsPresent), Type: apiChecks.MandatoryCheckType}, {Name: fmt.Sprintf("%s/%s", CheckVersion10, apiChecks.SignatureIsValid), Type: apiChecks.MandatoryCheckType}, + {Name: fmt.Sprintf("%s/%s", CheckVersion10, apiChecks.HasNotes), Type: apiChecks.MandatoryCheckType}, } return &profile diff --git a/internal/chartverifier/verifierbuilder.go b/internal/chartverifier/verifierbuilder.go index 19f5f23b..b09ca3e3 100644 --- a/internal/chartverifier/verifierbuilder.go +++ b/internal/chartverifier/verifierbuilder.go @@ -50,6 +50,7 @@ func init() { defaultRegistry.Add(apiChecks.ChartTesting, "v1.0", checks.ChartTesting) defaultRegistry.Add(apiChecks.RequiredAnnotationsPresent, "v1.0", checks.RequiredAnnotationsPresent) defaultRegistry.Add(apiChecks.SignatureIsValid, "v1.0", checks.SignatureIsValid) + defaultRegistry.Add(apiChecks.HasNotes, "v1.0", checks.HasNotes) } func DefaultRegistry() checks.Registry { diff --git a/pkg/chartverifier/checks/checks.go b/pkg/chartverifier/checks/checks.go index ed15d96f..9023aa94 100644 --- a/pkg/chartverifier/checks/checks.go +++ b/pkg/chartverifier/checks/checks.go @@ -14,6 +14,7 @@ const ( ChartTesting CheckName = "chart-testing" RequiredAnnotationsPresent CheckName = "required-annotations-present" SignatureIsValid CheckName = "signature-is-valid" + HasNotes CheckName = "has-notes" MandatoryCheckType CheckType = "Mandatory" OptionalCheckType CheckType = "Optional" ExperimentalCheckType CheckType = "Experimental" @@ -25,6 +26,7 @@ var setCheckNames = []CheckName{ ContainsValuesSchema, ContainsValues, HasKubeVersion, + HasNotes, HasReadme, HelmLint, ImagesAreCertified,