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

linter: add test-disabled-reason #1215

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
15 changes: 15 additions & 0 deletions pkg/lint/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,21 @@
return fmt.Errorf("auto-update is disabled but no reason is provided")
},
},
{
Name: "test-disabled-reason",
Description: "packages with test disabled should have a reason",
// TODO: Change to SeverityError when current packages are compliant.
Severity: SeverityWarning,
LintFunc: func(c config.Configuration) error {
if c.Test != nil && c.Test.Enabled {

Check failure on line 465 in pkg/lint/rules.go

View workflow job for this annotation

GitHub Actions / wolfictl text on wolfi-dev/os

c.Test.Enabled undefined (type *"chainguard.dev/melange/pkg/config".Test has no field or method Enabled)

Check failure on line 465 in pkg/lint/rules.go

View workflow job for this annotation

GitHub Actions / lint

c.Test.Enabled undefined (type *"chainguard.dev/melange/pkg/config".Test has no field or method Enabled)

Check failure on line 465 in pkg/lint/rules.go

View workflow job for this annotation

GitHub Actions / lint

c.Test.Enabled undefined (type *"chainguard.dev/melange/pkg/config".Test has no field or method Enabled)

Check failure on line 465 in pkg/lint/rules.go

View workflow job for this annotation

GitHub Actions / lint

c.Test.Enabled undefined (type *"chainguard.dev/melange/pkg/config".Test has no field or method Enabled)

Check failure on line 465 in pkg/lint/rules.go

View workflow job for this annotation

GitHub Actions / build

c.Test.Enabled undefined (type *"chainguard.dev/melange/pkg/config".Test has no field or method Enabled)
return nil
}
if c.Test != nil && !c.Test.Enabled && c.Test.ExcludeReason != "" {

Check failure on line 468 in pkg/lint/rules.go

View workflow job for this annotation

GitHub Actions / wolfictl text on wolfi-dev/os

c.Test.Enabled undefined (type *"chainguard.dev/melange/pkg/config".Test has no field or method Enabled)

Check failure on line 468 in pkg/lint/rules.go

View workflow job for this annotation

GitHub Actions / wolfictl text on wolfi-dev/os

c.Test.ExcludeReason undefined (type *"chainguard.dev/melange/pkg/config".Test has no field or method ExcludeReason)

Check failure on line 468 in pkg/lint/rules.go

View workflow job for this annotation

GitHub Actions / lint

c.Test.Enabled undefined (type *"chainguard.dev/melange/pkg/config".Test has no field or method Enabled)

Check failure on line 468 in pkg/lint/rules.go

View workflow job for this annotation

GitHub Actions / lint

c.Test.ExcludeReason undefined (type *"chainguard.dev/melange/pkg/config".Test has no field or method ExcludeReason)) (typecheck)

Check failure on line 468 in pkg/lint/rules.go

View workflow job for this annotation

GitHub Actions / lint

c.Test.Enabled undefined (type *"chainguard.dev/melange/pkg/config".Test has no field or method Enabled)

Check failure on line 468 in pkg/lint/rules.go

View workflow job for this annotation

GitHub Actions / lint

c.Test.ExcludeReason undefined (type *"chainguard.dev/melange/pkg/config".Test has no field or method ExcludeReason)) (typecheck)

Check failure on line 468 in pkg/lint/rules.go

View workflow job for this annotation

GitHub Actions / lint

c.Test.Enabled undefined (type *"chainguard.dev/melange/pkg/config".Test has no field or method Enabled)

Check failure on line 468 in pkg/lint/rules.go

View workflow job for this annotation

GitHub Actions / build

c.Test.Enabled undefined (type *"chainguard.dev/melange/pkg/config".Test has no field or method Enabled)

Check failure on line 468 in pkg/lint/rules.go

View workflow job for this annotation

GitHub Actions / build

c.Test.ExcludeReason undefined (type *"chainguard.dev/melange/pkg/config".Test has no field or method ExcludeReason)
return nil
}
return fmt.Errorf("test is disabled but no reason is provided")
},
},
{
Name: "valid-update-schedule",
Description: "update schedule config should contain a valid period",
Expand Down
18 changes: 18 additions & 0 deletions pkg/lint/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,24 @@ func TestLinter_Rules(t *testing.T) {
wantErr: false,
matches: 1,
},
{
file: "test-disabled.yaml",
minSeverity: SeverityInfo,
want: EvalResult{
File: "test-disabled",
Errors: EvalRuleErrors{
{
Rule: Rule{
Name: "test-disabled-reason",
Severity: SeverityWarning,
},
Error: fmt.Errorf("[test-disabled-reason]: test is disabled but no reason is provided (WARNING)"),
},
},
},
wantErr: false,
matches: 1,
},
{
file: "valid-update-schedule.yaml",
minSeverity: SeverityWarning,
Expand Down
28 changes: 28 additions & 0 deletions pkg/lint/testdata/files/test-disabled.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package:
name: update-disabled
version: 1.0.0
epoch: 0
description: A valid package
target-architecture:
- all
copyright:
- license: Apache-2.0
paths:
- "*"
environment:
contents:
packages:
- foo
- bar
- baz
pipeline:
- uses: fetch
with:
uri: https://test.com/foo/bar/baz.tar.gz
expected-sha512: 6d8e828fa406518b4b3f55b0e5f62bbd5cf25cb5782d1884b9d5eaf61fb0614deaacad4236ab7420fa5b3868c79df226ae1aa5193bb136c556aa52853eeca553
- runs: |
go build .
test:
enabled: false
update:
enabled: true
Loading