MCPcopy Create free account
hub / github.com/commander-cli/commander / TestCommand

Function TestCommand

pkg/app/test_command.go:27–76  ·  view source on GitHub ↗

TestCommand executes the test argument testPath is the path to the test suite config, it can be a dir or file ctx holds the command flags. If directory scanning is enabled with --dir, test filtering is not supported

(testPath string, ctx TestCommandContext)

Source from the content-addressed store, hash-verified

25// ctx holds the command flags. If directory scanning is enabled with --dir,
26// test filtering is not supported
27func TestCommand(testPath string, ctx TestCommandContext) error {
28 if ctx.Workdir != "" {
29 err := os.Chdir(ctx.Workdir)
30 if err != nil {
31 return fmt.Errorf(err.Error())
32 }
33 }
34
35 if ctx.Verbose {
36 log.SetOutput(os.Stdout)
37 }
38
39 overwriteConfigPath = ctx.Config
40 out = output.NewCliOutput(!ctx.NoColor)
41
42 if testPath == "" {
43 testPath = CommanderFile
44 }
45
46 var result runtime.Result
47 var err error
48 switch {
49 case ctx.Dir:
50 fmt.Println("Starting test against directory: " + testPath + "...")
51 fmt.Println("")
52 result, err = testDir(testPath, ctx.Filters)
53 case testPath == "-":
54 fmt.Println("Starting test from stdin...")
55 fmt.Println("")
56 result, err = testStdin(ctx.Filters)
57 case isURL(testPath):
58 fmt.Println("Starting test from " + testPath + "...")
59 fmt.Println("")
60 result, err = testURL(testPath, ctx.Filters)
61 default:
62 fmt.Println("Starting test file " + testPath + "...")
63 fmt.Println("")
64 result, err = testFile(testPath, "", ctx.Filters)
65 }
66
67 if err != nil {
68 return fmt.Errorf(err.Error())
69 }
70
71 if !out.PrintSummary(result) && !ctx.Verbose {
72 return fmt.Errorf("Test suite failed, use --verbose for more detailed output")
73 }
74
75 return nil
76}
77
78func testFile(filePath string, fileName string, filters runtime.Filters) (runtime.Result, error) {
79 s, err := getSuite(filePath, fileName)

Callers 15

createTestCommandFunction · 0.92
Test_TestCommand_VerboseFunction · 0.85
Test_TestCommandFunction · 0.85
Test_TestCommand_DirFunction · 0.85
Test_TestCommand_Dir_ErrFunction · 0.85
Test_TestCommand_HttpFunction · 0.85

Calls 7

NewCliOutputFunction · 0.92
testDirFunction · 0.85
testStdinFunction · 0.85
isURLFunction · 0.85
testURLFunction · 0.85
testFileFunction · 0.85
PrintSummaryMethod · 0.80

Tested by

no test coverage detected