{"id":22862407,"url":"https://github.com/dylibso/xtp-test-go","last_synced_at":"2026-04-24T16:38:06.777Z","repository":{"id":232877050,"uuid":"785413317","full_name":"dylibso/xtp-test-go","owner":"dylibso","description":"A Go test framework for xtp / Extism plugins.","archived":false,"fork":false,"pushed_at":"2024-05-22T22:30:52.000Z","size":1067,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-10-31T09:15:42.108Z","etag":null,"topics":["extism","plugins","testing","unit-testing","wasm","webassembly"],"latest_commit_sha":null,"homepage":"https://extism.org/docs/concepts/testing/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dylibso.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-11T20:57:56.000Z","updated_at":"2024-05-28T00:20:18.000Z","dependencies_parsed_at":"2024-05-21T06:30:25.981Z","dependency_job_id":"203085ca-0b2e-4fed-bf15-d802a5a3f842","html_url":"https://github.com/dylibso/xtp-test-go","commit_stats":null,"previous_names":["dylibso/xtp-test-go"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/dylibso/xtp-test-go","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dylibso%2Fxtp-test-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dylibso%2Fxtp-test-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dylibso%2Fxtp-test-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dylibso%2Fxtp-test-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dylibso","download_url":"https://codeload.github.com/dylibso/xtp-test-go/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dylibso%2Fxtp-test-go/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32231232,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T13:21:15.438Z","status":"ssl_error","status_checked_at":"2026-04-24T13:21:15.005Z","response_time":64,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["extism","plugins","testing","unit-testing","wasm","webassembly"],"created_at":"2024-12-13T10:13:27.916Z","updated_at":"2026-04-24T16:38:06.742Z","avatar_url":"https://github.com/dylibso.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# xtp-test\n\nA Go test framework for [xtp](https://getxtp.com) / [Extism](https://extism.org)\nplugins.\n\n## Example\n\n```go\npackage main\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\n\txtptest \"github.com/dylibso/xtp-test-go\"\n)\n\n// You _must_ export a single `test` function in order for the test runner to call something\n//\n//go:export test\nfunc test() int32 {\n\t// call the tested plugin's \"count_vowels\" function, passing it some data\n\toutput := xtptest.CallString(\"count_vowels\", []byte(\"hello\"))\n\t// check that the output is as expected\n\txtptest.AssertNe(\"we got some output\", output, \"\")\n\n\t// create a named group of tests. NOTE: plugin state is reset before and after the group runs.\n\txtptest.Group(\"check how fast the function performs\", func() {\n\t\t// check the amount of time in seconds or nanoseconds spent in the plugin function.\n\t\tsec := xtptest.TimeSeconds(\"count_vowels\", []byte(\"hello\"))\n\t\txtptest.AssertLt(\"it should be fast\", sec, 0.1)\n\t\tns := xtptest.TimeNanos(\"count_vowels\", []byte(\"hello\"))\n\t\txtptest.AssertLt(\"it should be really fast\", ns, 300000)\n\t})\n\n\txtptest.Group(\"check that count_vowels maintains state\", func() {\n\t\taccumTotal := 0\n\t\tfor i := 0; i \u003c 10; i++ {\n\t\t\tc := fromJson(xtptest.CallBytes(\"count_vowels\", []byte(\"this is a test\")))\n\t\t\taccumTotal += c.Count\n\t\t\txtptest.AssertEq(fmt.Sprintf(\"total should be incremented to: %d\", accumTotal), c.Total, accumTotal)\n\t\t}\n\t})\n\n\t// as this is an Extism plugin, return a status/error code\n\treturn 0\n}\n\nfunc fromJson(data []byte) CountVowels {\n\tvar res CountVowels\n\t_ = json.Unmarshal(data, \u0026res)\n\treturn res\n}\n\ntype CountVowels struct {\n\tVowels string `json:\"vowels\"`\n\tTotal  int    `json:\"total\"`\n\tCount  int    `json:\"count\"`\n}\n\nfunc main() {}\n```\n\n## API Docs\n\nPlease see the [**`godoc`**](https://pkg.go.dev/github.com/dylibso/xtp-test-go)\ndocumentation page for full details.\n\n## Usage\n\n**1. Create a Go project using the XTP Test package**\n\n```sh\nmkdir plugintest \u0026\u0026 cd plugintest\ngo mod init \u003cyour module\u003e\ngo get github.com/dylibso/xtp-test-go\n```\n\n**2. Write your test in Go**\n\n```go\n// test.go\npackage main\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\n\txtptest \"github.com/dylibso/xtp-test-go\"\n)\n\n//go:export test\nfunc test() int32 {\n    // call the tested plugin's \"count_vowels\" function, passing it some data\n\toutput := xtptest.CallString(\"count_vowels\", []byte(\"hello\"))\n    // check that the output is as expected\n\txtptest.AssertNe(\"we got some output\", output, \"\")\n    // ...\n```\n\n**3. Compile your test to .wasm:**\n\nEnsure you have\n[`tinygo` installed](https://tinygo.org/getting-started/install/). Eventually\nyou can use the `go` compiler, but the test runner _must_ find an exported\n`test` function from the test plugin, and `go` cannot currently export any\nfunction other than `_start`.\n\n```sh\ntinygo build -o test.wasm -target wasi test.go\n```\n\n**4. Run the test against your plugin:** Once you have your test code as a\n`.wasm` module, you can run the test against your plugin using the `xtp` CLI:\n\n### Install `xtp`\n\n```sh\ncurl https://static.dylibso.com/cli/install.sh | sudo sh\n```\n\n### Run the test suite\n\n```sh\nxtp plugin test ./plugin-*.wasm --with test.wasm --mock-host host.wasm\n#               ^^^^^^^^^^^^^^^        ^^^^^^^^^             ^^^^^^^^^\n#               your plugin(s)         test to run           optional mock host functions\n```\n\n**Note:** The optional mock host functions must be implemented as Extism\nplugins, whose exported functions match the host function signature imported by\nthe plugins being tested.\n\n## Need Help?\n\nPlease reach out via the\n[`#xtp` channel on Discord](https://discord.com/channels/1011124058408112148/1220464672784908358).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdylibso%2Fxtp-test-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdylibso%2Fxtp-test-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdylibso%2Fxtp-test-go/lists"}