Skip to content

Commit

Permalink
Address reviews
Browse files Browse the repository at this point in the history
Signed-off-by: Oğuzhan Durgun <oguzhandurgun95@gmail.com>
  • Loading branch information
oguzhand95 committed Apr 4, 2023
1 parent 13effc0 commit 997f719
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 28 deletions.
21 changes: 11 additions & 10 deletions cmd/cerbos/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@ cerbos compile --skip-tests /path/to/policy/repo
`

type Cmd struct { //nolint:govet // Kong prints fields in order, so we don't want to reorder fields to save bytes.
Dir string `help:"Policy directory" arg:"" required:"" type:"existingdir"`
IgnoreSchemas bool `help:"Ignore schemas during compilation"`
Tests string `help:"Path to the directory containing tests. Defaults to policy directory." type:"existingdir"`
RunRegex string `help:"Run only tests that match this regex" name:"run"`
SkipTests bool `help:"Skip tests"`
Output flagset.OutputFormat `help:"Output format (${enum})" default:"tree" enum:"tree,list,json,junit" short:"o"`
Color *outputcolor.Level `help:"Output color level (auto,never,always,256,16m). Defaults to auto." xor:"color"`
NoColor bool `help:"Disable colored output" xor:"color"`
Verbose bool `help:"Verbose output on test failure"`
Dir string `help:"Policy directory" arg:"" required:"" type:"existingdir"`
IgnoreSchemas bool `help:"Ignore schemas during compilation"`
Tests string `help:"Path to the directory containing tests. Defaults to policy directory." type:"existingdir"`
RunRegex string `help:"Run only tests that match this regex" name:"run"`
SkipTests bool `help:"Skip tests"`
Output flagset.OutputFormat `help:"Output format (${enum})" default:"tree" enum:"tree,list,json" short:"o"`
TestOutput flagset.VerificationOutputFormat `help:"Test output format (${enum})" default:"tree" enum:"tree,list,json,junit"`
Color *outputcolor.Level `help:"Output color level (auto,never,always,256,16m). Defaults to auto." xor:"color"`
NoColor bool `help:"Disable colored output" xor:"color"`
Verbose bool `help:"Verbose output on test failure"`
}

func (c *Cmd) Run(k *kong.Kong) error {
Expand Down Expand Up @@ -130,7 +131,7 @@ func (c *Cmd) Run(k *kong.Kong) error {
return fmt.Errorf("failed to run tests: %w", err)
}

err = verification.Display(p, results, c.Output, c.Verbose, colorLevel)
err = verification.Display(p, results, c.TestOutput, c.Verbose, colorLevel)
if err != nil {
return fmt.Errorf("failed to display test results: %w", err)
}
Expand Down
4 changes: 0 additions & 4 deletions cmd/cerbos/compile/internal/compilation/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
package compilation

import (
"fmt"

internalerrors "github.com/cerbos/cerbos/cmd/cerbos/compile/internal/errors"
"github.com/cerbos/cerbos/cmd/cerbos/compile/internal/flagset"
"github.com/cerbos/cerbos/internal/compile"
Expand All @@ -20,8 +18,6 @@ func Display(p *printer.Printer, errs compile.ErrorList, output flagset.OutputFo
return displayJSON(p, errs, colorLevel)
case flagset.OutputFormatList, flagset.OutputFormatTree:
return displayList(p, errs)
case flagset.OutputFormatJUnit:
return fmt.Errorf("invalid option %s", flagset.OutputFormatJUnit)
}

return internalerrors.ErrFailed
Expand Down
16 changes: 12 additions & 4 deletions cmd/cerbos/compile/internal/flagset/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ package flagset
type OutputFormat string

const (
OutputFormatTree OutputFormat = "tree"
OutputFormatList OutputFormat = "list"
OutputFormatJSON OutputFormat = "json"
OutputFormatJUnit OutputFormat = "junit"
OutputFormatTree OutputFormat = "tree"
OutputFormatList OutputFormat = "list"
OutputFormatJSON OutputFormat = "json"
)

type VerificationOutputFormat string

const (
VerificationOutputFormatTree VerificationOutputFormat = "tree"
VerificationOutputFormatList VerificationOutputFormat = "list"
VerificationOutputFormatJSON VerificationOutputFormat = "json"
VerificationOutputFormatJUnit VerificationOutputFormat = "junit"
)
4 changes: 0 additions & 4 deletions cmd/cerbos/compile/internal/lint/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
package lint

import (
"fmt"

internalerrors "github.com/cerbos/cerbos/cmd/cerbos/compile/internal/errors"
"github.com/cerbos/cerbos/cmd/cerbos/compile/internal/flagset"
"github.com/cerbos/cerbos/internal/outputcolor"
Expand All @@ -20,8 +18,6 @@ func Display(p *printer.Printer, errs *index.BuildError, output flagset.OutputFo
return displayJSON(p, errs, colorLevel)
case flagset.OutputFormatList, flagset.OutputFormatTree:
return displayList(p, errs)
case flagset.OutputFormatJUnit:
return fmt.Errorf("invalid option %s", flagset.OutputFormatJUnit)
}

return internalerrors.ErrFailed
Expand Down
10 changes: 5 additions & 5 deletions cmd/cerbos/compile/internal/verification/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ var (
}
)

func Display(p *printer.Printer, results *policyv1.TestResults, output flagset.OutputFormat, verbose bool, colorLevel outputcolor.Level) error {
func Display(p *printer.Printer, results *policyv1.TestResults, output flagset.VerificationOutputFormat, verbose bool, colorLevel outputcolor.Level) error {
switch output {
case flagset.OutputFormatJSON:
case flagset.VerificationOutputFormatJSON:
return p.PrintProtoJSON(results, colorLevel)
case flagset.OutputFormatTree:
case flagset.VerificationOutputFormatTree:
return displayTree(p, pterm.DefaultTree, results, verbose)
case flagset.OutputFormatList:
case flagset.VerificationOutputFormatList:
return displayTree(p, pterm.TreePrinter{Indent: listIndent, VerticalString: " "}, results, verbose)
case flagset.OutputFormatJUnit:
case flagset.VerificationOutputFormatJUnit:
return displayJUnit(p, results, verbose)
default:
return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/test/testdata/verify_junit/cases/case_001.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
description: Valid test suite with some failing tests and engine traces
description: Valid test suite with some failing tests

0 comments on commit 997f719

Please sign in to comment.