Skip to content

Commit

Permalink
chore: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
xNok committed Sep 30, 2024
1 parent f0b6f88 commit 92993db
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
5 changes: 3 additions & 2 deletions document/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package document

import (
"fmt"
"github.com/open-policy-agent/opa/ast"
"github.com/open-policy-agent/opa/loader"
"os"
"path/filepath"
"strings"

"github.com/open-policy-agent/opa/ast"
"github.com/open-policy-agent/opa/loader"
)

// ParseRegoWithAnnotations parse the rego in the indicated directory
Expand Down
4 changes: 2 additions & 2 deletions document/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package document

import (
"fmt"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/open-policy-agent/opa/ast"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
)

func validateAnnotation(t *testing.T, as ast.FlatAnnotationsRefSet, want []string) {
Expand Down Expand Up @@ -51,7 +52,6 @@ func PartialEqual(t *testing.T, expected, actual any, diffOpts cmp.Option, msgAn
assert.Fail(t, fmt.Sprintf("Not equal: \n"+
"expected: %s\n"+
"actual : %s%s", expected, actual, diff), msgAndArgs...)
return
}

func TestGetAnnotations(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion document/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func renderTemplate(tpl *TemplateConfig, args interface{}, out io.Writer) error
return err
}
default:
return fmt.Errorf("unknown template kind: %s", tpl.kind)
return fmt.Errorf("unknown template kind: %v", tpl.kind)
}

// we render the template
Expand Down
9 changes: 6 additions & 3 deletions document/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package document

import (
"bytes"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"os"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func Test_generateDocument(t *testing.T) {
Expand Down Expand Up @@ -52,7 +53,9 @@ func Test_generateDocument(t *testing.T) {
assert.Equal(t, string(wantOut), gotOut.String())

// prospective golden file, much simpler to see what's the result in case the test fails
os.WriteFile(tt.wantOut+".golden", gotOut.Bytes(), 0644)
// this does not override the existing test, but create a new file called xxx.golden
err = os.WriteFile(tt.wantOut+".golden", gotOut.Bytes(), 0600)
assert.NoError(t, err)
},
)
}
Expand Down
8 changes: 6 additions & 2 deletions internal/commands/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package commands

import (
"fmt"
"github.com/open-policy-agent/conftest/document"
"github.com/spf13/cobra"
"log"
"os"
"path/filepath"

"github.com/open-policy-agent/conftest/document"
"github.com/spf13/cobra"
)

func NewDocumentCommand() *cobra.Command {
Expand Down Expand Up @@ -55,6 +56,9 @@ func NewDocumentCommand() *cobra.Command {
}(f)

template, err := cmd.Flags().GetString("template")
if err != nil {
return fmt.Errorf("invalid template: %s", err)
}

err = document.GenerateDocument(path, template, f)
if err != nil {
Expand Down

0 comments on commit 92993db

Please sign in to comment.