Skip to content

Commit 0413220

Browse files
committed
small app refactor, fix fail test output, add docs and changlog entry
1 parent 1485c34 commit 0413220

6 files changed

Lines changed: 22 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# v2.1.0
2+
3+
- Added `--dir` flag to execute all commander test suites within a directory. This feature is not recursive.
4+
15
# v2.0.0
26

37
- Added `nodes` which allow remote execution of tests

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ $ ./commander test /tmp/test.yaml
195195

196196
# Execute a single test
197197
$ ./commander test /tmp/test.yaml "my test"
198+
199+
# Execute suites within a test directory
200+
$ ./commander test --dir /tmp
198201
```
199202

200203
### Adding tests

cmd/commander/commander.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func createTestCommand() cli.Command {
6161
},
6262
cli.BoolFlag{
6363
Name: "dir",
64-
Usage: "Execute all test files in directory - e.g. /path/to/test_files/",
64+
Usage: "Execute all test files in a directory sorted by file name, this is not recursive - e.g. /path/to/test_files/",
6565
},
6666
},
6767
Action: func(c *cli.Context) error {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Hello, I am file in a directory. Don't delete me
22
as I am a place hold for commander's integration tests.
3-
Please see missing test 'test missing dir flag' in
3+
Please see the test 'test missing dir flag' in
44
commander_unix.yaml for why (:

pkg/app/test_command.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"io/ioutil"
66
"log"
77
"os"
8+
"path"
89
"sync"
910

1011
"github.com/SimonBaeumer/commander/pkg/output"
@@ -71,7 +72,7 @@ func testDir(directory string) (<-chan runtime.TestResult, error) {
7172
continue
7273
}
7374

74-
fileResults, err := testFile(directory+"/"+f.Name(), "")
75+
fileResults, err := testFile(path.Join(directory, f.Name()), "")
7576
if err != nil {
7677
panic(fmt.Sprintf("%s: %s", f.Name(), err))
7778
}

pkg/output/cli.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ func (w *OutputWriter) Start(results <-chan runtime.TestResult) bool {
4242
for r := range results {
4343
testResults = append(testResults, r)
4444
if r.ValidationResult.Success {
45-
w.printResult(r, "✓")
45+
w.printResult(r)
4646
} else {
47-
w.printResult(r, "✗")
47+
w.printResult(r)
4848
failed++
4949
}
5050
}
@@ -67,8 +67,15 @@ func (w *OutputWriter) Start(results <-chan runtime.TestResult) bool {
6767
return failed == 0
6868
}
6969

70-
func (w *OutputWriter) printResult(r runtime.TestResult, mark string) {
71-
str := fmt.Sprintf("%s [%s] %s", mark, r.Node, r.TestCase.Title)
70+
func (w *OutputWriter) printResult(r runtime.TestResult) {
71+
if !r.ValidationResult.Success {
72+
str := fmt.Sprintf("✗ [%s] %s", r.Node, r.TestCase.Title)
73+
str = w.addFile(str, r)
74+
s := w.addTries(str, r)
75+
w.fprintf(au.Red(s))
76+
return
77+
}
78+
str := fmt.Sprintf("✓ [%s] %s", r.Node, r.TestCase.Title)
7279
str = w.addFile(str, r)
7380
s := w.addTries(str, r)
7481
w.fprintf(s)

0 commit comments

Comments
 (0)