Skip to content

Commit 6ae857d

Browse files
committed
Add filter integration tests
1 parent 14a067e commit 6ae857d

File tree

7 files changed

+47
-17
lines changed

7 files changed

+47
-17
lines changed

cmd/commander/commander.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func createTestCommand() cli.Command {
6969
},
7070
},
7171
Action: func(c *cli.Context) error {
72-
return app.TestCommand(c.Args().First(), c.Args().Get(1), app.NewAddContextFromCli(c))
72+
return app.TestCommand(c.Args().First(), app.NewAddContextFromCli(c))
7373
},
7474
}
7575
}

commander_unix.yaml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,25 @@ tests:
7878
stdout:
7979
contains:
8080
- 'integration/unix/directory_test/: is a directory'
81-
exit-code: 1
81+
exit-code: 1
82+
83+
test filter flag works:
84+
command: ./commander test integration/unix/filter_test.yaml --filter=executed
85+
stdout:
86+
contains:
87+
- ✓ [local] should be executed
88+
- ✓ [local] should also be executed
89+
not-contains:
90+
- should be filtered
91+
exit-code: 0
92+
93+
test filter flag with regex:
94+
command: ./commander test integration/unix/filter_test.yaml --filter="executed$"
95+
stdout:
96+
contains:
97+
- ✓ [local] should be executed
98+
- ✓ [local] should also be executed
99+
not-contains:
100+
- should be ignored
101+
- executed at the beginning is ignored
102+
exit-code: 0

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ module github.com/commander-cli/commander
22

33
require (
44
github.com/Microsoft/go-winio v0.4.14 // indirect
5-
github.com/SimonBaeumer/commander v1.3.0 // indirect
65
github.com/antchfx/xmlquery v1.1.0
76
github.com/antchfx/xpath v1.1.0 // indirect
87
github.com/commander-cli/cmd v1.3.0

go.sum

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
github.com/Microsoft/go-winio v0.4.14 h1:+hMXMk01us9KgxGb7ftKQt2Xpf5hH/yky+TDA+qxleU=
22
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
3-
github.com/SimonBaeumer/cmd v1.1.0 h1:tr5dUMlly/8bLiC5B0J1AcE4ISru8POEfzAirWnUJnY=
4-
github.com/SimonBaeumer/cmd v1.1.0/go.mod h1:4mc/LDXDWNbkeooqHP83yx3JXtInPHjJkF8zhzqqmZE=
5-
github.com/SimonBaeumer/commander v1.3.0 h1:QwZ7sTYFrmkOAccZwu8LZltDC08kIEcFjBBOkpjdZIg=
6-
github.com/SimonBaeumer/commander v1.3.0/go.mod h1:sNvvvwudBa2kQcSO7G1PttZHcBUnS5LmtJAjDS1Yh+U=
73
github.com/antchfx/xmlquery v1.1.0 h1:vj0kZ1y3Q6my4AV+a9xbWrMYzubw+84zuiKgvfV8vb8=
84
github.com/antchfx/xmlquery v1.1.0/go.mod h1:/+CnyD/DzHRnv2eRxrVbieRU/FIF6N0C+7oTtyUtCKk=
95
github.com/antchfx/xpath v1.1.0 h1:mJTvYpiHvxNQRD4Lbfin/FodHVCHh2a5KrOFr4ZxMOI=
@@ -40,9 +36,7 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
4036
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
4137
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
4238
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
43-
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
4439
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
45-
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
4640
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
4741
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
4842
github.com/tidwall/gjson v1.3.2 h1:+7p3qQFaH3fOMXAJSrdZwGKcOO/lYdGS0HqGhPqDdTI=

integration/unix/filter_test.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
tests:
2+
should be executed:
3+
command: echo executed
4+
exit-code: 0
5+
6+
should also be executed:
7+
command: echo executed
8+
exit-code: 0
9+
10+
executed at the beginning is ignored:
11+
command: echo ignored
12+
exit-code: 0
13+
14+
should be ignored:
15+
command: echo filtered
16+
exit-code: 0

pkg/app/test_command.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestCommand(testPath string, ctx AddCommandContext) error {
3939
default:
4040
fmt.Println("Starting test file " + testPath + "...")
4141
fmt.Println("")
42-
result, err = testFile(testPath, ctx.Filters)
42+
result, err = testFile(testPath, "", ctx.Filters)
4343
}
4444

4545
if err != nil {
@@ -85,17 +85,16 @@ func convergeResults(result runtime.Result, new runtime.Result) runtime.Result {
8585
return result
8686
}
8787

88-
func testFile(filePath string, fileName string, filters runtime.Filters) (<-chan runtime.TestResult, error) {
89-
content, err := readFile(filePath, fileName)
88+
func testFile(filePath string, fileName string, filters runtime.Filters) (runtime.Result, error) {
89+
s, err := readFile(filePath, fileName)
9090
if err != nil {
9191
return runtime.Result{}, fmt.Errorf("Error " + err.Error())
9292
}
9393

94-
return execute(content, filters)
94+
return execute(s, filters)
9595
}
9696

97-
func execute(s suite.Suite, title string) (runtime.Result, error)
98-
{
97+
func execute(s suite.Suite, filters runtime.Filters) (runtime.Result, error) {
9998
tests := s.GetTests()
10099
if len(filters) != 0 {
101100
tests = []runtime.TestCase{}

pkg/app/test_command_linux_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package app
22

33
import (
4-
"github.com/SimonBaeumer/commander/pkg/runtime"
5-
"github.com/stretchr/testify/assert"
64
"io/ioutil"
75
"testing"
6+
7+
"github.com/commander-cli/commander/pkg/runtime"
8+
"github.com/stretchr/testify/assert"
89
)
910

1011
const TestSuiteFile = "/tmp/commander_test.yaml"

0 commit comments

Comments
 (0)