Skip to content

Commit

Permalink
fixer: Return formatting to Fixer test
Browse files Browse the repository at this point in the history
Signed-off-by: Charlie Egan <[email protected]>
  • Loading branch information
charlieegan3 committed Jan 8, 2025
1 parent 4262a4a commit a5c1b18
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
1 change: 0 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@
}
]
}

32 changes: 13 additions & 19 deletions pkg/fixer/fixer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ package fixer
import (
"bytes"
"context"
"os"
"slices"
"testing"

"github.com/open-policy-agent/opa/v1/ast"
"github.com/open-policy-agent/opa/v1/format"
"github.com/open-policy-agent/opa/v1/topdown"

"github.com/styrainc/regal/pkg/config"
"github.com/styrainc/regal/pkg/fixer/fileprovider"
Expand All @@ -23,7 +21,10 @@ func TestFixer(t *testing.T) {
policies := map[string][]byte{
"test/main.rego": []byte(`package test
allow = true #no space
allow if {
true #no space
}
deny = true
`),
}

Expand All @@ -36,35 +37,28 @@ allow = true #no space

l := linter.NewLinter().
WithEnableAll(true).
WithInputModules(&input).
WithPrintHook(topdown.NewPrintHook(os.Stderr)).
WithUserConfig(config.Config{
Capabilities: &config.Capabilities{
Features: []string{"rego_v1_import"},
},
})
WithInputModules(&input)

f := NewFixer()
f.RegisterFixes(
[]fixes.Fix{
&fixes.UseAssignmentOperator{},
&fixes.NoWhitespaceComment{},
&fixes.DirectoryPackageMismatch{},
}...,
)
f.RegisterFixes(fixes.NewDefaultFixes()...)

fixReport, err := f.Fix(context.Background(), &l, memfp)
if err != nil {
t.Fatalf("failed to fix: %v", err)
}

expectedFileFixedViolations := map[string][]string{
"test/main.rego": {"no-whitespace-comment", "use-assignment-operator"},
// use-assigment-operator is correct in formatting so does not appear.
"test/main.rego": {"no-whitespace-comment", "opa-fmt"},
}
expectedFileContents := map[string][]byte{
"test/main.rego": []byte(`package test
allow := true # no space
allow := true
# no space
deny := true
`),
}

Expand Down

0 comments on commit a5c1b18

Please sign in to comment.