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

e2e: Fix CLI test for 1.0 preparations and defaults #1321

Merged
merged 1 commit into from
Jan 8, 2025
Merged
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
40 changes: 31 additions & 9 deletions e2e/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,13 @@ func TestLintProposeToRunFix(t *testing.T) {

act := strings.Split(stdout.String(), "\n")
act = act[len(act)-5:]
exp := []string{"1 file linted. 5 violations found.", "", "Hint: 2/5 violations can be automatically fixed (directory-package-mismatch, use-rego-v1)", " Run regal fix --help for more details.", ""}
exp := []string{
"1 file linted. 2 violations found.",
"",
"Hint: 2/2 violations can be automatically fixed (directory-package-mismatch, opa-fmt)",
" Run regal fix --help for more details.",
"",
}
if diff := cmp.Diff(act, exp); diff != "" {
t.Errorf("unexpected stdout trailer: (-want, +got):\n%s", diff)
}
Expand Down Expand Up @@ -278,8 +284,9 @@ func TestLintV0WithRegoV1ImportViolations(t *testing.T) {

cwd := testutil.Must(os.Getwd())(t)

err := regal(&stdout, &stderr)("lint", "--format", "json", "--config-file",
cwd+filepath.FromSlash("/testdata/configs/v0-with-import-rego-v1.yaml"),
err := regal(&stdout, &stderr)(
"lint", "--format", "json",
"--config-file", cwd+filepath.FromSlash("/testdata/configs/v0-with-import-rego-v1.yaml"),
cwd+filepath.FromSlash("/testdata/v0/"))

expectExitCode(t, err, 3, &stdout, &stderr)
Expand Down Expand Up @@ -437,7 +444,7 @@ func TestAggregatesAreCollectedAndUsed(t *testing.T) {
t.Run("two policies — no violations expected", func(t *testing.T) {
stdout, stderr := bytes.Buffer{}, bytes.Buffer{}

err := regal(&stdout, &stderr)("lint", "--format", "json", "--rules",
err := regal(&stdout, &stderr)("lint", "--format", "json",
basedir+filepath.FromSlash("/custom/regal/rules/testcase/aggregates/custom_rules_using_aggregates.rego"),
basedir+filepath.FromSlash("/two_policies"))

Expand Down Expand Up @@ -465,7 +472,9 @@ func TestAggregatesAreCollectedAndUsed(t *testing.T) {
t.Run("three policies - violation expected", func(t *testing.T) {
stdout, stderr := bytes.Buffer{}, bytes.Buffer{}

err := regal(&stdout, &stderr)("lint", "--format", "json", "--rules",
err := regal(&stdout, &stderr)("lint", "--format", "json",
"--config-file", filepath.Join(cwd, "e2e_conf.yaml"),
"--rules",
basedir+filepath.FromSlash("/custom/regal/rules/testcase/aggregates/custom_rules_using_aggregates.rego"),
basedir+filepath.FromSlash("/three_policies"))

Expand All @@ -489,7 +498,9 @@ func TestAggregatesAreCollectedAndUsed(t *testing.T) {
t.Run("custom policy where nothing aggregate is a violation", func(t *testing.T) {
stdout, stderr := bytes.Buffer{}, bytes.Buffer{}

err := regal(&stdout, &stderr)("lint", "--format", "json", "--rules",
err := regal(&stdout, &stderr)("lint", "--format", "json",
"--config-file", filepath.Join(cwd, "e2e_conf.yaml"),
"--rules",
basedir+filepath.FromSlash("/custom/regal/rules/testcase/empty_aggregate/"),
basedir+filepath.FromSlash("/two_policies"))

Expand Down Expand Up @@ -517,8 +528,13 @@ func TestLintAggregateIgnoreDirective(t *testing.T) {
stdout, stderr := bytes.Buffer{}, bytes.Buffer{}
cwd := testutil.Must(os.Getwd())(t)

err := regal(&stdout, &stderr)("lint", "--format", "json",
cwd+filepath.FromSlash("/testdata/aggregates/ignore_directive"))
err := regal(&stdout, &stderr)(
"lint",
"--config-file", filepath.Join(cwd, "e2e_conf.yaml"),
"--format",
"json",
cwd+filepath.FromSlash("/testdata/aggregates/ignore_directive"),
)

expectExitCode(t, err, 3, &stdout, &stderr)

Expand Down Expand Up @@ -818,7 +834,13 @@ func TestLintPprof(t *testing.T) {
_ = os.Remove(pprofFile)
})

err := regal(&stdout, &stderr)("lint", "--pprof", "clock", cwd+filepath.FromSlash("/testdata/violations"))
err := regal(&stdout, &stderr)(
"lint",
// this overrides the ignore directives for e2e loaded from the config file
"--ignore-files=none",
"--pprof", "clock",
cwd+filepath.FromSlash("/testdata/violations"),
)

expectExitCode(t, err, 3, &stdout, &stderr)

Expand Down
2 changes: 2 additions & 0 deletions e2e/testdata/configs/v0-with-import-rego-v1.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
project:
rego-version: 0
capabilities:
from:
engine: opa
Expand Down
Loading