Skip to content

Commit d2b4251

Browse files
authored
Merge pull request #120 from dylanhitt/add-test-against-directory
Add test against directory
2 parents 36ed967 + 2fff09e commit d2b4251

20 files changed

Lines changed: 260 additions & 49 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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ package main
22

33
import (
44
"fmt"
5-
"github.com/SimonBaeumer/commander/pkg/app"
6-
"github.com/urfave/cli"
75
"io/ioutil"
86
"log"
97
"os"
108
"path"
119
"strings"
10+
11+
"github.com/SimonBaeumer/commander/pkg/app"
12+
"github.com/urfave/cli"
1213
)
1314

1415
var version string
@@ -58,6 +59,10 @@ func createTestCommand() cli.Command {
5859
Usage: "More output for debugging",
5960
EnvVar: "COMMANDER_VERBOSE",
6061
},
62+
cli.BoolFlag{
63+
Name: "dir",
64+
Usage: "Execute all test files in a directory sorted by file name, this is not recursive - e.g. /path/to/test_files/",
65+
},
6166
},
6267
Action: func(c *cli.Context) error {
6368
if c.Bool("verbose") {

commander_linux.yaml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,24 @@ tests:
1414
test docker:
1515
command: ./commander test integration/linux/docker.yaml
1616
stdout: ✓ [docker-host] cat /etc/os-release
17-
exit-code: 0
17+
exit-code: 0
18+
19+
test directory:
20+
command: ./commander test --dir integration/linux/
21+
stdout:
22+
contains:
23+
- ✓ [nodes.yaml] [ssh-host] it should test ssh host
24+
- ✓ [nodes.yaml] [ssh-host] it should set env variable
25+
- ✓ [nodes.yaml] [ssh-host-default] it should be executed on ssh-host-default
26+
- ✓ [nodes.yaml] [ssh-host] it should test multiple hosts
27+
- ✓ [nodes.yaml] [ssh-host-default] it should test multiple hosts
28+
- ✓ [nodes.yaml] [local] it should test multiple hosts
29+
- ✓ [docker.yaml] [docker-host] cat /etc/os-release
30+
exit-code: 0
31+
32+
test file with directory:
33+
command: ./commander test integration/linux/
34+
stdout:
35+
contains:
36+
- Use --dir to test directories with multiple test files
37+
exit-code: 1

commander_unix.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,17 @@ tests:
6565
- ✓ [local] it should retry failed commands, retries 2
6666
- ✗ [local] it should retry failed commands with an interval, retries 2
6767
exit-code: 1
68+
69+
test directory order:
70+
command: ./commander test --dir integration/unix/directory_test/
71+
stdout:
72+
lines:
73+
3: ✓ [alpha_test.yaml] [local] sleep test
74+
4: ✓ [beta_test.yaml] [local] ehco hello
75+
76+
test missing dir flag:
77+
command: ./commander test integration/unix/directory_test/
78+
stdout:
79+
contains:
80+
- 'integration/unix/directory_test/: is a directory'
81+
exit-code: 1

examples/commander.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ tests:
1818

1919
it should fail:
2020
command: invalid
21-
stderr: "/bin/sh: 1: invalid: not found"
22-
exit-code: 127
21+
stderr: "/bin/sh: 1: command invalid: not found"
22+
exit-code: 127

examples/environment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ tests:
1212
config:
1313
env:
1414
KEY: local
15-
exit-code: 0
15+
exit-code: 0

examples/minimal_test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
tests:
22
echo hello:
3-
exit-code: 0
3+
exit-code: 0

integration/linux/docker.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ tests:
2020
BUG_REPORT_URL="https://bugs.alpinelinux.org/"
2121
2222
"id -u":
23-
stdout: "1001"
23+
stdout: "1001"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
tests:
2+
sleep test:
3+
command: sleep 2
4+
exit-code: 0

0 commit comments

Comments
 (0)