tests-generator

command module
v0.0.0-...-9ac6608 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2019 License: MIT Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

WIP: tests-generator CircleCI

Generate tests for your routes based on a declaration file (yaml)

Usage

This projects aims to generate tests for your API's routes. It tries to follow table driven tests philosophy. The goal is to declare your test in a conf file written in yaml and generates it as it quite a repetetive process.

The specs file consist of a list of test defined as follow:

suite:
  - name: GetIndex # The name of the test functions => TestGetIndex(t *testing.T)
    method: GET # The route method
    path: / # The route path
    query: '?page=0' # Optional query parameters to pass
    body: '{}' # Optional stringified body to send
    response:
      status: 200 # The expected response status code
      body: `[{...}]` # The expected stringified response

To be able to generate test your package you need to have a function returning the http.Handler to test.

Assuming this function is called NewRouter, is in the api package, and your specs file is api/specs.yaml, create the file api/api_test.go with content:

//go:generate tests-generator --specs-file ./specs.yaml --pkg api --handler-func NewRouter
package api

Then simply go in api and run go generate.

Todos

  • Better handling of target package (Use of go generate kinda handle that)
  • Pass parameters to handler func
  • Handles other types of body than application/json
  • Use openapi parser to define response/request bodies
  • Give option to compare response to openapi spec

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
example module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址