Skip to content

Commit

Permalink
Add NOTES.txt check
Browse files Browse the repository at this point in the history
Signed-off-by: Tayler Geiger <[email protected]>
  • Loading branch information
trgeiger committed Apr 1, 2024
1 parent 784ac07 commit aa1ce49
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 0 deletions.
Binary file not shown.
19 changes: 19 additions & 0 deletions internal/chartverifier/checks/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down Expand Up @@ -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 {
Expand Down
37 changes: 37 additions & 0 deletions internal/chartverifier/checks/checks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions internal/chartverifier/profiles/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions internal/chartverifier/verifierbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions pkg/chartverifier/checks/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -25,6 +26,7 @@ var setCheckNames = []CheckName{
ContainsValuesSchema,
ContainsValues,
HasKubeVersion,
HasNotes,
HasReadme,
HelmLint,
ImagesAreCertified,
Expand Down

0 comments on commit aa1ce49

Please sign in to comment.