Test
Run tests for a gRPC router plugin
wgc router grpc-plugin test
The test
command runs tests for your gRPC router plugin to verify its functionality.
Usage
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 Go 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.
Required Tools
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 |
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
Best Practices
When writing tests for your gRPC 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.