Skip to content

Provides some addons functions for usage together with gocheck.

License

Notifications You must be signed in to change notification settings

echocat/gocheck-addons

Repository files navigation

Go Report Card Circle CI Coverage Status License

gocheck-addons

Provides some addons functions for usage together with gocheck.

Installation

Install dependencies:

go get -u github.com/echocat/gocheck-addons

Import in source code files:

import (
	. "github.com/echocat/gocheck-addons"
	. "gopkg.in/check.v1"
)

Checkers

ThrowsPanicThatMatches

Check for a panic message that should occur.

Example:

c.Assert(func() {
    panic(errors.New("foo123"))
}, ThrowsPanicThatMatches, "foo1.3")
c.Assert(func() {
    panic(enclosesString{string: "foo123"})
}, ThrowsPanicThatMatches, "foo1.3")
c.Assert(func() {
    panic("foo123")
}, ThrowsPanicThatMatches, "foo1.3")

IsEmpty

Check that a value is empty. Currently support strings, arrays and maps.

Example:

c.Assert("abc", Not(IsEmpty))
c.Assert("", IsEmpty)
c.Assert([]string{"abc"}, Not(IsEmpty))
c.Assert([]string{}, IsEmpty)
c.Assert([]int{1}, Not(IsEmpty))
c.Assert([]int{}, IsEmpty)
c.Assert(map[string]int{"abc": 1}, Not(IsEmpty))
c.Assert(map[string]int{}, IsEmpty)

Contains

Check that a specific value is contained in another. Currently support only strings.

Example:

c.Assert("abc", Contains, "a")
c.Assert("abc", Contains, "b")
c.Assert("abc", Contains, "c")
c.Assert("abc", Contains, "abc")
c.Assert("abc", Contains, "")
c.Assert("abc", Not(Contains), "x")

HasPrefix

Check that a specific value prefixes another. Currently support only strings.

Example:

c.Assert("abc", HasPrefix, "a")
c.Assert("abc", HasPrefix, "ab")
c.Assert("abc", HasPrefix, "abc")
c.Assert("abc", HasPrefix, "")
c.Assert("abc", Not(HasPrefix), "b")
c.Assert("abc", Not(HasPrefix), "c")

HasSuffix

Check that a specific value suffixes another. Currently support only strings.

Example:

c.Assert("abc", HasSuffix, "c")
c.Assert("abc", HasSuffix, "bc")
c.Assert("abc", HasSuffix, "abc")
c.Assert("abc", HasSuffix, "")
c.Assert("abc", Not(HasSuffix), "a")
c.Assert("abc", Not(HasSuffix), "b")

IsLessThan

Check that a value is less than to provided.

Example:

c.Assert(22, IsLessThan, 66)
c.Assert(22, Not(IsLessThan), 11)
c.Assert(22, Not(IsLessThan), 22)
c.Assert(22.5, IsLessThan, 66.5)
c.Assert(22.5, Not(IsLessThan), 11.5)
c.Assert(22.5, Not(IsLessThan), 22.5)
c.Assert(time.Duration(22), IsLessThan, time.Duration(66))

IsLessThanOrEqual

Check that a value is less than or equal to provided.

Example:

c.Assert(22, IsLessThanOrEqualTo, 66)
c.Assert(22, IsLessThanOrEqualTo, 22)
c.Assert(22, Not(IsLessThanOrEqualTo), 11)
c.Assert(22.5, IsLessThanOrEqualTo, 66.5)
c.Assert(22.5, IsLessThanOrEqualTo, 22.5)
c.Assert(22.5, Not(IsLessThanOrEqualTo), 11.5)
c.Assert(time.Duration(22), IsLessThanOrEqualTo, time.Duration(66))
c.Assert(time.Duration(22), IsLessThanOrEqualTo, time.Duration(22))

IsLargerThan

Check that a value is larger than to provided.

Example:

c.Assert(22, IsLargerThan, 11)
c.Assert(22, Not(IsLargerThan), 66)
c.Assert(22, Not(IsLargerThan), 22)
c.Assert(66.5, IsLargerThan, 22.5)
c.Assert(11.5, Not(IsLargerThan), 22.5)
c.Assert(22.5, Not(IsLargerThan), 22.5)
c.Assert(time.Duration(22), IsLargerThan, time.Duration(11))

IsLargerThanOrEqualTo

Check that a value is larger than or equal to provided.

Example:

c.Assert(22, IsLargerThanOrEqualTo, 11)
c.Assert(22, Not(IsLargerThanOrEqualTo), 66)
c.Assert(22, IsLargerThanOrEqualTo, 22)
c.Assert(66.5, IsLargerThanOrEqualTo, 22.5)
c.Assert(11.5, Not(IsLargerThanOrEqualTo), 22.5)
c.Assert(22.5, IsLargerThanOrEqualTo, 22.5)
c.Assert(time.Duration(22), IsLargerThanOrEqualTo, time.Duration(11))
c.Assert(time.Duration(22), IsLargerThanOrEqualTo, time.Duration(22))

Run tests of this library

This includes download of all dependencies and also creation and upload of coverage reports.

No working golang installation is required but Java 8+ (in PATH or JAVA_HOME set.).

# On Linux/macOS
$ ./gradlew test

# On Windows
$ gradlew test

Contributing

gocheck-addons is an open source project by echocat. So if you want to make this project even better, you can contribute to this project on Github by fork us.

If you commit code to this project, you have to accept that this code will be released under the license of this project.

Support

If you need support you can create a ticket in our issue tracker.

License

See the LICENSE file.

Releases

No releases published

Packages

No packages published

Languages