assert
assert
implements functions for making assertions in tests.
Installation
The recommended way to install assert
is with dep
.
dep ensure -add github.com/dapr-project/assert@v1.0.0
Where v1.0.0
is the version you want to pin to. Alternatively you can go get
the package into your $GOPATH
.
go get -u github.com/dapr-project/assert
Once installed you can import into your project.
import "github.com/dapr-project/assert"
Usage
Use the assert.OK()
function inside to assert expected results.
func TestMax(t *testing.T) {
max := math.Max(1.0, 3.0)
assert.OK(t, max == 3.0, "max isn't 3.0")
}
Use the assert.Includes()
function to assert an element is included in a list.
func TestSplit(t *testing.T) {
words := strings.Split("hello world", " ")
assert.Includes(t, words, "hello", "words excludes 'hello'")
}
Use the assert.Excludes()
function to assert an element is excluded from a
list.
func TestSplit(t *testing.T) {
words := strings.Split("hello world", " ")
assert.Excludes(t, words, "foobar", "words includes 'foobar'")
}
Use the assert.Unique()
function to assert an element is only included once in
a list.
func TestSplit(t *testing.T) {
letters := strings.Split("hello", "")
assert.Unique(t, letters, "h", "letters includes 'h' multiple times")
}