Skip to content

Commit

Permalink
Update to webrpc@v0.10.0 test suite (#5)
Browse files Browse the repository at this point in the history
* 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
VojtechVitek committed Dec 31, 2022
1 parent 4a4d466 commit 87775b4
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 49 deletions.
50 changes: 24 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,6 @@ on:
- "**"

jobs:
test-client:
strategy:
matrix:
webrpc-gen: [v0.9.1]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
run: |
cd tests/
npm install
- name: Add webrpc binaries to path
run: |
mkdir -p bin
curl -L -o webrpc-test https://github.com/webrpc/webrpc/releases/download/${{ matrix.webrpc-gen }}/webrpc-test.linux-amd64
curl -L -o webrpc-gen https://github.com/webrpc/webrpc/releases/download/${{ matrix.webrpc-gen }}/webrpc-gen.linux-amd64
chmod +x webrpc-test
chmod +x webrpc-gen
mv -t bin/ webrpc-test webrpc-gen
echo "$(pwd)/bin/" >> $GITHUB_PATH
- name: Run tests
run: |
VERSION=${{ matrix.webrpc-gen }} make test
test:
runs-on: ubuntu-latest
steps:
Expand All @@ -52,3 +26,27 @@ jobs:
run: cd _examples && make generate
- name: Git diff of regenerated files
run: cd _examples && make diff

webrpc-interoperability:
strategy:
matrix:
webrpc-version: [v0.10.0]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Set up webrpc binary cache folder
uses: actions/cache@v3
with:
key: webrpc-binaries
path: tests/bin
- name: Install dependencies
run: cd tests && npm install
- name: Download webrpc binaries
run: cd tests && ./download.sh ${{ matrix.webrpc-version }} bin/${{ matrix.webrpc-version }}
- name: Export path of webrpc binaries
run: cd tests && echo "$PWD/bin/${{ matrix.webrpc-version }}" >> $GITHUB_PATH
- name: Run interoperability tests
run: cd tests && ./test.sh
8 changes: 0 additions & 8 deletions Makefile

This file was deleted.

3 changes: 2 additions & 1 deletion tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bin/
node_modules/
api.ridl
test.ridl
client.ts
15 changes: 15 additions & 0 deletions tests/README.md
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
```
11 changes: 0 additions & 11 deletions tests/complex.spec.ts

This file was deleted.

20 changes: 20 additions & 0 deletions tests/download.sh
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
7 changes: 4 additions & 3 deletions tests/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "gen-typescript",
"name": "gen-typescript-test",
"version": "1.0.0",
"description": "Typescript generator",
"description": "Webrpc TypeScript generator test",
"main": "index.js",
"scripts": {
"test": "./node_modules/.bin/vitest run --reporter verbose --dir ./"
"test": "./test.sh",
"vitest": "./node_modules/.bin/vitest run --reporter verbose --dir ./"
},
"repository": {
"type": "git",
Expand Down
14 changes: 14 additions & 0 deletions tests/test.sh
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
38 changes: 38 additions & 0 deletions tests/test.spec.ts
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();
});
});

0 comments on commit 87775b4

Please sign in to comment.