Categorygithub.com/msackman/argot
modulepackage
1.0.1
Repository: https://github.com/msackman/argot.git
Documentation: pkg.go.dev

# README

argot

A lightweight simple testing framework in Go. Comes with reasonable support for testing HTTP servers.

GoDoc available here: http://godoc.org/github.com/msackman/argot

Blog post available here: https://tech.labs.oliverwyman.com/blog/2017/04/21/argot-a-lightweight-composable-test-framework-for-go/

Build

go get github.com/msackman/argot

Example

Just to show off one example again:

package main

import (
    "errors"
    "github.com/msackman/argot"
    "net/http"
    "testing"
)

func AlwaysFails() argot.Step {
    return argot.NewNamedStep(
        "AlwaysSucceeds",
        func() error {
            return errors.New("nope")
        },
    )
}

func Testify(t *testing.T) {
    req := argot.NewHttpCall(nil)
    defer req.Reset()
    argot.Steps([]argot.Step{
        req.NewRequest("POST", server+"/api/v1/foo/bar", nil),
        req.RequestHeader("Content-Type", "application/json"),
        req.ResponseStatusEquals(http.StatusOK),
        req.ResponseHeaderEquals("Content-Type", "application/json"),
        req.ResponseHeaderNotExists("Magical-Response"),
        req.ResponseHeaderNotExists("No-Unicorns"),
        req.ResponseBodyEquals("Attack ships on fire off the shoulder of Orion...\n"),
        AlwaysFails(req),
    }).Test(t)
}

As a result running go test will output a helpful log in case any of the steps failed:

% go test
--- FAIL: Testify (0.24s)
        test.go:20: Achieved Steps:
               [NewRequest(POST: https://...)
                RequestHeader(Content-Type: application/json)
                ResponseStatusEquals(200)
                ResponseHeaderEquals(Content-Type: application/json)
                ResponseHeaderNotExists(Magical-Response)
                ResponseHeaderNotExists(No-Unicorns)]
               Error: nope
FAIL

# Functions

AnyError is a utility function that returns the first non-nil error in the slice, or nil if either the slice or all elements of the slice are nil.
NewHttpCall creates a new HttpCall.
NewNamedStep creates a NamedStep with the given name and Step function.

# Structs

HttpCall captures all the state relating to a single HTTP call.
NamedStep extends StepFunc by adding a name, which is mainly of use when formatting a Step.

# Interfaces

Step represents a step in a test.

# Type aliases

StepFunc is the basic type of a Step: a function that takes no arguments and returns an error.
If we can have a single Step, then we can have a slice of Steps representing the order of Steps in a larger unit.