Skip to content

Commit 75acc48

Browse files
authored
Merge pull request #144 from commander-cli/skip-test-case
Skip test case
2 parents d896521 + 352ac31 commit 75acc48

File tree

18 files changed

+168
-25
lines changed

18 files changed

+168
-25
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# v2.3.0
2+
3+
- Add property `skip`, adds the ability to skip test cases
4+
15
# v2.2.0
26

37
- Move from `github.com/SimonBaeumer` to `github.com/commander-cli`

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ For more information take a look at the [quick start](#quick-start), the [exampl
4141
* [not-contains](#not-contains)
4242
* [xml](#xml)
4343
- [stderr](#stderr)
44+
- [skip](#skip)
4445
+ [Config](#user-content-config-config)
4546
- [dir](#dir)
4647
- [env](#env)
@@ -146,6 +147,11 @@ tests:
146147
stdout: hello # Default is to check if it contains the given characters
147148
exit-code: 0 # Assert exit-code
148149

150+
it should skip:
151+
command: echo "I should be skipped"
152+
stdout: I should be skipped
153+
skip: true
154+
149155
it should fail:
150156
command: invalid
151157
stderr:
@@ -162,7 +168,8 @@ tests:
162168
xml:
163169
"//book//auhtor": Steven King # Make assertions on xml documents
164170
exit-code: 127
165-
171+
skip: false
172+
166173
it has configs:
167174
command: echo hello
168175
stdout:
@@ -536,6 +543,20 @@ See [stdout](#stdout) for more information.
536543
line-count: 1
537544
```
538545

546+
#### skip
547+
548+
`skip` is a `boolean` type, setting this field to `true` will skip the test case.
549+
550+
- name: `skip`
551+
- type: `bool`
552+
- default: `false`
553+
554+
```yaml
555+
echo test:
556+
stdout: test
557+
skip: true
558+
```
559+
539560
### <a name="config-config"></a>Config
540561

541562
You can add configs which will be applied globally to all tests or just for a specific test case, i.e.:

commander_linux.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ tests:
66
- ✓ [ssh-host] it should test ssh host
77
- ✓ [ssh-host] it should set env variable
88
- ✓ [ssh-host-default] it should be executed on ssh-host-default
9+
- "- [ssh-host-default] it should skip, was skipped"
10+
- "- [ssh-host] it should skip, was skipped"
11+
- "- [local] it should skip, was skipped"
912
- ✓ [ssh-host] it should test multiple hosts
1013
- ✓ [ssh-host-default] it should test multiple hosts
1114
- ✓ [local] it should test multiple hosts

commander_unix.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ tests:
1515
stdout:
1616
contains:
1717
- ✓ [local] it should exit with error code
18-
line-count: 16
18+
- "- [local] it should skip, was skipped"
19+
line-count: 17
1920
exit-code: 0
2021

2122
it should assert that commander will fail:

commander_windows.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ tests:
1414
command: commander.exe test ./integration/windows/commander_test.yaml
1515
stdout:
1616
contains:
17+
- "- [local] it should skip, was skipped"
1718
- test
1819
exit-code: 0
1920

examples/commander.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,8 @@ tests:
2020
command: invalid
2121
stderr: "/bin/sh: 1: command invalid: not found"
2222
exit-code: 127
23+
24+
it should skip:
25+
command: echo "I should be skipped"
26+
stdout: I should be skipped
27+
skip: true

integration/linux/nodes.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ tests:
4040
it should be executed on ssh-host-default:
4141
command: whoami
4242
stdout: root
43+
44+
it should skip:
45+
command: whoami
46+
stdout: root
47+
config:
48+
nodes:
49+
- ssh-host-default
50+
- ssh-host
51+
- local
52+
skip: true
4353

4454
it should test multiple hosts:
4555
command: echo hello

integration/unix/commander_test.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,8 @@ tests:
6565
command: echo $USER
6666
stdout: from_parent
6767
exit-code: 0
68+
69+
it should skip:
70+
command: whoami
71+
stdout: root
72+
skip: true

integration/windows/commander_test.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,9 @@ tests:
3838
command: echo lorem ipsum
3939
stdout:
4040
not-contains:
41-
- not contains
41+
- not contains
42+
43+
it should skip:
44+
command: whoami
45+
stdout: root
46+
skip: true

pkg/output/cli.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type TestResult struct {
4444
FailedProperty string
4545
Diff string
4646
Error error
47+
Skipped bool
4748
}
4849

4950
// GetEventHandler create a new runtime.EventHandler
@@ -53,6 +54,12 @@ func (w *OutputWriter) GetEventHandler() *runtime.EventHandler {
5354
tr := convertTestResult(testResult)
5455
w.printResult(tr)
5556
}
57+
58+
handler.TestSkipped = func(testResult runtime.TestResult) {
59+
tr := convertTestResult(testResult)
60+
w.printSkip(tr)
61+
}
62+
5663
return &handler
5764
}
5865

@@ -74,7 +81,7 @@ func (w *OutputWriter) PrintSummary(result runtime.Result) bool {
7481
return result.Failed == 0
7582
}
7683

77-
// PrintResult prints the simple output form of a TestReault
84+
// printResult prints the simple output form of a TestReault
7885
func (w *OutputWriter) printResult(r TestResult) {
7986
if !r.Success {
8087
w.fprintf(w.au.Red(w.template.testResult(r)))
@@ -83,18 +90,27 @@ func (w *OutputWriter) printResult(r TestResult) {
8390
w.fprintf(w.template.testResult(r))
8491
}
8592

93+
func (w *OutputWriter) printSkip(r TestResult) {
94+
w.fprintf(fmt.Sprintf("- [%s] %s, was skipped", r.Node, r.Title))
95+
}
96+
8697
func (w *OutputWriter) printFailures(results []runtime.TestResult) {
8798
w.fprintf("")
8899
w.fprintf(w.au.Bold("Results"))
89100
w.fprintf(w.au.Bold(""))
90101

91102
for _, tr := range results {
92103
r := convertTestResult(tr)
104+
if r.Skipped {
105+
continue
106+
}
107+
93108
if r.Error != nil {
94109
w.fprintf(w.au.Bold(w.au.Red(w.template.errors(r))))
95110
w.fprintf(r.Error.Error())
96111
continue
97112
}
113+
98114
if !r.Success {
99115
w.fprintf(w.au.Bold(w.au.Red(w.template.failures(r))))
100116
w.fprintf(r.Diff)
@@ -119,6 +135,7 @@ func convertTestResult(tr runtime.TestResult) TestResult {
119135
FailedProperty: tr.FailedProperty,
120136
Diff: tr.ValidationResult.Diff,
121137
Error: tr.TestCase.Result.Error,
138+
Skipped: tr.Skipped,
122139
}
123140

124141
return testResult

0 commit comments

Comments
 (0)