Skip to content

Commit

Permalink
sdk/test error message improvements (#521)
Browse files Browse the repository at this point in the history
* sdk/test error message improvements

* sdk/ts forgot to commit the better error messages

* Update README.md

---------

Co-authored-by: Ben Croker <57572400+bencroker@users.noreply.github.com>
  • Loading branch information
Superpat and bencroker authored Jan 24, 2025
1 parent 2b76713 commit f082567
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
10 changes: 4 additions & 6 deletions sdk/test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ Processing GET cases...
Processing POST cases...
```

If nothing else is outputted then all tests passed !
If nothing else is output then all tests passed!

Results of the test can be found in `./get_cases/$case_name/testOutput.txt` (or `post_cases` depending on the test).
Results of the test can be found in `./get_cases/$case_name/testOutput.txt` (or `post_cases` depending on the test).

Take note that these tests are stricter about data line ordering then the SDK spec is, but unless that becomes an actual problem I dont intend to fix it, since it would add complexity.
Take note that these tests are stricter about data line ordering then the SDK spec is, but unless that becomes an actual problem I dont intend to fix it, since it would add complexity.

## Adding new cases

Expand All @@ -27,6 +27,7 @@ Processing POST cases...
That folder must contain an `input.json` file and an `output.txt` file.

The `input.json` file must contain valid json of the following shape:

```
{"events":
[
Expand Down Expand Up @@ -54,7 +55,4 @@ data: attributes type text/javascript
data: attributes blocking false
data: autoRemove false
data: script console.log('hello');
```

6 changes: 3 additions & 3 deletions sdk/test/test-all.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/bin/sh

#!/bin/sh

# Check if an argument is provided
if [ -z "$1" ]; then
echo "Usage: $0 <argument>"
Expand All @@ -18,6 +16,7 @@ if [ -d "./get-cases" ]; then
./test-get.sh "$case" "$1"
fi
done
echo "Finished processing GET cases"
else
echo "Directory './get-cases' not found!"
fi
Expand All @@ -30,6 +29,7 @@ if [ -d "./post-cases" ]; then
./test-post.sh "$case" "$1"
fi
done
echo "Finished processing POST cases"
else
echo "Directory './post-cases' not found!"
fi
fi
5 changes: 5 additions & 0 deletions sdk/test/test-get.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
[ ! -f "$1/output.txt" ] && echo "case $1 does not have output.txt" && return 1

input=$(cat "$1/input.json")

rm "$1/testOutput.txt"

curl -sN --get --data-urlencode "datastar=$input" "$2/test" -o "$1/testOutput.txt"

[ ! -f "$1/testOutput.txt" ] && echo "case $1 failed: your server did not return anything" && return 1

diff -q "$1/testOutput.txt" "$1/output.txt"

return 0
4 changes: 4 additions & 0 deletions sdk/test/test-post.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
[ ! -f "$1/input.json" ] && echo "case $1 does not have input.json" && return 1
[ ! -f "$1/output.txt" ] && echo "case $1 does not have output.txt" && return 1

rm "$1/testOutput.txt"

input=$(cat "$1/input.json")
curl -sN --json "$input" "$2/test" -o "$1/testOutput.txt"

[ ! -f "$1/testOutput.txt" ] && echo "case $1 failed: your server did not return anything" && return 1

diff -q "$1/testOutput.txt" "$1/output.txt"

return 0

0 comments on commit f082567

Please sign in to comment.