monkey

package
v0.0.0-...-cf25b83 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2021 License: MIT Imports: 1 Imported by: 0

README

gotests-complex-function example

Using the go tool gotests to test a function with complex inputs and outputs.

GitHub Webpage

WHAT IS GOTESTS

gotests makes writing go tests easy. It's a golang cli that generates table driven tests based on its target source files' function and method signatures.

Install,

go get -u github.com/cweill/gotests/...

THE FUNCTION TO TEST

The function Check() has the following input/outputs.

func Check(input InputJSON, logger *log.Logger) (checkOutputJSON, error) {

where,

version struct {
    Ref string `json:"ref"`
}

InputJSON struct {
    Params  map[string]string `json:"params"`
    Source  map[string]string `json:"source"`
    Version version           `json:"version"`
}

checkOutputJSON []version

HOW I GENERATED THE TEST FILE

gotests -w -all complex-function.go

Refer to this file to see how I added tests.

RUN TEST & COVERAGE

go test -v -cover .
go test -coverprofile coverage.out
go tool cover -html=coverage.out -o coverage.html

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(input InputJSON, logger *log.Logger) (checkOutputJSON, error)

Check will return a new versions of a resource.

Types

type InputJSON

type InputJSON struct {
	Params  map[string]string `json:"params"`
	Source  map[string]string `json:"source"`
	Version version           `json:"version"`
}

InputJSON ...

Jump to

Keyboard shortcuts

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