wgc router grpc-plugin test

The test command runs tests for your gRPC router plugin to verify its functionality.

Usage

wgc router grpc-plugin test [options] [directory]

Arguments

ArgumentDescriptionDefault
directoryDirectory of the plugin. (current directory)

Options

OptionDescriptionDefault
--skip-tools-installationSkip tool installationfalse
--force-tools-installationForce tools installation regardless of version check or confirmationfalse

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:

  1. Check and install required tools if needed
  2. Run Go tests in the src directory
  3. 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:

ToolVersionInstallation Link
Go>=1.22.0 (Last 2 versions)Releases
Protocol Buffers (protoc)^29.3Releases
protoc-gen-go^1.34.2GitHub Releases
protoc-gen-go-grpc^1.5.1GitHub 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

wgc router grpc-plugin test ./my-plugin

Best Practices

When writing tests for your gRPC plugin:

  1. Test all resolvers: Make sure to create test cases for all your GraphQL resolvers
  2. Test edge cases: Include tests for error conditions and edge cases
  3. Mock dependencies: If your plugin interacts with external systems, use mocks in your tests
  4. Test arguments: Verify that your resolvers correctly handle different argument values
  5. 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.