Skip to content

Testing a codec

Each examples/*.json in a package is one call and what it must answer:

{
"fn": "encodeDownlink",
"input": {"ip": {"command": "status", "params": {}, "device": {"address": "192.168.1.20"},
"results": [{"ok": true, "status": 200, "body": "{\"on\": true}"}]}},
"expect": {"data": {"status": "done", "data": {"on": true}}}
}
Key
fn decodeUplink or encodeDownlink (the default)
input What the codec is called with
expect What its answer must hold

expect states only what matters: an object’s keys it leaves out are not compared, so an answer may carry more (a raw dump, a memo). Numbers compare by value (1 is 1.0), and true is not 1. Arrays compare whole.

For a codec that drives a device, record its real answers into results, and replace any real key or password in a recording with a made-up one before keeping it.

Command
pulzr-codec test <dir> [lib=path ...] Every example through the package’s codec, its libraries bundled. Prints one line an example and exits non-zero when one fails
pulzr-codec bundle <dir> [lib=path ...] Prints the codec with its library modules ahead of it
pulzr-codec run <customer|library> <fn> <codec.js> <input.json> One call

A library comes from GitHub at the tag device.json names (GITHUB_TOKEN is used when set, for the rate limit), or from a local directory given as name=path, which is how a library and the types built on it are tested together:

pulzr-codec test types/plug tuya=.
- run: |
curl -sSL https://github.com/pulzar-net/pulzr-codec/releases/download/v0.1.0/pulzr-codec-v0.1.0-x86_64-unknown-linux-gnu.tar.gz | tar xz
./pulzr-codec-*/pulzr-codec test types/plug