Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NOTES.txt check #430

Merged
merged 3 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
18 changes: 18 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.txt"
NotesDoesNotExist = "Chart does not contain NOTES.txt"
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,22 @@ 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 {
if f.Name == "templates/NOTES.txt" {
r.SetResult(true, NotesExist)
komish marked this conversation as resolved.
Show resolved Hide resolved
}
}

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
3 changes: 2 additions & 1 deletion internal/chartverifier/profiles/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const (
CheckVersion10 = "v1.0"
CheckVersion11 = "v1.1"
DefaultProfile = "partner"
DefaultProfileVersion = "v1.2"
DefaultProfileVersion = "v1.3"
)

func getDefaultProfile(msg string) *Profile {
Expand Down 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.OptionalCheckType},
}

return &profile
Expand Down
19 changes: 10 additions & 9 deletions internal/chartverifier/profiles/profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
configVersion10 string = "v1.0"
configVersion11 string = "v1.1"
configVersion12 string = "v1.2"
configVersion13 string = "v1.3"
checkVersion10 string = CheckVersion10
checkVersion11 string = "v1.1"
NoVendorType VendorType = ""
Expand All @@ -33,7 +34,7 @@ const (

func TestProfile(t *testing.T) {
testProfile := getDefaultProfile("test")
testProfile.Name = "profile-partner-1.2"
testProfile.Name = "profile-partner-1.3"
config := make(map[string]interface{})
config[VendorTypeConfigName] = PartnerVendorType

Expand Down Expand Up @@ -77,14 +78,14 @@ func TestGetProfiles(t *testing.T) {
getAndCheckProfile(t, RedhatVendorType, RedhatVendorType, configVersion11, configVersion11)
getAndCheckProfile(t, CommunityVendorType, CommunityVendorType, configVersion11, configVersion11)
getAndCheckProfile(t, NoVendorType, PartnerVendorType, configVersion11, configVersion11)
getAndCheckProfile(t, RedhatVendorType, RedhatVendorType, NoVersion, configVersion12)
getAndCheckProfile(t, NoVendorType, PartnerVendorType, NoVersion, configVersion12)
getAndCheckProfile(t, PartnerVendorType, PartnerVendorType, configVersion12, configVersion12)
getAndCheckProfile(t, PartnerVendorType, PartnerVendorType, configVersion00, configVersion12)
getAndCheckProfile(t, RedhatVendorType, RedhatVendorType, configVersion12, configVersion12)
getAndCheckProfile(t, RedhatVendorType, RedhatVendorType, configVersion00, configVersion12)
getAndCheckProfile(t, CommunityVendorType, CommunityVendorType, configVersion00, configVersion12)
getAndCheckProfile(t, CommunityVendorType, CommunityVendorType, configVersion12, configVersion12)
getAndCheckProfile(t, RedhatVendorType, RedhatVendorType, NoVersion, configVersion13)
getAndCheckProfile(t, NoVendorType, PartnerVendorType, NoVersion, configVersion13)
getAndCheckProfile(t, PartnerVendorType, PartnerVendorType, configVersion13, configVersion13)
getAndCheckProfile(t, PartnerVendorType, PartnerVendorType, configVersion00, configVersion13)
getAndCheckProfile(t, RedhatVendorType, RedhatVendorType, configVersion13, configVersion13)
getAndCheckProfile(t, RedhatVendorType, RedhatVendorType, configVersion00, configVersion13)
getAndCheckProfile(t, CommunityVendorType, CommunityVendorType, configVersion00, configVersion13)
getAndCheckProfile(t, CommunityVendorType, CommunityVendorType, configVersion13, configVersion13)
}

func getAndCheckProfile(t *testing.T, configVendorType, expectVendorType VendorType, configVersion, expectVersion string) {
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
38 changes: 38 additions & 0 deletions internal/profileconfig/profiles/profile-community-1.3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apiversion: v1
kind: verifier-profile
vendorType: community
version: v1.3
annotations:
- "Digest"
- "TestedOpenShiftVersion"
- "LastCertifiedTimestamp"
- "SupportedOpenShiftVersions"
checks:
- name: v1.0/has-readme
type: Optional
- name: v1.0/is-helm-v3
type: Optional
- name: v1.0/contains-test
type: Optional
- name: v1.0/contains-values
type: Optional
- name: v1.0/contains-values-schema
type: Optional
- name: v1.1/has-kubeversion
type: Optional
- name: v1.0/not-contains-crds
type: Optional
- name: v1.0/helm-lint
type: Mandatory
- name: v1.0/not-contain-csi-objects
type: Optional
- name: v1.1/images-are-certified
type: Optional
- name: v1.0/chart-testing
type: Optional
- name: v1.0/required-annotations-present
type: Optional
- name: v1.0/signature-is-valid
type: Optional
- name: v1.0/has-notes
type: Optional
39 changes: 39 additions & 0 deletions internal/profileconfig/profiles/profile-partner-1.3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apiversion: v1
kind: verifier-profile
vendorType: partner
version: v1.3
annotations:
- "Digest"
- "TestedOpenShiftVersion"
- "LastCertifiedTimestamp"
- "SupportedOpenShiftVersions"
checks:
- name: v1.0/has-readme
type: Mandatory
- name: v1.0/is-helm-v3
type: Mandatory
- name: v1.0/contains-test
type: Mandatory
- name: v1.0/contains-values
type: Mandatory
- name: v1.0/contains-values-schema
type: Mandatory
- name: v1.1/has-kubeversion
type: Mandatory
- name: v1.0/not-contains-crds
type: Mandatory
- name: v1.0/helm-lint
type: Mandatory
- name: v1.0/not-contain-csi-objects
type: Mandatory
- name: v1.1/images-are-certified
type: Mandatory
- name: v1.0/chart-testing
type: Mandatory
- name: v1.0/required-annotations-present
type: Mandatory
- name: v1.0/signature-is-valid
type: Mandatory
- name: v1.0/has-notes
type: Optional

38 changes: 38 additions & 0 deletions internal/profileconfig/profiles/profile-redhat-1.3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apiversion: v1
kind: verifier-profile
vendorType: redhat
version: v1.3
annotations:
- "Digest"
- "TestedOpenShiftVersion"
- "LastCertifiedTimestamp"
- "SupportedOpenShiftVersions"
checks:
- name: v1.0/has-readme
type: Mandatory
- name: v1.0/is-helm-v3
type: Mandatory
- name: v1.0/contains-test
type: Mandatory
- name: v1.0/contains-values
type: Mandatory
- name: v1.0/contains-values-schema
type: Mandatory
- name: v1.1/has-kubeversion
type: Mandatory
- name: v1.0/not-contains-crds
type: Mandatory
- name: v1.0/helm-lint
type: Mandatory
- name: v1.0/not-contain-csi-objects
type: Mandatory
- name: v1.1/images-are-certified
type: Mandatory
- name: v1.0/chart-testing
type: Mandatory
- name: v1.0/required-annotations-present
type: Mandatory
- name: v1.0/signature-is-valid
type: Mandatory
- name: v1.0/has-notes
type: Optional
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"metadata": {
"vendorType": "community",
"profileVersion": "v1.2",
"profileVersion": "v1.3",
"webCatalogOnly": false,
"chart-uri": "psql-service-0.1.11.tgz",
"chart": {
Expand Down
2 changes: 1 addition & 1 deletion tests/charts/psql-service/0.1.11/partner-report-info.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"metadata": {
"vendorType": "partner",
"profileVersion": "v1.2",
"profileVersion": "v1.3",
"webCatalogOnly": false,
"chart-uri": "psql-service-0.1.11.tgz",
"chart": {
Expand Down
2 changes: 1 addition & 1 deletion tests/charts/psql-service/0.1.11/redhat-report-info.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"metadata": {
"vendorType": "redhat",
"profileVersion": "v1.2",
"profileVersion": "v1.3",
"webCatalogOnly": false,
"chart-uri": "psql-service-0.1.11.tgz",
"chart": {
Expand Down
2 changes: 1 addition & 1 deletion tests/charts/psql-service/0.1.8/community-report-info.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"metadata": {
"vendorType": "community",
"profileVersion": "v1.2",
"profileVersion": "v1.3",
"webCatalogOnly": false,
"chart-uri": "/charts/src",
"chart": {
Expand Down
2 changes: 1 addition & 1 deletion tests/charts/psql-service/0.1.8/partner-report-info.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"metadata": {
"vendorType": "partner",
"profileVersion": "v1.2",
"profileVersion": "v1.3",
"webCatalogOnly": false,
"chart-uri": "/charts/src",
"chart": {
Expand Down
2 changes: 1 addition & 1 deletion tests/charts/psql-service/0.1.8/redhat-report-info.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"metadata": {
"vendorType": "redhat",
"profileVersion": "v1.2",
"profileVersion": "v1.3",
"webCatalogOnly": false,
"chart-uri": "/charts/src",
"chart": {
Expand Down
2 changes: 1 addition & 1 deletion tests/charts/psql-service/0.1.9/community-report-info.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"metadata": {
"vendorType": "community",
"profileVersion": "v1.2",
"profileVersion": "v1.3",
"webCatalogOnly": false,
"chart-uri": "psql-service-0.1.9.tgz",
"chart": {
Expand Down
2 changes: 1 addition & 1 deletion tests/charts/psql-service/0.1.9/partner-report-info.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"metadata": {
"vendorType": "partner",
"profileVersion": "v1.2",
"profileVersion": "v1.3",
"webCatalogOnly": false,
"chart-uri": "psql-service-0.1.9.tgz",
"chart": {
Expand Down
2 changes: 1 addition & 1 deletion tests/charts/psql-service/0.1.9/redhat-report-info.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"metadata": {
"vendorType": "redhat",
"profileVersion": "v1.2",
"profileVersion": "v1.3",
"webCatalogOnly": false,
"chart-uri": "psql-service-0.1.9.tgz",
"chart": {
Expand Down
Loading