Categorygithub.com/golib/assert
repositorypackage
1.8.0
Repository: https://github.com/golib/assert.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# README

assert

CircleCI

golang assert helpers modified from testify

Assertions allow you to easily write testing codes, and are global funcs in the assert package. All assertion funcs take, as the first argument, the *testing.T object provided by the testing framework. This allows the assertion funcs to write the failings and other details to the correct place.

Every assertion func also takes an optional string message as the final argument, allowing custom error messages to be appended to the message the assertion method outputs.

Basic Usage

import (
    "testing"

    "github.com/golib/assert"
)

func TestSomething(t *testing.T) {
    var (
        a string = "Hello"
        b string = "Hello"
    )

    assert.Equal(t, a, b, "The two words should be the same.")
}

Advanced Usage

import (
    "testing"
    "net/http"

    "github.com/golib/assert"
)

// if you assert many times, use the format below:
func TestSomething(t *testing.T) {
    it := assert.New(t)

    req, err := http.NewRequest(http.MethodGet, "https://example.com", nil)
    if it.Nil(err) {
        resp, err := http.DefaultClient.Do(req)
        if it.Nil(err) {
            it.Equal("HIT", resp.Header().Get("x-cache"))
        }
    }
}