Skip to content

Commit

Permalink
Merge pull request #1 from pfnet/fix/enable_flags
Browse files Browse the repository at this point in the history
fix: Make flags work properly
  • Loading branch information
hrk091 authored Sep 21, 2024
2 parents feeb548 + 4675bc8 commit 80c4033
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions internal/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/spf13/cobra"
)

func newInitCmd(cfg tester.CmdConfig) *cobra.Command {
func newInitCmd(cfg *tester.CmdConfig) *cobra.Command {
return &cobra.Command{
Use: "init [path to admission policy file]",
Short: "Generate skeleton manifests for writing tests",
Expand All @@ -32,7 +32,7 @@ func newInitCmd(cfg tester.CmdConfig) *cobra.Command {
return fmt.Errorf("path is required")
}
targetFilePath := args[0]
return tester.RunInit(cfg, targetFilePath)
return tester.RunInit(*cfg, targetFilePath)
},
}
}
8 changes: 5 additions & 3 deletions internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ func newRootCmd() *cobra.Command {
cmd.PersistentFlags().BoolVarP(&cfg.Verbose, "verbose", "v", false, "Verbose output")
cmd.PersistentFlags().BoolVarP(&cfg.Debug, "debug", "d", false, "Debug output")

initLog(cfg)
cobra.OnInitialize(func() {
initLog(cfg)
})

cmd.AddCommand(newInitCmd(cfg))
cmd.AddCommand(newRunCmd(cfg))
cmd.AddCommand(newInitCmd(&cfg))
cmd.AddCommand(newRunCmd(&cfg))
cmd.AddCommand(newVersionCmd())
return cmd
}
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ import (
"github.com/spf13/cobra"
)

func newRunCmd(cfg tester.CmdConfig) *cobra.Command {
func newRunCmd(cfg *tester.CmdConfig) *cobra.Command {
return &cobra.Command{
Use: "run [path to test manifest]...",
Short: "Run the tests of ValidatingAdmissionPolicy",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return fmt.Errorf("path is required")
}
return tester.Run(cfg, args)
return tester.Run(*cfg, args)
},
}
}
7 changes: 3 additions & 4 deletions internal/tester/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,11 @@ func (r *policyEvalResult) String(verbose bool) string {
}
summary += fmt.Sprintf(" - %s ==> %s", strings.ToUpper(string(r.TestCase.Expect)), strings.ToUpper(string(r.Result)))

if !verbose {
return summary
}

out := []string{summary}
for _, d := range r.Decisions {
if r.Pass() && !verbose {
continue
}
// Workaround to handle the case where the evaluation is not set
// TODO remove this workaround after htcps://github.com/kubernetes/kubernetes/pull/126867 is released
if d.Evaluation == "" {
Expand Down

0 comments on commit 80c4033

Please sign in to comment.