Skip to content

Commit 9ada839

Browse files
committed
merge master
2 parents d8f0056 + bb33069 commit 9ada839

33 files changed

Lines changed: 3196 additions & 5 deletions

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# v2.4.0
2+
3+
- Add ability to test suite from a url
4+
15
# v2.3.0
26

37
- Preserve test execution order alphabetical order

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ $ ./commander test /tmp/test.yaml
203203
# Execute a single test
204204
$ ./commander test /tmp/test.yaml "my test"
205205

206+
# Execute suite from url
207+
$ ./commander test https://raw.githubusercontent.com/commander-cli/commander/master/integration/unix/commander_test.yaml
208+
206209
# Execute suites within a test directory
207210
$ ./commander test --dir /tmp
208211
```

commander_unix.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,15 @@ tests:
123123
✓ [local] a
124124
✓ [local] b
125125
exit-code: 0
126+
127+
it should execute test from url:
128+
config:
129+
env:
130+
USER: from_parent
131+
command: ./commander test https://raw.githubusercontent.com/commander-cli/commander/master/integration/unix/commander_test.yaml
132+
stdout:
133+
contains:
134+
- ✓ [local] it should exit with error code
135+
- "- [local] it should skip, was skipped"
136+
line-count: 17
137+
exit-code: 0

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ require (
2020
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2
2121
golang.org/x/net v0.0.0-20191014212845-da9a3fd4c582 // indirect
2222
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
23+
gopkg.in/h2non/gock.v1 v1.0.15
2324
gopkg.in/yaml.v2 v2.2.4
2425
)
2526

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKoh
1818
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
1919
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
2020
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
21+
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
22+
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
2123
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
2224
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
2325
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
@@ -26,6 +28,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
2628
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
2729
github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e h1:9MlwzLdW7QSDrhDjFlsEYmxpFyIoXmYRon3dt0io31k=
2830
github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
31+
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4=
32+
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
2933
github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ=
3034
github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
3135
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -61,6 +65,8 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
6165
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
6266
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
6367
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
68+
gopkg.in/h2non/gock.v1 v1.0.15 h1:SzLqcIlb/fDfg7UvukMpNcWsu7sI5tWwL+KCATZqks0=
69+
gopkg.in/h2non/gock.v1 v1.0.15/go.mod h1:sX4zAkdYX1TRGJ2JY156cFspQn4yRWn6p9EMdODlynE=
6470
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
6571
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
6672
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=

integration/unix/remote_http.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
tests:
2+
hello world:
3+
command: echo hello world
4+
stdout: hello world
5+
exit-code: 0

pkg/app/test_command.go

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import (
55
"fmt"
66
"io/ioutil"
77
"log"
8+
"net/http"
89
"os"
910
"path"
11+
"strings"
1012

1113
"github.com/commander-cli/commander/pkg/output"
1214
"github.com/commander-cli/commander/pkg/runtime"
@@ -17,8 +19,8 @@ var out output.OutputWriter
1719

1820
// TestCommand executes the test argument
1921
// testPath is the path to the test suite config, it can be a dir or file
20-
// ctx holds the command flags. If directory scanning is enabled with --dir it is
21-
// not supported to filter tests, therefore testFilterTitle is an empty string
22+
// ctx holds the command flags. If directory scanning is enabled with --dir,
23+
// test filtering is not supported
2224
func TestCommand(testPath string, ctx TestCommandContext) error {
2325
if ctx.Verbose {
2426
log.SetOutput(os.Stdout)
@@ -41,6 +43,10 @@ func TestCommand(testPath string, ctx TestCommandContext) error {
4143
fmt.Println("Starting test from stdin...")
4244
fmt.Println("")
4345
result, err = testStdin(ctx.Filters)
46+
case isURL(testPath):
47+
fmt.Println("Starting test from " + testPath + "...")
48+
fmt.Println("")
49+
result, err = testURL(testPath, ctx.Filters)
4450
default:
4551
fmt.Println("Starting test file " + testPath + "...")
4652
fmt.Println("")
@@ -62,7 +68,7 @@ func testDir(directory string, filters runtime.Filters) (runtime.Result, error)
6268
result := runtime.Result{}
6369
files, err := ioutil.ReadDir(directory)
6470
if err != nil {
65-
return result, fmt.Errorf(err.Error())
71+
return result, fmt.Errorf("Error: Input is not a directory")
6672
}
6773

6874
for _, f := range files {
@@ -82,6 +88,27 @@ func testDir(directory string, filters runtime.Filters) (runtime.Result, error)
8288
return result, nil
8389
}
8490

91+
func testURL(url string, filters runtime.Filters) (runtime.Result, error) {
92+
resp, err := http.Get(url)
93+
if err != nil {
94+
return runtime.Result{}, err
95+
}
96+
defer resp.Body.Close()
97+
98+
body, err := ioutil.ReadAll(resp.Body)
99+
if err != nil {
100+
return runtime.Result{}, err
101+
}
102+
103+
s := suite.ParseYAML(body, "")
104+
105+
return execute(s, filters)
106+
}
107+
108+
func isURL(s string) bool {
109+
return strings.HasPrefix(s, "http://") || strings.HasPrefix(s, "https://")
110+
}
111+
85112
func convergeResults(result runtime.Result, new runtime.Result) runtime.Result {
86113
result.TestResults = append(result.TestResults, new.TestResults...)
87114
result.Failed += new.Failed
@@ -137,7 +164,7 @@ func execute(s suite.Suite, filters runtime.Filters) (runtime.Result, error) {
137164
return result, nil
138165
}
139166

140-
func readFile(filePath string, filName string) (suite.Suite, error) {
167+
func readFile(filePath string, fileName string) (suite.Suite, error) {
141168
s := suite.Suite{}
142169

143170
f, err := os.Stat(filePath)
@@ -154,7 +181,7 @@ func readFile(filePath string, filName string) (suite.Suite, error) {
154181
return s, err
155182
}
156183

157-
s = suite.ParseYAML(content, filName)
184+
s = suite.ParseYAML(content, fileName)
158185

159186
return s, nil
160187
}

pkg/app/test_command_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
commanderRuntime "github.com/commander-cli/commander/pkg/runtime"
1414
"github.com/stretchr/testify/assert"
15+
"gopkg.in/h2non/gock.v1"
1516
)
1617

1718
func Test_TestCommand_Verbose(t *testing.T) {
@@ -68,6 +69,45 @@ func Test_TestCommand_Dir(t *testing.T) {
6869
}
6970
}
7071

72+
func Test_TestCommand_Dir_Err(t *testing.T) {
73+
err := TestCommand("http://foo.com/bar", TestCommandContext{Dir: true})
74+
75+
if runtime.GOOS == "windows" {
76+
assert.Contains(t, err.Error(), "Error: Input is not a directory")
77+
} else {
78+
assert.Equal(t, "Error: Input is not a directory", err.Error())
79+
}
80+
}
81+
82+
func Test_TestCommand_Http(t *testing.T) {
83+
defer gock.Off()
84+
85+
gock.New("http://foo.com").
86+
Get("/bar").
87+
Reply(200).
88+
BodyString(`
89+
tests:
90+
echo hello:
91+
exit-code: 0
92+
`)
93+
94+
out := captureOutput(func() {
95+
TestCommand("http://foo.com/bar", TestCommandContext{Verbose: true})
96+
})
97+
98+
assert.Contains(t, out, "✓ [local] echo hello")
99+
}
100+
101+
func Test_TestCommand_Http_Err(t *testing.T) {
102+
err := TestCommand("http://error/not/a/url", TestCommandContext{Dir: false})
103+
104+
if runtime.GOOS == "windows" {
105+
assert.NotNil(t, err)
106+
} else {
107+
assert.NotNil(t, err)
108+
}
109+
}
110+
71111
func Test_ConvergeResults(t *testing.T) {
72112
duration, _ := time.ParseDuration("5s")
73113

vendor/github.com/h2non/parth/LICENSE

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)