Skip to content

Commit

Permalink
added expect to test return status code
Browse files Browse the repository at this point in the history
  • Loading branch information
speier committed Nov 25, 2020
1 parent e43c23e commit fe14f86
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=v0.1.3
VERSION=v0.1.4

release:
@git tag -a ${VERSION} -m "Release ${VERSION}" && git push origin ${VERSION}
Expand Down
7 changes: 5 additions & 2 deletions examples/basic.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const host = 'https://httpbin.org'

// simple GET
GET(`${host}/get`)
GET(`${host}/get?foo=bar`)

// append header and POST data
POST(`${host}/post`, 'Accept: application/vnd.foobar.v2+json', { payload: { data: 'foobar' }})
POST(`${host}/post`, 'Accept: application/vnd.xxx.v2+json', { foo: { bar: 'baz' }})

// expect status code
expect(200, GET(`${host}/status/400`))
6 changes: 4 additions & 2 deletions pkg/req/req.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ func printres(host string, status int, body string, err error) {
fmt.Printf("\n[%d] %s\n%s\n", status, host, body)
}

func httpGet(host string, args ...interface{}) {
func httpGet(host string, args ...interface{}) int {
status, body, err := httpreq(http.MethodGet, host, args...)
printres(host, status, body, err)
return status
}

func httpPost(host string, args ...interface{}) {
func httpPost(host string, args ...interface{}) int {
status, body, err := httpreq(http.MethodPost, host, args...)
printres(host, status, body, err)
return status
}

func setHeader(args ...interface{}) {
Expand Down
5 changes: 5 additions & 0 deletions pkg/vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ func NewInterpreter(globals map[string]interface{}) VM {
runtime.Set("console", map[string]interface{}{
"log": fmt.Println,
})
runtime.Set("expect", func(a, b interface{}) {
if a != b {
fmt.Printf("[ERR] expected %v got %v\n", a, b)
}
})

if globals != nil {
for name, value := range globals {
Expand Down

0 comments on commit fe14f86

Please sign in to comment.