shakers

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2016 License: Apache-2.0 Imports: 5 Imported by: 51

README

Shakers

🐹 + 🐙 = 😽 Circle CI

A collection of go-check Checkers to ease the use of it.

Building and testing it

You need either docker, or go and glide in order to build and test shakers.

Using Docker and Makefile

You need to run the test-unit target.

$ make test-unit
docker build -t "shakers-dev:master" .
# […]
docker run --rm -it   "shakers-dev:master" ./script/make.sh test-unit
---> Making bundle: test-unit (in .)
+ go test -cover -coverprofile=cover.out .
ok      github.com/vdemeester/shakers   0.015s  coverage: 96.0% of statements

Test success
Using glide and GO15VENDOREXPERIMENT
  • Get the dependencies with glide up (or use go get but you have no garantuees over the version of the dependencies)
  • If you're using glide (and not standard go get) export GO15VENDOREXPERIMENT with export GO15VENDOREXPERIMENT=1
  • Run tests with go test .

Documentation

Overview

Package shakers provide some checker implementation the go-check.Checker interface.

Index

Constants

This section is empty.

Variables

View Source
var (
	DeepEquals   = check.DeepEquals
	ErrorMatches = check.ErrorMatches
	FitsTypeOf   = check.FitsTypeOf
	HasLen       = check.HasLen
	Implements   = check.Implements
	IsNil        = check.IsNil
	Matches      = check.Matches
	Not          = check.Not
	NotNil       = check.NotNil
	PanicMatches = check.PanicMatches
	Panics       = check.Panics
)

As a commodity, we bring all check.Checker variables into the current namespace to avoid having to think about check.X versus checker.X.

View Source
var Contains check.Checker = &substringChecker{
	&check.CheckerInfo{
		Name:   "Contains",
		Params: []string{"obtained", "substring"},
	},
	strings.Contains,
}

Contains checker verifies that obtained value contains a substring.

View Source
var ContainsAny check.Checker = &substringChecker{
	&check.CheckerInfo{
		Name:   "ContainsAny",
		Params: []string{"obtained", "chars"},
	},
	strings.ContainsAny,
}

ContainsAny checker verifies that any Unicode code points in chars are in the obtained string.

View Source
var Count check.Checker = &substringCountChecker{
	&check.CheckerInfo{
		Name:   "Count",
		Params: []string{"obtained", "sep", "expected"},
	},
	strings.Count,
}

Count checker verifies that obtained value has the specified number of non-overlapping instances of sep

View Source
var EqualFold check.Checker = &substringChecker{
	&check.CheckerInfo{
		Name:   "EqualFold",
		Params: []string{"obtained", "expected"},
	},
	strings.EqualFold,
}

EqualFold checker verifies that obtained value is, interpreted as UTF-8 strings, are equal under Unicode case-folding.

View Source
var Equals check.Checker = &equalChecker{
	&check.CheckerInfo{
		Name:   "Equals",
		Params: []string{"obtained", "expected"},
	},
}

Equals checker verifies the obtained value is equal to the specified one. It's is smart in a wait that it supports several *types* (built-in, Equaler, time.Time)

c.Assert(myStruct, Equals, aStruct, check.Commentf("bouuuhh"))
c.Assert(myTime, Equals, aTime, check.Commentf("bouuuhh"))
View Source
var False check.Checker = &boolChecker{
	&check.CheckerInfo{
		Name:   "False",
		Params: []string{"obtained"},
	},
	false,
}

False checker verifies the obtained value is false

c.Assert(myBool, False)
View Source
var GreaterOrEqualThan check.Checker = &greaterOrEqualThanChecker{
	&check.CheckerInfo{
		Name:   "GreaterOrEqualThan",
		Params: []string{"obtained", "expected"},
	},
}

GreaterOrEqualThan checker verifies the obtained value is greater or equal than the specified one. It's is smart in a wait that it supports several *types* (built-in, time.Time)

c.Assert(myTime, GreaterOrEqualThan, aTime, check.Commentf("bouuuhh"))
c.Assert(myInt, GreaterOrEqualThan, 2, check.Commentf("bouuuhh"))
View Source
var GreaterThan check.Checker = &greaterThanChecker{
	&check.CheckerInfo{
		Name:   "GreaterThan",
		Params: []string{"obtained", "expected"},
	},
}

GreaterThan checker verifies the obtained value is greater than the specified one. It's is smart in a wait that it supports several *types* (built-in, time.Time)

c.Assert(myTime, GreaterThan, aTime, check.Commentf("bouuuhh"))
c.Assert(myInt, GreaterThan, 2, check.Commentf("bouuuhh"))
View Source
var HasPrefix check.Checker = &substringChecker{
	&check.CheckerInfo{
		Name:   "HasPrefix",
		Params: []string{"obtained", "prefix"},
	},
	strings.HasPrefix,
}

HasPrefix checker verifies that obtained value has the specified substring as prefix

View Source
var HasSuffix check.Checker = &substringChecker{
	&check.CheckerInfo{
		Name:   "HasSuffix",
		Params: []string{"obtained", "suffix"},
	},
	strings.HasSuffix,
}

HasSuffix checker verifies that obtained value has the specified substring as prefix

View Source
var Index check.Checker = &substringCountChecker{
	&check.CheckerInfo{
		Name:   "Index",
		Params: []string{"obtained", "sep", "expected"},
	},
	strings.Index,
}

Index checker verifies that the index of the first instance of sep in the obtained value is equal to expected

View Source
var IndexAny check.Checker = &substringCountChecker{
	&check.CheckerInfo{
		Name:   "IndexAny",
		Params: []string{"obtained", "chars", "expected"},
	},
	strings.IndexAny,
}

IndexAny checker verifies that the index of the first instance of any Unicode code point from chars in the obtained value is equal to expected

View Source
var IsAfter check.Checker = &isAfterChecker{
	&check.CheckerInfo{
		Name:   "IsAfter",
		Params: []string{"obtained", "expected"},
	},
}

IsAfter checker verifies the specified value is before the specified time. It is exclusive.

c.Assert(myTime, IsAfter, theTime, check.Commentf("bouuuhhh"))
View Source
var IsBefore check.Checker = &isBeforeChecker{
	&check.CheckerInfo{
		Name:   "IsBefore",
		Params: []string{"obtained", "expected"},
	},
}

IsBefore checker verifies the specified value is before the specified time. It is exclusive.

c.Assert(myTime, IsBefore, theTime, check.Commentf("bouuuhhh"))
View Source
var IsBetween check.Checker = &isBetweenChecker{
	&check.CheckerInfo{
		Name:   "IsBetween",
		Params: []string{"obtained", "start", "end"},
	},
}

IsBetween checker verifies the specified time is between the specified start and end. It's exclusive so if the specified time is at the tip of the interval.

c.Assert(myTime, IsBetween, startTime, endTime, check.Commentf("bouuuhhh"))
View Source
var IsLower check.Checker = &stringTransformChecker{
	&check.CheckerInfo{
		Name:   "IsLower",
		Params: []string{"obtained"},
	},
	strings.ToLower,
}

IsLower checker verifies that the obtained value is in lower case

View Source
var IsUpper check.Checker = &stringTransformChecker{
	&check.CheckerInfo{
		Name:   "IsUpper",
		Params: []string{"obtained"},
	},
	strings.ToUpper,
}

IsUpper checker verifies that the obtained value is in lower case

View Source
var LessOrEqualThan check.Checker = &lessOrEqualThanChecker{
	&check.CheckerInfo{
		Name:   "LessOrEqualThan",
		Params: []string{"obtained", "expected"},
	},
}

LessOrEqualThan checker verifies the obtained value is less or equal than the specified one. It's is smart in a wait that it supports several *types* (built-in, time.Time)

c.Assert(myTime, LessThan, aTime, check.Commentf("bouuuhh"))
c.Assert(myInt, LessThan, 2, check.Commentf("bouuuhh"))
View Source
var LessThan check.Checker = &lessThanChecker{
	&check.CheckerInfo{
		Name:   "LessThan",
		Params: []string{"obtained", "expected"},
	},
}

LessThan checker verifies the obtained value is less than the specified one. It's is smart in a wait that it supports several *types* (built-in, time.Time)

c.Assert(myTime, LessThan, aTime, check.Commentf("bouuuhh"))
c.Assert(myInt, LessThan, 2, check.Commentf("bouuuhh"))
View Source
var TimeEquals check.Checker = &timeEqualsChecker{
	&check.CheckerInfo{
		Name:   "TimeEquals",
		Params: []string{"obtained", "expected"},
	},
}

TimeEquals checker verifies the specified time is the equal to the expected time.

c.Assert(myTime, TimeEquals, expected, check.Commentf("bouhhh"))

It's possible to ignore some part of the time (like hours, minutes, etc..) using the TimeIgnore checker with it.

c.Assert(myTime, TimeIgnore(TimeEquals, time.Hour), expected, check.Commentf("... bouh.."))
View Source
var True check.Checker = &boolChecker{
	&check.CheckerInfo{
		Name:   "True",
		Params: []string{"obtained"},
	},
	true,
}

True checker verifies the obtained value is true

c.Assert(myBool, True)

Functions

func TimeIgnore

func TimeIgnore(checker check.Checker, ignore time.Duration) check.Checker

TimeIgnore checker will ignore some part of the time on the encapsulated checker.

c.Assert(myTime, TimeIgnore(IsBetween, time.Second), start, end)

FIXME use interface{} for ignore (to enable "Month", ..

Types

type Equaler

type Equaler interface {
	Equal(Equaler) bool
}

Equaler is an interface implemented if the type has a Equal method. This is used to compare struct using shakers.Equals.

Jump to

Keyboard shortcuts

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