https://github.com/dylibso/testing-xtp-plugins
An end-to-end example of testing XTP plugins which call host functions + example mocked host functions.
https://github.com/dylibso/testing-xtp-plugins
example golang host mock testing typescript wasm xtp zig
Last synced: 5 months ago
JSON representation
An end-to-end example of testing XTP plugins which call host functions + example mocked host functions.
- Host: GitHub
- URL: https://github.com/dylibso/testing-xtp-plugins
- Owner: dylibso
- License: bsd-3-clause
- Created: 2024-08-20T17:35:53.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-11T17:11:34.000Z (12 months ago)
- Last Synced: 2025-03-27T13:47:39.384Z (10 months ago)
- Topics: example, golang, host, mock, testing, typescript, wasm, xtp, zig
- Language: Zig
- Homepage: https://docs.xtp.dylibso.com/docs/concepts/testing-plugins
- Size: 21.5 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Testing XTP Plugins with Host Functions
## Repository Overview
### `mock`
This directory contains the implementation of the mocked host functions. Note
that these functions are Extism plugin exports, which become imports to the
plugin that calls the host functions.
### `plugin`
This directory contains an example XTP plugin, based on the `schema.yaml`
schema. It calls the host functions from its export `handleLogEvent` and
aggregates the count of events per event source. We test this plugin's behavior
and the host function integration by running it several times with different
inputs to see that the KV data and plugin aggregation of that data is correct.
### `test`
This directory contains the test code that calls into the code in `plugin` to
test various aspects of it.
## Building
Before compiling the contents, please ensure that you have the following
installed:
- [`xtp`](https://docs.xtp.dylibso.com/docs/cli#installation) (any recent
version)
- [`tinygo`](https://tinygo.org/getting-started/install/) (>= 0.31.2)
- [`zig`](https://ziglang.org/) (>= 0.13.0)
- [`extism-js`](https://github.com/extism/js-pdk?tab=readme-ov-file#install-the-compiler)
(>= 1.0.0-rc11)
- [`npm`](https://nodejs.org) (>= 10.2.4)
With all of the above installed, you can now run:
```sh
make build
```
## Testing
After you've built the `mock`, `plugin` and `test` modules, you can run:
```sh
make test
```
or:
```sh
cd plugin
xtp plugin test # note: the plugin/xtp.toml [[test]] configuration
```
## Questions or need help?
File [an issue](https://github.com/dylibso/testing-xtp-plugins/issues) on this
repository, or reach out to us on the
[Extism Discord](https://extism.org/discord) and we can provide assistance.