@@ -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
2224func 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+
85112func 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}
0 commit comments