Skip to content

Commit 1e65930

Browse files
twmbclaudemmatczuk
authored
cli(test): add --verbose flag to list test case names (#400)
Adds a -v/--verbose flag to the test command that prints individual test case names as they are executed, similar to go test -v. Closes redpanda-data/connect#893 Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Michal Matczuk <michal.matczuk@redpanda.com>
1 parent 9c5bc40 commit 1e65930

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

internal/cli/test/cli.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ func CliCommand(cliOpts *common.CLIOpts) *cli.Command {
2323
Usage: "allow components to write logs at a provided level to stdout.",
2424
},
2525

26+
&cli.BoolFlag{
27+
Name: "verbose",
28+
Aliases: []string{"v"},
29+
Usage: "print all test case names before they are executed.",
30+
},
31+
2632
&cli.StringSliceFlag{
2733
Name: common.RootFlagResources,
2834
Aliases: []string{"r"},
@@ -61,17 +67,18 @@ For more information check out the docs at:
6167
if resourcesPaths, err = filepath.Globs(ifs.OS(), resourcesPaths); err != nil {
6268
return fmt.Errorf("failed to resolve resource glob pattern: %w", err)
6369
}
70+
verbose := c.Bool("verbose")
6471
if logLevel := c.String("log"); logLevel != "" {
6572
logConf := log.NewConfig()
6673
logConf.LogLevel = logLevel
6774
logger, err := log.New(cliOpts.Stdout, ifs.OS(), logConf)
6875
if err != nil {
6976
return fmt.Errorf("failed to init logger: %w", err)
7077
}
71-
if RunAll(cliOpts, c.Args().Slice(), "_benthos_test", true, logger, resourcesPaths) {
78+
if RunAll(cliOpts, c.Args().Slice(), "_benthos_test", true, verbose, logger, resourcesPaths) {
7279
return nil
7380
}
74-
} else if RunAll(cliOpts, c.Args().Slice(), "_benthos_test", true, log.Noop(), resourcesPaths) {
81+
} else if RunAll(cliOpts, c.Args().Slice(), "_benthos_test", true, verbose, log.Noop(), resourcesPaths) {
7582
return nil
7683
}
7784
return &common.ErrExitCode{Err: errors.New("lint errors"), Code: 1}

internal/cli/test/command.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func lintTarget(opts *common.CLIOpts, spec docs.FieldSpecs, path, testSuffix str
125125
// RunAll executes the test command for a slice of paths. The path can either be
126126
// a config file, a config files test definition file, a directory, or the
127127
// wildcard pattern './...'.
128-
func RunAll(opts *common.CLIOpts, paths []string, testSuffix string, lint bool, logger log.Modular, resourcesPaths []string) bool {
128+
func RunAll(opts *common.CLIOpts, paths []string, testSuffix string, lint, verbose bool, logger log.Modular, resourcesPaths []string) bool {
129129
targets, err := GetTestTargets(paths, testSuffix)
130130
if err != nil {
131131
fmt.Fprintf(opts.Stderr, "Failed to obtain test targets: %v\n", err)
@@ -158,6 +158,15 @@ func RunAll(opts *common.CLIOpts, paths []string, testSuffix string, lint bool,
158158
return false
159159
}
160160
}
161+
if verbose {
162+
for _, c := range targets[target] {
163+
name := c.Name
164+
if name == "" {
165+
name = "(unnamed)"
166+
}
167+
fmt.Fprintf(opts.Stdout, " - %v\n", name)
168+
}
169+
}
161170
if failCases, err = Execute(opts.Environment, opts.MainConfigSpecCtor(), targets[target], target, resourcesPaths, logger); err != nil {
162171
fmt.Fprintf(opts.Stderr, "Failed to execute test target '%v': %v\n", target, err)
163172
return false

internal/cli/test/command_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,15 @@ tests:
247247
}
248248
defer os.RemoveAll(testDir)
249249

250-
if !test.RunAll(common.NewCLIOpts("", ""), []string{filepath.Join(testDir, "foo.yaml")}, "_benthos_test", false, log.Noop(), nil) {
250+
if !test.RunAll(common.NewCLIOpts("", ""), []string{filepath.Join(testDir, "foo.yaml")}, "_benthos_test", false, false, log.Noop(), nil) {
251251
t.Error("Unexpected result")
252252
}
253253

254-
if test.RunAll(common.NewCLIOpts("", ""), []string{filepath.Join(testDir, "foo.yaml")}, "_benthos_test", true, log.Noop(), nil) {
254+
if test.RunAll(common.NewCLIOpts("", ""), []string{filepath.Join(testDir, "foo.yaml")}, "_benthos_test", true, false, log.Noop(), nil) {
255255
t.Error("Unexpected result")
256256
}
257257

258-
if test.RunAll(common.NewCLIOpts("", ""), []string{testDir}, "_benthos_test", true, log.Noop(), nil) {
258+
if test.RunAll(common.NewCLIOpts("", ""), []string{testDir}, "_benthos_test", true, false, log.Noop(), nil) {
259259
t.Error("Unexpected result")
260260
}
261261
}

0 commit comments

Comments
 (0)