Agent Skills › meshery/meshery › gen-test

gen-test

GitHub

为 Meshery 项目的 Go 包和 Handler 生成符合规范的测试代码。支持自动读取目标文件和现有测试风格,遵循表格驱动、httptest 及 testify 等约定,覆盖成功/错误路径及边界情况,适用于 handler、model 和 CLI 命令测试。

.agents/skills/gen-test/SKILL.md meshery/meshery

Trigger Scenarios

需要为 Go 文件生成单元测试 需要补充 HTTP Handler 或 CLI 命令的测试用例

Install

npx skills add meshery/meshery --skill gen-test -g -y
More Options

Non-standard path

npx skills add https://github.com/meshery/meshery/tree/master/.agents/skills/gen-test -g -y

Use without installing

npx skills use meshery/meshery@gen-test

指定 Agent (Claude Code)

npx skills add meshery/meshery --skill gen-test -a claude-code -g -y

安装 repo 全部 skill

npx skills add meshery/meshery --all -g -y

预览 repo 内 skill

npx skills add meshery/meshery --list

SKILL.md

Frontmatter
{
    "name": "gen-test",
    "tools": [
        "search\/changes",
        "search\/codebase",
        "edit\/editFiles",
        "vscode\/extensions",
        "web\/fetch",
        "web\/githubRepo",
        "vscode\/getProjectSetupInfo",
        "vscode\/installExtension",
        "vscode\/newWorkspace",
        "vscode\/runCommand",
        "vscode\/openSimpleBrowser",
        "read\/problems",
        "execute\/getTerminalOutput",
        "execute\/runInTerminal",
        "read\/terminalLastCommand",
        "read\/terminalSelection",
        "execute\/createAndRunTask",
        "execute",
        "execute\/runTask",
        "execute\/runTests",
        "search",
        "search\/searchResults",
        "execute\/testFailure",
        "search\/usages",
        "vscode\/vscodeAPI",
        "github\/*",
        "memory"
    ],
    "description": "Generate idiomatic tests for Go packages and handlers in the Meshery project."
}

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

  1. Read the target file to understand its exported functions, methods, and types.
  2. Read existing tests in the same package (look for *_test.go files) to match the project's testing style.
  3. Generate tests following these conventions:

Go Test Conventions

  • Use table-driven tests with t.Run subtests
  • Name test functions Test<FunctionName> or Test<Type>_<Method>
  • Use testify/assert or testify/require if already used in the package; otherwise use standard library
  • For HTTP handlers, use httptest.NewRecorder() and httptest.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)
            }
        })
    }
}

Version History

  • 2e666fd Current 2026-08-20 16:24

Same Skill Collection

.agents/skills/agent-md-refactor/SKILL.md
.agents/skills/api-doc/SKILL.md
.agents/skills/chrome-devtools-axi/SKILL.md
.agents/skills/command-creator/SKILL.md
.agents/skills/database-schema-designer/SKILL.md
.agents/skills/gen-relationship/SKILL.md
.agents/skills/gepetto/SKILL.md
.agents/skills/gh-axi/SKILL.md
.agents/skills/gnhf/SKILL.md
.agents/skills/iterate-pr/SKILL.md
.agents/skills/lavish/SKILL.md
.agents/skills/qa-test-planner/SKILL.md
.agents/skills/quota-axi/SKILL.md
.agents/skills/reducing-entropy/SKILL.md
.agents/skills/cut-release/SKILL.md
.agents/skills/find-skills/SKILL.md

Metadata

Files
0
Version
3783392
Hash
5b69244e
Indexed
2026-08-20 16:24

Accueil - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-09-29 16:40
浙ICP备14020137号-1