wgc router plugin test
The test command runs tests for your gRPC router plugin to verify its functionality.
Usage
wgc router plugin test [options] [directory]
Arguments
| Argument | Description | Default |
|---|
directory | Directory of the plugin | . (current directory) |
Options
| Option | Description | Default |
|---|
--skip-tools-installation | Skip tool installation | false |
--force-tools-installation | Force tools installation regardless of version check or confirmation | false |
Description
This command runs the tests for your plugin. For Go plugins, it executes the Go test runner against the test files in your source directory.
The test command will:
- Check and install required tools if needed
- Run the tests in the
src directory
- Report the test results
Testing your plugin is an important step to ensure that your resolvers work correctly before deploying the plugin to your router.
The build command will automatically check for and install the necessary toolchain (like protoc, protoc-gen-go, etc.) when required tools can’t be found in the right version on your system. You can control this behavior with the --skip-tools-installation and --force-tools-installation flags.
For debugging your plugin, use the --debug flag to build with debug symbols. This enables debugging with tools like Delve, GoLand, or VS Code. See the debugging guide for detailed instructions.
You can also install the dependencies manually and use an IDE with Go support. The following table shows the current versions and download links for the required tools:
| Tool | Version | Installation Link |
|---|
| Go | >=1.22.0 (Last 2 versions) | Releases |
| Protocol Buffers (protoc) | ^29.3 | Releases |
| protoc-gen-go | ^1.34.2 | GitHub Releases |
| protoc-gen-go-grpc | ^1.5.1 | GitHub Releases |
| bun | ^1.0.35 | GitHub Releases |
When building TypeScript plugins, the protoc TS/JS equivalents of the above are obtained via the .bin folder in your plugins node_modules, these versions can be customized by the package.json of the TS plugin.
Test File
When you initialize a new plugin with wgc router plugin init, a test file is automatically created at src/main_test.go. This file includes a basic test setup that you can expand with your own test cases.
The default test file tests the plugin’s ability to handle basic GraphQL queries. You should add additional tests to cover your custom resolver logic.
Examples
Run tests for a plugin
wgc router plugin test ./my-plugin
Best Practices
When writing tests for your router plugin:
- Test all resolvers: Make sure to create test cases for all your GraphQL resolvers
- Test edge cases: Include tests for error conditions and edge cases
- Mock dependencies: If your plugin interacts with external systems, use mocks in your tests
- Test arguments: Verify that your resolvers correctly handle different argument values
- Benchmark performance: Add benchmarks for performance-critical resolvers
By thoroughly testing your plugin, you can ensure it behaves correctly when integrated with the Cosmo Router.
See also: Plugins · GraphQL Support for gRPC Integration