assert

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2022 License: Apache-2.0 Imports: 6 Imported by: 1

README

assert

Provides some useful assertion methods.

Install

go get github.com/go-spring/spring-base@v1.1.0-rc2 

Import

import "github.com/go-spring/spring-base/assert"

Example

assert.True(t, ok)
assert.False(t, ok)
assert.Nil(t, nil)
assert.Equal(t, 0, "0")
assert.NotEqual(t, "0", 0)
assert.Same(t, 0, "0")
assert.NotSame(t, "0", "0")
assert.Panic(t, func() {}, "an error")
assert.Matches(t, "there's no error", "an error")
assert.Error(t, errors.New("there's no error"), "an error")
assert.TypeOf(t, new(int), (*int)(nil))
assert.Implements(t, errors.New("error"), (*error)(nil))

Documentation

Overview

Package assert provides some useful assertion methods.

Package assert is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal(t T, got interface{}, expect interface{}, msg ...string)

Equal assertion failed when got and expect are not `deeply equal`.

func Error

func Error(t T, got error, expr string, msg ...string)

Error assertion failed when got `error` doesn't match expr expression.

func False

func False(t T, got bool, msg ...string)

False assertion failed when got is true.

func Implements

func Implements(t T, got interface{}, expect interface{}, msg ...string)

Implements assertion failed when got doesn't implement expect.

func JsonEqual

func JsonEqual(t T, got string, expect string, msg ...string)

JsonEqual assertion failed when got and expect are not `json equal`.

func Matches

func Matches(t T, got string, expr string, msg ...string)

Matches assertion failed when got doesn't match expr expression.

func Nil

func Nil(t T, got interface{}, msg ...string)

Nil assertion failed when got is not nil.

func NotEqual

func NotEqual(t T, got interface{}, expect interface{}, msg ...string)

NotEqual assertion failed when got and expect are `deeply equal`.

func NotNil

func NotNil(t T, got interface{}, msg ...string)

NotNil assertion failed when got is nil.

func NotSame

func NotSame(t T, got interface{}, expect interface{}, msg ...string)

NotSame assertion failed when got and expect are same.

func Panic

func Panic(t T, fn func(), expr string, msg ...string)

Panic assertion failed when fn doesn't panic or not match expr expression.

func Same

func Same(t T, got interface{}, expect interface{}, msg ...string)

Same assertion failed when got and expect are not same.

func True

func True(t T, got bool, msg ...string)

True assertion failed when got is false.

func TypeOf

func TypeOf(t T, got interface{}, expect interface{}, msg ...string)

TypeOf assertion failed when got and expect are not same type.

Types

type MockT

type MockT struct {
	// contains filtered or unexported fields
}

MockT is a mock of T interface.

func NewMockT

func NewMockT(ctrl *gomock.Controller) *MockT

NewMockT creates a new mock instance.

func (*MockT) EXPECT

func (m *MockT) EXPECT() *MockTMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockT) Error added in v1.1.3

func (m *MockT) Error(args ...interface{})

Error mocks base method.

func (*MockT) Helper

func (m *MockT) Helper()

Helper mocks base method.

type MockTMockRecorder

type MockTMockRecorder struct {
	// contains filtered or unexported fields
}

MockTMockRecorder is the mock recorder for MockT.

func (*MockTMockRecorder) Error added in v1.1.3

func (mr *MockTMockRecorder) Error(args ...interface{}) *gomock.Call

Error indicates an expected call of Error.

func (*MockTMockRecorder) Helper

func (mr *MockTMockRecorder) Helper() *gomock.Call

Helper indicates an expected call of Helper.

type StringAssertion

type StringAssertion struct {
	// contains filtered or unexported fields
}

StringAssertion assertion for type string.

func String added in v1.1.3

func String(t T, v string) *StringAssertion

String returns an assertion for type string.

func (*StringAssertion) Contains added in v1.1.3

func (a *StringAssertion) Contains(substr string, msg ...string) *StringAssertion

Contains assertion failed when v doesn't contain substring `substr`.

func (*StringAssertion) EqualFold added in v1.1.3

func (a *StringAssertion) EqualFold(s string, msg ...string)

EqualFold assertion failed when v doesn't equal to `s` under Unicode case-folding.

func (*StringAssertion) HasPrefix

func (a *StringAssertion) HasPrefix(prefix string, msg ...string) *StringAssertion

HasPrefix assertion failed when v doesn't have prefix `prefix`.

func (*StringAssertion) HasSuffix

func (a *StringAssertion) HasSuffix(suffix string, msg ...string) *StringAssertion

HasSuffix assertion failed when v doesn't have suffix `suffix`.

type T

type T interface {
	Helper()
	Error(args ...interface{})
}

T is the minimum interface of *testing.T.

Jump to

Keyboard shortcuts

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