Skip to content

Commit

Permalink
Merge pull request #64 from studio-b12/dev-v1.2
Browse files Browse the repository at this point in the history
Dev v1.2
  • Loading branch information
zekroTJA authored Jun 14, 2024
2 parents 27577be + 9eb521c commit 94bc7e7
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 135 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

- Added a new request option [`followredirects`](https://studio-b12.github.io/goat/goatfile/requests/options.html#followredirects). This is `true` by default, but can be set to `false` if redirects should not be followed transparently. [#61]

- Addeda new script builtin [`assert_eq`](https://studio-b12.github.io/goat/scripting/builtins.html#assert_eq), where you can pass two values which are compared and output for better error clarification.

# Minor Changes and Bug Fixes

- Fixed an issue when parsing file descriptors on Windows systems.
15 changes: 15 additions & 0 deletions docs/book/src/scripting/builtins.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
The following built-in functions are available in each script instance.

- [`assert`](#assert)
- [`assert_eq`](#assert_eq)
- [`print`](#print)
- [`println`](#println)
- [`info`](#info)
Expand Down Expand Up @@ -31,6 +32,20 @@ Takes an `expression` which, when evaluated to `false`, will throw an assert exc
assert(response.StatusCode >= 400, `Status code was ${response.StatusCode}`);
```

## `assert_eq`

```ts
function assert_eq(value: any, expected: any, fail_message?: string): void;
```

Takes a `value` and an `expected` value and deep-equals them. That means, that also contents of objects and lists are compared. If the comparison fails, it will throw an exception which will also display both compared values. You can also pass an additional `fail_message` to further specify the error output.

**Example**

```js
assert(response.StatusCode >= 400, `Status code was ${response.StatusCode}`);
```

## `print`

```ts
Expand Down
22 changes: 11 additions & 11 deletions e2e/cases/fileimport-parameterized/a/_a.goat
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ info(response)

var body = response.Body;

assert(response.StatusCode == 200);
assert(body.method == "POST");
assert(body.query.orderBy[0] == "date");
assert(body.query.filterBy[0] == "date");
assert(body.query.filterBy[1] == "name");
assert(body.query.filterBy[2] == "age");
assert(body.query.page[0] == "2");
assert(body.query.count[0] == "100");
assert(body.headers["Content-Type"][0] == "text/plain");
assert(body.headers["X-Foo"][0] == "bar");
assert(body.body_string == "some\nbody\ncontent");
assert_eq(response.StatusCode, 200, "status code");
assert_eq(body.method, "POST", "method");
assert_eq(body.query.orderBy[0], "date", "query.orderBy");
assert_eq(body.query.filterBy[0], "date", "query.filterBy.0");
assert_eq(body.query.filterBy[1], "name", "query.filterBy.1");
assert_eq(body.query.filterBy[2], "age", "query.filterBy.2");
assert_eq(body.query.page[0], "2", "query.page");
assert_eq(body.query.count[0], "100", "query.count");
assert_eq(body.headers["Content-Type"][0], "text/plain", "headers.content-type");
assert_eq(body.headers["X-Foo"][0], "bar", "headers.x-foo");
assert_eq(body.body_string, "some\nbody\ncontent", "body");
22 changes: 11 additions & 11 deletions e2e/cases/fileimport-parameterized/direct.goat
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ info(response)

var body = response.Body;

assert(response.StatusCode == 200);
assert(body.method == "POST");
assert(body.query.orderBy[0] == "date");
assert(body.query.filterBy[0] == "date");
assert(body.query.filterBy[1] == "name");
assert(body.query.filterBy[2] == "age");
assert(body.query.page[0] == "2");
assert(body.query.count[0] == "100");
assert(body.headers["Content-Type"][0] == "text/plain");
assert(body.headers["X-Foo"][0] == "bar");
assert(body.body_string == "some\nbody\ncontent");
assert_eq(response.StatusCode, 200, "status code");
assert_eq(body.method, "POST", "method");
assert_eq(body.query.orderBy[0], "date", "query.orderBy");
assert_eq(body.query.filterBy[0], "date", "query.filterBy.0");
assert_eq(body.query.filterBy[1], "name", "query.filterBy.1");
assert_eq(body.query.filterBy[2], "age", "query.filterBy.2");
assert_eq(body.query.page[0], "2", "query.page");
assert_eq(body.query.count[0], "100", "query.count");
assert_eq(body.headers["Content-Type"][0], "text/plain", "headers.content-type");
assert_eq(body.headers["X-Foo"][0], "bar", "headers.x-foo");
assert_eq(body.body_string, "some\nbody\ncontent", "body");
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.19

require (
github.com/alexflint/go-arg v1.5.0
github.com/dop251/goja v0.0.0-20240516125602-ccbae20bcec2
github.com/dop251/goja v0.0.0-20240610225006-393f6d42497b
github.com/golang/mock v1.6.0
github.com/joho/godotenv v1.5.1
github.com/stretchr/testify v1.8.1
Expand All @@ -13,23 +13,23 @@ require (
)

require (
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/BurntSushi/toml v1.4.0 // indirect
github.com/alexflint/go-scalar v1.2.0 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/lipgloss v0.10.0 // indirect
github.com/charmbracelet/lipgloss v0.11.0 // indirect
github.com/charmbracelet/x/ansi v0.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dlclark/regexp2 v1.11.0 // indirect
github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect
github.com/google/pprof v0.0.0-20240521024322-9665fa269a30 // indirect
github.com/google/pprof v0.0.0-20240528025155-186aa0362fba // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 94bc7e7

Please sign in to comment.