Gen Test
Testing & Qualitygen-testGen Test is an Agent Skill for testing & quality published in the meshery/meshery repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.
Generate idiomatic tests for Go packages and handlers in the Meshery project.
QUICK START
How to use this skill
Bring this guide into your coding agent with a prompt tailored to the tool you use.
- Open your project in Codex.
- Copy and paste the prompt below.
- Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/meshery/meshery/blob/HEAD/.agents/skills/gen-test/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/gen-test, but wait for my approval before writing files or running scripts.
Copying this prompt does not install or run the skill. Review third-party files before use.
Skill: gen-test
Generate idiomatic tests for Go packages and handlers in the Meshery project.
Usage
Invoke this skill with a target file or package path:
/gen-test server/handlers/provider_handler.go/gen-test mesheryctl/internal/cli/root/system/start.go
Instructions
- Read the target file to understand its exported functions, methods, and types.
- Read existing tests in the same package (look for
*_test.gofiles) to match the project's testing style. - Generate tests following these conventions:
Go Test Conventions
- Use table-driven tests with
t.Runsubtests - Name test functions
Test<FunctionName>orTest<Type>_<Method> - Use
testify/assertortestify/requireif already used in the package; otherwise use standard library - For HTTP handlers, use
httptest.NewRecorder()andhttptest.NewRequest() - Mock external dependencies using interfaces — check if mock implementations already exist in the package
- Test both success and error paths
- Include edge cases: nil inputs, empty strings, boundary values
File Placement
- Place test files in the same directory as the source file
- Name:
<source_file>_test.go(or append to existing test file if one exists)
What to Test
For handlers (server/handlers/):
- HTTP status codes for valid and invalid requests
- Response body structure
- Authentication/authorization checks (if applicable)
- Input validation errors
For models (server/models/):
- Struct method behavior
- Serialization/deserialization
- Validation logic
For mesheryctl commands (mesheryctl/):
- Command output for various flag combinations
- Error messages for invalid input
- Exit codes
Example Pattern
func TestHandlerName(t *testing.T) {
tests := []struct {
name string
method string
path string
body string
expectedStatus int
}{
{
name: "valid request",
method: http.MethodGet,
path: "/api/resource",
expectedStatus: http.StatusOK,
},
{
name: "missing required field",
method: http.MethodPost,
path: "/api/resource",
body: `{}`,
expectedStatus: http.StatusBadRequest,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
req := httptest.NewRequest(tt.method, tt.path, strings.NewReader(tt.body))
rec := httptest.NewRecorder()
handler.ServeHTTP(rec, req)
if rec.Code != tt.expectedStatus {
t.Errorf("expected status %d, got %d", tt.expectedStatus, rec.Code)
}
})
}
}