MCPcopy Create free account
hub / github.com/conforma/cli / NewTestCommand

Function NewTestCommand

cmd/test/test.go:119–269  ·  view source on GitHub ↗

NewTestCommand creates a new test command.

(ctx context.Context)

Source from the content-addressed store, hash-verified

117
118// NewTestCommand creates a new test command.
119func NewTestCommand(ctx context.Context) *cobra.Command {
120 cmd := cobra.Command{
121 Use: "test <path> [path [...]]",
122 Short: "Test your configuration files using Open Policy Agent",
123 Long: testDesc,
124 PreRunE: func(cmd *cobra.Command, _ []string) error {
125 flagNames := []string{
126 "all-namespaces",
127 "combine",
128 "data",
129 "fail-on-warn",
130 "ignore",
131 "namespace",
132 "no-color",
133 "no-fail",
134 "suppress-exceptions",
135 "output",
136 "parser",
137 "policy",
138 "proto-file-dirs",
139 "capabilities",
140 "rego-version",
141 "trace",
142 "strict",
143 "show-builtin-errors",
144 "update",
145 "junit-hide-message",
146 "quiet",
147 "tls",
148 }
149 for _, name := range flagNames {
150 if err := viper.BindPFlag(name, cmd.Flags().Lookup(name)); err != nil {
151 return fmt.Errorf("bind flag: %w", err)
152 }
153 }
154
155 return nil
156 },
157
158 RunE: func(cmd *cobra.Command, fileList []string) error {
159 if len(fileList) < 1 {
160 cmd.Usage() //nolint
161 return fmt.Errorf("missing required arguments")
162 }
163
164 var runner runner.TestRunner
165 if err := viper.Unmarshal(&runner); err != nil {
166 return fmt.Errorf("unmarshal parameters: %w", err)
167 }
168
169 results, resultsErr := runner.Run(ctx, fileList)
170
171 exitCode := results.ExitCode()
172 if runner.FailOnWarn {
173 exitCode = results.ExitCodeFailOnWarn()
174 }
175
176 // Do this so we can write the appstudio format to a file

Callers 2

initFunction · 0.92
AddCommandsToFunction · 0.92

Calls 7

appstudioErrorHandlerFunction · 0.85
appstudioReportFunction · 0.85
GetMethod · 0.80
OutputMethod · 0.80
ErrorfMethod · 0.65
RunMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected