Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
G

gonkey

> 测试质量
Open source

Gonkey - a testing automation tool

393 stars0 likes0 views
WebsiteGitHub

About

Gonkey - a testing automation tool

Gonkey: testing automation tool

View Russian version of this file here

Gonkey will test your services using their API. It can bomb the service with prepared requests and check the responses. Test scenarios are described in YAML-files.

Capabilities:

  • works with REST/JSON API
  • tests service API for compliance with OpenAPI-specs
  • seeds the DB with fixtures data (supports PostgreSQL, MySQL, Aerospike, Redis)
  • provides mocks for external services
  • can be used as a library and ran together with unit-tests
  • stores the results as an Allure report with TMS integration support (TestIT, Allure TestOps)
  • there is a JSON-schema to add autocomletion and validation for gonkey YAML files

Table of contents

  • Gonkey: testing automation tool
    • Table of contents
    • Using the CLI
    • Using gonkey as a library
    • Test scenario example
    • Test status
    • HTTP-request
    • HTTP-response
    • Variables
      • Assignment
        • In the description of the test
        • From the response of the previous test
        • From the response of currently running test
        • From a request caught by a mock
        • From environment variables or from env-file
        • From cases
    • multipart/form-data requests
      • Form
      • File upload
    • Fixtures
      • Deleting data from tables
      • Record templates
      • Record inheritance
      • Record linking
      • Expressions
      • Aerospike
      • Redis
    • Mocks
      • Running mocks while using gonkey as a library
      • Mocks definition in the test file
        • Request constraints (requestConstraints)
          • nop
          • bodyMatchesJSON
          • bodyJSONFieldMatchesJSON
          • pathMatches
          • queryMatches
          • queryMatchesRegexp
          • methodIs
          • headerIs
          • bodyMatchesText
          • bodyMatchesXML
        • Response strategies (strategy)
          • nop
          • file
          • constant
          • template
          • uriVary
          • methodVary
          • sequence
          • basedOnRequest
          • dropRequest
        • Calls count
    • Shell scripts usage
      • Script definition
      • Running a script with parameterization
    • A DB query
      • Test Format
      • Query definition
      • Definition of DB request response
      • DB request parameterization
      • Ignoring ordering in DB response
    • JSON-schema
      • Setup in Jetbrains IDE
      • Setup is VSCode IDE

Using the CLI

To test a service located on a remote host, use gonkey as a console util.

./gonkey -host -tests [-spec ] [-db_dsn -fixtures ] [-allure] [-v]

  • -spec path to a file or URL with the swagger-specs for the service
  • -host service host:port
  • -tests test file or directory
  • -db-type - database type. PostgreSQL, Aerospike, Redis are currently supported.
  • -aerospike_host when using Aerospike - connection URL in a form of host:port/namespace
  • -redis_url when using Redis - connection address, for example redis://user:password@localhost:6789/1?dial_timeout=1&db=1&read_timeout=6s&max_retries=2
  • -db_dsn DSN for the test DB (the DB will be cleared before seeding!), supports only PostgreSQL
  • -fixtures fixtures directory
  • -allure generate an Allure-report
  • -allure-format Allure report format: v2/json (modern JSON, default) or v1/xml (legacy XML)
  • -v verbose output
  • -debug debug output

You can't use mocks in this mode.

Using gonkey as a library

To integrate functional and native Go tests and run them together, use gonkey as a library.

Create a test file, for example func_test.go.

Import gonkey as a dependency to your project in this file.

go
import (
    "github.com/lamoda/gonkey/runner"
    "github.com/lamoda/gonkey/mocks"
)

Create a test function.

…

Starts from version 1.18.3, externally written fixture loader may be used for loading test data, if gonkey used as a library. To start using the custom loader, you need to import the custom module, that contains implementation of fixtures.Loader interface.

Example with a redis fixtures loader:

…

The tests can be now ran with go test, for example: go test ./....

Test scenario example

…

As you can see in this example, you can use Regexp for checking response body. It can be used for all body (if it's plaint text):

yaml
    response:
        200: "$matchRegexp(^xy+z$)"

or for elements of map/array (if it's JSON):

yaml
    response:
        200: |
          {
            "id": "$matchRegexp([\\w-]+)",
            "jsonrpc": "$matchRegexp([12].0)",
            "result": [
              "data": [
                  "$matchRegexp(ORDER[0]{3}[0-9])",
                  "$matchRegexp(ORDER[0]{3}[0-9])"
              ],
            ]
          }

Also, "?" in query is optional

Test status

status - a parameter, for specially mark tests, can have following values:

  • broken - do not run test, only mark it as broken
  • skipped - do not run test, skip it
  • focus - run only this specific test, and mark all other tests with unset status as skipped

Allure Metadata for TMS Integration

You can add Allure metadata to tests for integration with Test Management Systems (TestIT, Allure TestOps, etc.). Metadata is added in the allure section:

…

By default, gonkey generates reports in modern Allure 2 format (JSON). To use legacy XML format (Allure 1.x), specify -allure-format=v1 or GONKEY_ALLURE_FORMAT=v1.

Global TestIT Labels (RunWithTestingParams)

When using gonkey as a library, you can set default package and testClass labels globally via RunWithTestingParams:

go
runner.RunWithTesting(t, &runner.RunWithTestingParams{
    Server:          srv,
    TestsDir:        "cases",
    AllurePackage:   "api",           // Default package label for all tests
    AllureTestClass: "UserHandler",   // Default testClass label for all tests
})

These labels are used for TestIT integration and help organize tests by component (package) and implementation class (testClass). Typical values:

  • AllurePackage: "api", "cron", "consumer", "scheduler"
  • AllureTestClass: handler or method name, e.g., "OrdersHandler", "CreateUser"

Priority: Test-level labels (defined in YAML) always override these global defaults. This allows you to:

  1. Set common labels once in your test setup
  2. Override them for specific tests when needed

HTTP-request

method - a parameter for HTTP request type, the format is in the example above.

path - a parameter for URL path, the format is in the example above.

headers - a parameter for HTTP headers, the format is in the example above.

cookies - a parameter for cookies, the format is in the example above.

HTTP-response

response - the HTTP response body for the specified HTTP status codes.

responseHeaders - all HTTP response headers for the specified HTTP status codes.

Variables

You can use variables in the description of the test, the following fields are supported:

  • method
  • description
  • path
  • query
  • headers
  • request
  • response
  • dbQuery
  • dbResponse
  • mocks body
  • mocks headers
  • mocks requestConstraints
  • form

Example:

yaml
- method: "{{ $method }}"
  description: "{{ $description }}"
  path: "/some/path/{{ $pathPart }}"
  query: "{{ $query }}"
  headers:
    header1: "{{ $header }}"
  request: '{"reqParam": "{{ $reqParam }}"}'
  response:
    200: "{{ $resp }}"
  mocks:
    server_mock:
      strategy: constant
      body: >
        {
          "message": "{{ $mockParam }}"
        }
      statusCode: 200
  dbQuery: >
    SELECT id, name FROM testing_tools WHERE id={{ $sqlQueryParam }}
  dbResponse:
    - '{"id": {{ $sqlResultParam }}, "name": "gonkey"}'

You can assign values to variables in the following ways (priorities are from top to bottom):

  • in the description of the test
  • from the response of the previous test
  • from the response of currently running test
  • from a request caught by a mock of the previous test
  • from environment variables or from env-file

Assignment

In the description of the test

Example:

yaml
- method: "{{ $method }}"
  path: "/some/path/{{ $pathPart }}"
  variables:
    reqParam: "reqParam_value"
    method: "POST"
    pathPart: "part_of_path"
    query: "query_val"
    header: "header_val"
    resp: "resp_val"
  query: "{{ $query }}"
  headers:
    header1: "{{ $header }}"
  request: '{"reqParam": "{{ $reqParam }}"}'
  response:
    200: "{{ $resp }}"

From the response of the previous test

Example:

yaml
# if the response is plain text
- name: "get_last_post_id"
  ...
  variables_to_set:
          200: "id"

# if the response is JSON
- name: "get_last_post_info"
  variables_to_set:
          200:
            id: "id"
            title: "title"
            authorId: "author_info.id"

You can access nested fields like this:

"author_info.id"

Any nesting levels are supported.

From the response of currently running test

Example:

yaml
- name: Get info with database
  method: GET
  path: "/info/1"
  variables_to_set:
    200:
      golang_id: query_result.0.0
  response:
    200: '{"result_id": "1", "query_result": [[ {{ $golang_id }} , "golang"], [2, "gonkey"]]}'
  dbQuery: >
    SELECT id, name FROM testing_tools WHERE id={{ $golang_id }}
  dbResponse:
    - '{"id": {{ $golang_id}}, "name": "golang"}'

From a request caught by a mock

A mock can capture values of the request it receives into variables. Variables become available after the test finishes, so they can be used in subsequent tests.

Use variablesToSet on the mock definition (at the same level as strategy). The values are templates that read the incoming request using the same syntax as the template reply strategy: {{ .request.Json }}, {{ .request.Query "name" }} and {{ .request.Header "name" }}.

Short form:

yaml
- name: "create user"
  ...
  mocks:
    backend:
      strategy: constant
      body: '{"ok": true}'
      variablesToSet:
        capturedUserId: '{{ .request.Json.user.id }}'
        capturedPage:   '{{ .request.Query "page" }}'
        capturedToken:  '{{ .request.Header "X-Auth-Token" }}'

- name: "next test can use captured values"
  ...
  request: '{"user_id": "{{ $capturedUserId }}"}'

If the mock (more precisely, the definition holding variablesToSet) is called several times within one test, the value of the last call is stored by default. Use the full form with fromCall to keep the value of the first call instead:

yam

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Goautotestingfixturesmicroservicesmocks

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category测试质量
PricingOpen source

> Related tools

J
Jest
JavaScript 测试框架
P
Playwright
现代端到端测试框架
E
eslint-plugin-test-selectors
Enforces that data-test-id attributes are added to interactive DOM elements (JSX) to help with UI testing. JSX only.