-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to webrpc@v0.10.0 test suite (#5)
* Update to webrpc@v0.10.0 test suite * Update to webrpc@v0.10.0 test schema; add README * Implement full webrpc@v0.10.0 test suite
- Loading branch information
1 parent
4a4d466
commit 87775b4
Showing
9 changed files
with
117 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
bin/ | ||
node_modules/ | ||
api.ridl | ||
test.ridl | ||
client.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Interoperability tests | ||
|
||
This folder implements webrpc interoperability tests. | ||
|
||
## Test matrix against webrpc-test reference binary | ||
|
||
1. Generate code | ||
2. Download webrpc binaries | ||
3. Test generated client and server code against multiple versions of `webrpc-test` reference binaries via [test.sh](./test.sh) script | ||
|
||
```bash | ||
./download.sh v0.10.0 bin/v0.10.0 | ||
export PATH="$PWD/bin/v0.10.0:$PATH" | ||
npm run test | ||
``` |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
VERSION="${1}" | ||
DIR="${2}" | ||
[[ -z "$VERSION" || -z "$DIR" ]] && { echo "Usage: $0 <webrpc-version> <dir>"; exit 1; } | ||
|
||
mkdir -p "$DIR" | ||
|
||
# Download webrpc binaries if not available locally | ||
OS="$(basename $(uname -o | tr A-Z a-z))" | ||
ARCH="$(uname -m | sed 's/x86_64/amd64/')" | ||
if [[ ! -f "$DIR/webrpc-gen" ]]; then | ||
curl -o "$DIR/webrpc-gen" -fLJO "https://github.com/webrpc/webrpc/releases/download/$VERSION/webrpc-gen.$OS-$ARCH" | ||
chmod +x "$DIR/webrpc-gen" | ||
fi | ||
if [[ ! -f "$DIR/webrpc-test" ]]; then | ||
curl -o "$DIR/webrpc-test" -fLJO "https://github.com/webrpc/webrpc/releases/download/$VERSION/webrpc-test.$OS-$ARCH" | ||
chmod +x "$DIR/webrpc-test" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
export PORT=9988 | ||
|
||
webrpc-test -version | ||
webrpc-test -print-schema > ./test.ridl | ||
webrpc-gen -schema=./test.ridl -target=typescript -client -out=./client.ts | ||
|
||
webrpc-test -server -port=$PORT -timeout=5s & | ||
|
||
# Wait until http://localhost:$PORT is available, up to 10s. | ||
for (( i=0; i<100; i++ )); do nc -z localhost $PORT && break || sleep 0.1; done | ||
|
||
npm run vitest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { TestApi } from "./client"; | ||
|
||
describe("Test interoperability with webrpc-test reference server", () => { | ||
const testApiClient = new TestApi( | ||
`http://localhost:${process.env.PORT}`, | ||
fetch | ||
); | ||
|
||
it("getEmpty() should get empty type successfully", async () => { | ||
await expect(testApiClient.getEmpty()).resolves.not.toThrowError(); | ||
}); | ||
|
||
it("getError() should throw error", async () => { | ||
await expect(() => testApiClient.getError()).rejects.toThrowError(); | ||
}); | ||
|
||
it("getOne() should receive simple type and send it back via sendOne() successfully", async () => { | ||
const complex = await testApiClient.getOne(); | ||
await expect( | ||
testApiClient.sendOne(complex, {}) | ||
).resolves.not.toThrowError(); | ||
}); | ||
|
||
it("getMulti() should receive simple type and send it back via sendMulti() successfully", async () => { | ||
const { one, two, three } = await testApiClient.getMulti(); | ||
await expect( | ||
testApiClient.sendMulti({ one, two, three }, {}) | ||
).resolves.not.toThrowError(); | ||
}); | ||
|
||
it("getComplex() should receive complex type and send it back via sendComplex() successfully", async () => { | ||
const complex = await testApiClient.getComplex(); | ||
await expect( | ||
testApiClient.sendComplex(complex, {}) | ||
).resolves.not.toThrowError(); | ||
}); | ||
}); |