replace dep with go modules (#16017)
- guide shamelessly stolen from prometheus/prometheus - updates local interface of oauth exchange - updates local impl of hclogger - bump jaeger client version closes #16088
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
*.iml
|
||||
/.idea
|
||||
coverage.out
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
# Contributing
|
||||
|
||||
In general, the code posted to the [SmartyStreets github organization](https://github.com/smartystreets) is created to solve specific problems at SmartyStreets that are ancillary to our core products in the address verification industry and may or may not be useful to other organizations or developers. Our reason for posting said code isn't necessarily to solicit feedback or contributions from the community but more as a showcase of some of the approaches to solving problems we have adopted.
|
||||
|
||||
Having stated that, we do consider issues raised by other githubbers as well as contributions submitted via pull requests. When submitting such a pull request, please follow these guidelines:
|
||||
|
||||
- _Look before you leap:_ If the changes you plan to make are significant, it's in everyone's best interest for you to discuss them with a SmartyStreets team member prior to opening a pull request.
|
||||
- _License and ownership:_ If modifying the `LICENSE.md` file, limit your changes to fixing typographical mistakes. Do NOT modify the actual terms in the license or the copyright by **SmartyStreets, LLC**. Code submitted to SmartyStreets projects becomes property of SmartyStreets and must be compatible with the associated license.
|
||||
- _Testing:_ If the code you are submitting resides in packages/modules covered by automated tests, be sure to add passing tests that cover your changes and assert expected behavior and state. Submit the additional test cases as part of your change set.
|
||||
- _Style:_ Match your approach to **naming** and **formatting** with the surrounding code. Basically, the code you submit shouldn't stand out.
|
||||
- "Naming" refers to such constructs as variables, methods, functions, classes, structs, interfaces, packages, modules, directories, files, etc...
|
||||
- "Formatting" refers to such constructs as whitespace, horizontal line length, vertical function length, vertical file length, indentation, curly braces, etc...
|
||||
+619
@@ -0,0 +1,619 @@
|
||||
# assertions
|
||||
--
|
||||
import "github.com/smartystreets/assertions"
|
||||
|
||||
Package assertions contains the implementations for all assertions which are
|
||||
referenced in goconvey's `convey` package
|
||||
(github.com/smartystreets/goconvey/convey) and gunit
|
||||
(github.com/smartystreets/gunit) for use with the So(...) method. They can also
|
||||
be used in traditional Go test functions and even in applications.
|
||||
|
||||
https://smartystreets.com
|
||||
|
||||
Many of the assertions lean heavily on work done by Aaron Jacobs in his
|
||||
excellent oglematchers library. (https://github.com/jacobsa/oglematchers) The
|
||||
ShouldResemble assertion leans heavily on work done by Daniel Jacques in his
|
||||
very helpful go-render library. (https://github.com/luci/go-render)
|
||||
|
||||
## Usage
|
||||
|
||||
#### func GoConveyMode
|
||||
|
||||
```go
|
||||
func GoConveyMode(yes bool)
|
||||
```
|
||||
GoConveyMode provides control over JSON serialization of failures. When using
|
||||
the assertions in this package from the convey package JSON results are very
|
||||
helpful and can be rendered in a DIFF view. In that case, this function will be
|
||||
called with a true value to enable the JSON serialization. By default, the
|
||||
assertions in this package will not serializer a JSON result, making standalone
|
||||
usage more convenient.
|
||||
|
||||
#### func ShouldAlmostEqual
|
||||
|
||||
```go
|
||||
func ShouldAlmostEqual(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldAlmostEqual makes sure that two parameters are close enough to being
|
||||
equal. The acceptable delta may be specified with a third argument, or a very
|
||||
small default delta will be used.
|
||||
|
||||
#### func ShouldBeBetween
|
||||
|
||||
```go
|
||||
func ShouldBeBetween(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeBetween receives exactly three parameters: an actual value, a lower
|
||||
bound, and an upper bound. It ensures that the actual value is between both
|
||||
bounds (but not equal to either of them).
|
||||
|
||||
#### func ShouldBeBetweenOrEqual
|
||||
|
||||
```go
|
||||
func ShouldBeBetweenOrEqual(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeBetweenOrEqual receives exactly three parameters: an actual value, a
|
||||
lower bound, and an upper bound. It ensures that the actual value is between
|
||||
both bounds or equal to one of them.
|
||||
|
||||
#### func ShouldBeBlank
|
||||
|
||||
```go
|
||||
func ShouldBeBlank(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeBlank receives exactly 1 string parameter and ensures that it is equal
|
||||
to "".
|
||||
|
||||
#### func ShouldBeChronological
|
||||
|
||||
```go
|
||||
func ShouldBeChronological(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeChronological receives a []time.Time slice and asserts that they are in
|
||||
chronological order starting with the first time.Time as the earliest.
|
||||
|
||||
#### func ShouldBeEmpty
|
||||
|
||||
```go
|
||||
func ShouldBeEmpty(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeEmpty receives a single parameter (actual) and determines whether or not
|
||||
calling len(actual) would return `0`. It obeys the rules specified by the len
|
||||
function for determining length: http://golang.org/pkg/builtin/#len
|
||||
|
||||
#### func ShouldBeError
|
||||
|
||||
```go
|
||||
func ShouldBeError(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeError asserts that the first argument implements the error interface. It
|
||||
also compares the first argument against the second argument if provided (which
|
||||
must be an error message string or another error value).
|
||||
|
||||
#### func ShouldBeFalse
|
||||
|
||||
```go
|
||||
func ShouldBeFalse(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeFalse receives a single parameter and ensures that it is false.
|
||||
|
||||
#### func ShouldBeGreaterThan
|
||||
|
||||
```go
|
||||
func ShouldBeGreaterThan(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeGreaterThan receives exactly two parameters and ensures that the first
|
||||
is greater than the second.
|
||||
|
||||
#### func ShouldBeGreaterThanOrEqualTo
|
||||
|
||||
```go
|
||||
func ShouldBeGreaterThanOrEqualTo(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeGreaterThanOrEqualTo receives exactly two parameters and ensures that
|
||||
the first is greater than or equal to the second.
|
||||
|
||||
#### func ShouldBeIn
|
||||
|
||||
```go
|
||||
func ShouldBeIn(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeIn receives at least 2 parameters. The first is a proposed member of the
|
||||
collection that is passed in either as the second parameter, or of the
|
||||
collection that is comprised of all the remaining parameters. This assertion
|
||||
ensures that the proposed member is in the collection (using ShouldEqual).
|
||||
|
||||
#### func ShouldBeLessThan
|
||||
|
||||
```go
|
||||
func ShouldBeLessThan(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeLessThan receives exactly two parameters and ensures that the first is
|
||||
less than the second.
|
||||
|
||||
#### func ShouldBeLessThanOrEqualTo
|
||||
|
||||
```go
|
||||
func ShouldBeLessThanOrEqualTo(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeLessThan receives exactly two parameters and ensures that the first is
|
||||
less than or equal to the second.
|
||||
|
||||
#### func ShouldBeNil
|
||||
|
||||
```go
|
||||
func ShouldBeNil(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeNil receives a single parameter and ensures that it is nil.
|
||||
|
||||
#### func ShouldBeTrue
|
||||
|
||||
```go
|
||||
func ShouldBeTrue(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeTrue receives a single parameter and ensures that it is true.
|
||||
|
||||
#### func ShouldBeZeroValue
|
||||
|
||||
```go
|
||||
func ShouldBeZeroValue(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeZeroValue receives a single parameter and ensures that it is the Go
|
||||
equivalent of the default value, or "zero" value.
|
||||
|
||||
#### func ShouldContain
|
||||
|
||||
```go
|
||||
func ShouldContain(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldContain receives exactly two parameters. The first is a slice and the
|
||||
second is a proposed member. Membership is determined using ShouldEqual.
|
||||
|
||||
#### func ShouldContainKey
|
||||
|
||||
```go
|
||||
func ShouldContainKey(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldContainKey receives exactly two parameters. The first is a map and the
|
||||
second is a proposed key. Keys are compared with a simple '=='.
|
||||
|
||||
#### func ShouldContainSubstring
|
||||
|
||||
```go
|
||||
func ShouldContainSubstring(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldContainSubstring receives exactly 2 string parameters and ensures that the
|
||||
first contains the second as a substring.
|
||||
|
||||
#### func ShouldEndWith
|
||||
|
||||
```go
|
||||
func ShouldEndWith(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldEndWith receives exactly 2 string parameters and ensures that the first
|
||||
ends with the second.
|
||||
|
||||
#### func ShouldEqual
|
||||
|
||||
```go
|
||||
func ShouldEqual(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldEqual receives exactly two parameters and does an equality check using the
|
||||
following semantics: 1. If the expected and actual values implement an Equal
|
||||
method in the form `func (this T) Equal(that T) bool` then call the method. If
|
||||
true, they are equal. 2. The expected and actual values are judged equal or not
|
||||
by oglematchers.Equals.
|
||||
|
||||
#### func ShouldEqualJSON
|
||||
|
||||
```go
|
||||
func ShouldEqualJSON(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldEqualJSON receives exactly two parameters and does an equality check by
|
||||
marshalling to JSON
|
||||
|
||||
#### func ShouldEqualTrimSpace
|
||||
|
||||
```go
|
||||
func ShouldEqualTrimSpace(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldEqualTrimSpace receives exactly 2 string parameters and ensures that the
|
||||
first is equal to the second after removing all leading and trailing whitespace
|
||||
using strings.TrimSpace(first).
|
||||
|
||||
#### func ShouldEqualWithout
|
||||
|
||||
```go
|
||||
func ShouldEqualWithout(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldEqualWithout receives exactly 3 string parameters and ensures that the
|
||||
first is equal to the second after removing all instances of the third from the
|
||||
first using strings.Replace(first, third, "", -1).
|
||||
|
||||
#### func ShouldHappenAfter
|
||||
|
||||
```go
|
||||
func ShouldHappenAfter(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldHappenAfter receives exactly 2 time.Time arguments and asserts that the
|
||||
first happens after the second.
|
||||
|
||||
#### func ShouldHappenBefore
|
||||
|
||||
```go
|
||||
func ShouldHappenBefore(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldHappenBefore receives exactly 2 time.Time arguments and asserts that the
|
||||
first happens before the second.
|
||||
|
||||
#### func ShouldHappenBetween
|
||||
|
||||
```go
|
||||
func ShouldHappenBetween(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldHappenBetween receives exactly 3 time.Time arguments and asserts that the
|
||||
first happens between (not on) the second and third.
|
||||
|
||||
#### func ShouldHappenOnOrAfter
|
||||
|
||||
```go
|
||||
func ShouldHappenOnOrAfter(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldHappenOnOrAfter receives exactly 2 time.Time arguments and asserts that
|
||||
the first happens on or after the second.
|
||||
|
||||
#### func ShouldHappenOnOrBefore
|
||||
|
||||
```go
|
||||
func ShouldHappenOnOrBefore(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldHappenOnOrBefore receives exactly 2 time.Time arguments and asserts that
|
||||
the first happens on or before the second.
|
||||
|
||||
#### func ShouldHappenOnOrBetween
|
||||
|
||||
```go
|
||||
func ShouldHappenOnOrBetween(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldHappenOnOrBetween receives exactly 3 time.Time arguments and asserts that
|
||||
the first happens between or on the second and third.
|
||||
|
||||
#### func ShouldHappenWithin
|
||||
|
||||
```go
|
||||
func ShouldHappenWithin(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldHappenWithin receives a time.Time, a time.Duration, and a time.Time (3
|
||||
arguments) and asserts that the first time.Time happens within or on the
|
||||
duration specified relative to the other time.Time.
|
||||
|
||||
#### func ShouldHaveLength
|
||||
|
||||
```go
|
||||
func ShouldHaveLength(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldHaveLength receives 2 parameters. The first is a collection to check the
|
||||
length of, the second being the expected length. It obeys the rules specified by
|
||||
the len function for determining length: http://golang.org/pkg/builtin/#len
|
||||
|
||||
#### func ShouldHaveSameTypeAs
|
||||
|
||||
```go
|
||||
func ShouldHaveSameTypeAs(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldHaveSameTypeAs receives exactly two parameters and compares their
|
||||
underlying types for equality.
|
||||
|
||||
#### func ShouldImplement
|
||||
|
||||
```go
|
||||
func ShouldImplement(actual interface{}, expectedList ...interface{}) string
|
||||
```
|
||||
ShouldImplement receives exactly two parameters and ensures that the first
|
||||
implements the interface type of the second.
|
||||
|
||||
#### func ShouldNotAlmostEqual
|
||||
|
||||
```go
|
||||
func ShouldNotAlmostEqual(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotAlmostEqual is the inverse of ShouldAlmostEqual
|
||||
|
||||
#### func ShouldNotBeBetween
|
||||
|
||||
```go
|
||||
func ShouldNotBeBetween(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotBeBetween receives exactly three parameters: an actual value, a lower
|
||||
bound, and an upper bound. It ensures that the actual value is NOT between both
|
||||
bounds.
|
||||
|
||||
#### func ShouldNotBeBetweenOrEqual
|
||||
|
||||
```go
|
||||
func ShouldNotBeBetweenOrEqual(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotBeBetweenOrEqual receives exactly three parameters: an actual value, a
|
||||
lower bound, and an upper bound. It ensures that the actual value is nopt
|
||||
between the bounds nor equal to either of them.
|
||||
|
||||
#### func ShouldNotBeBlank
|
||||
|
||||
```go
|
||||
func ShouldNotBeBlank(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotBeBlank receives exactly 1 string parameter and ensures that it is
|
||||
equal to "".
|
||||
|
||||
#### func ShouldNotBeChronological
|
||||
|
||||
```go
|
||||
func ShouldNotBeChronological(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotBeChronological receives a []time.Time slice and asserts that they are
|
||||
NOT in chronological order.
|
||||
|
||||
#### func ShouldNotBeEmpty
|
||||
|
||||
```go
|
||||
func ShouldNotBeEmpty(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotBeEmpty receives a single parameter (actual) and determines whether or
|
||||
not calling len(actual) would return a value greater than zero. It obeys the
|
||||
rules specified by the `len` function for determining length:
|
||||
http://golang.org/pkg/builtin/#len
|
||||
|
||||
#### func ShouldNotBeIn
|
||||
|
||||
```go
|
||||
func ShouldNotBeIn(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotBeIn receives at least 2 parameters. The first is a proposed member of
|
||||
the collection that is passed in either as the second parameter, or of the
|
||||
collection that is comprised of all the remaining parameters. This assertion
|
||||
ensures that the proposed member is NOT in the collection (using ShouldEqual).
|
||||
|
||||
#### func ShouldNotBeNil
|
||||
|
||||
```go
|
||||
func ShouldNotBeNil(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotBeNil receives a single parameter and ensures that it is not nil.
|
||||
|
||||
#### func ShouldNotBeZeroValue
|
||||
|
||||
```go
|
||||
func ShouldNotBeZeroValue(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeZeroValue receives a single parameter and ensures that it is NOT the Go
|
||||
equivalent of the default value, or "zero" value.
|
||||
|
||||
#### func ShouldNotContain
|
||||
|
||||
```go
|
||||
func ShouldNotContain(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotContain receives exactly two parameters. The first is a slice and the
|
||||
second is a proposed member. Membership is determinied using ShouldEqual.
|
||||
|
||||
#### func ShouldNotContainKey
|
||||
|
||||
```go
|
||||
func ShouldNotContainKey(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotContainKey receives exactly two parameters. The first is a map and the
|
||||
second is a proposed absent key. Keys are compared with a simple '=='.
|
||||
|
||||
#### func ShouldNotContainSubstring
|
||||
|
||||
```go
|
||||
func ShouldNotContainSubstring(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotContainSubstring receives exactly 2 string parameters and ensures that
|
||||
the first does NOT contain the second as a substring.
|
||||
|
||||
#### func ShouldNotEndWith
|
||||
|
||||
```go
|
||||
func ShouldNotEndWith(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldEndWith receives exactly 2 string parameters and ensures that the first
|
||||
does not end with the second.
|
||||
|
||||
#### func ShouldNotEqual
|
||||
|
||||
```go
|
||||
func ShouldNotEqual(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotEqual receives exactly two parameters and does an inequality check. See
|
||||
ShouldEqual for details on how equality is determined.
|
||||
|
||||
#### func ShouldNotHappenOnOrBetween
|
||||
|
||||
```go
|
||||
func ShouldNotHappenOnOrBetween(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotHappenOnOrBetween receives exactly 3 time.Time arguments and asserts
|
||||
that the first does NOT happen between or on the second or third.
|
||||
|
||||
#### func ShouldNotHappenWithin
|
||||
|
||||
```go
|
||||
func ShouldNotHappenWithin(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotHappenWithin receives a time.Time, a time.Duration, and a time.Time (3
|
||||
arguments) and asserts that the first time.Time does NOT happen within or on the
|
||||
duration specified relative to the other time.Time.
|
||||
|
||||
#### func ShouldNotHaveSameTypeAs
|
||||
|
||||
```go
|
||||
func ShouldNotHaveSameTypeAs(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotHaveSameTypeAs receives exactly two parameters and compares their
|
||||
underlying types for inequality.
|
||||
|
||||
#### func ShouldNotImplement
|
||||
|
||||
```go
|
||||
func ShouldNotImplement(actual interface{}, expectedList ...interface{}) string
|
||||
```
|
||||
ShouldNotImplement receives exactly two parameters and ensures that the first
|
||||
does NOT implement the interface type of the second.
|
||||
|
||||
#### func ShouldNotPanic
|
||||
|
||||
```go
|
||||
func ShouldNotPanic(actual interface{}, expected ...interface{}) (message string)
|
||||
```
|
||||
ShouldNotPanic receives a void, niladic function and expects to execute the
|
||||
function without any panic.
|
||||
|
||||
#### func ShouldNotPanicWith
|
||||
|
||||
```go
|
||||
func ShouldNotPanicWith(actual interface{}, expected ...interface{}) (message string)
|
||||
```
|
||||
ShouldNotPanicWith receives a void, niladic function and expects to recover a
|
||||
panic whose content differs from the second argument.
|
||||
|
||||
#### func ShouldNotPointTo
|
||||
|
||||
```go
|
||||
func ShouldNotPointTo(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotPointTo receives exactly two parameters and checks to see that they
|
||||
point to different addresess.
|
||||
|
||||
#### func ShouldNotResemble
|
||||
|
||||
```go
|
||||
func ShouldNotResemble(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotResemble receives exactly two parameters and does an inverse deep equal
|
||||
check (see reflect.DeepEqual)
|
||||
|
||||
#### func ShouldNotStartWith
|
||||
|
||||
```go
|
||||
func ShouldNotStartWith(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotStartWith receives exactly 2 string parameters and ensures that the
|
||||
first does not start with the second.
|
||||
|
||||
#### func ShouldPanic
|
||||
|
||||
```go
|
||||
func ShouldPanic(actual interface{}, expected ...interface{}) (message string)
|
||||
```
|
||||
ShouldPanic receives a void, niladic function and expects to recover a panic.
|
||||
|
||||
#### func ShouldPanicWith
|
||||
|
||||
```go
|
||||
func ShouldPanicWith(actual interface{}, expected ...interface{}) (message string)
|
||||
```
|
||||
ShouldPanicWith receives a void, niladic function and expects to recover a panic
|
||||
with the second argument as the content.
|
||||
|
||||
#### func ShouldPointTo
|
||||
|
||||
```go
|
||||
func ShouldPointTo(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldPointTo receives exactly two parameters and checks to see that they point
|
||||
to the same address.
|
||||
|
||||
#### func ShouldResemble
|
||||
|
||||
```go
|
||||
func ShouldResemble(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldResemble receives exactly two parameters and does a deep equal check (see
|
||||
reflect.DeepEqual)
|
||||
|
||||
#### func ShouldStartWith
|
||||
|
||||
```go
|
||||
func ShouldStartWith(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldStartWith receives exactly 2 string parameters and ensures that the first
|
||||
starts with the second.
|
||||
|
||||
#### func So
|
||||
|
||||
```go
|
||||
func So(actual interface{}, assert assertion, expected ...interface{}) (bool, string)
|
||||
```
|
||||
So is a convenience function (as opposed to an inconvenience function?) for
|
||||
running assertions on arbitrary arguments in any context, be it for testing or
|
||||
even application logging. It allows you to perform assertion-like behavior (and
|
||||
get nicely formatted messages detailing discrepancies) but without the program
|
||||
blowing up or panicking. All that is required is to import this package and call
|
||||
`So` with one of the assertions exported by this package as the second
|
||||
parameter. The first return parameter is a boolean indicating if the assertion
|
||||
was true. The second return parameter is the well-formatted message showing why
|
||||
an assertion was incorrect, or blank if the assertion was correct.
|
||||
|
||||
Example:
|
||||
|
||||
if ok, message := So(x, ShouldBeGreaterThan, y); !ok {
|
||||
log.Println(message)
|
||||
}
|
||||
|
||||
For an alternative implementation of So (that provides more flexible return
|
||||
options) see the `So` function in the package at
|
||||
github.com/smartystreets/assertions/assert.
|
||||
|
||||
#### type Assertion
|
||||
|
||||
```go
|
||||
type Assertion struct {
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
#### func New
|
||||
|
||||
```go
|
||||
func New(t testingT) *Assertion
|
||||
```
|
||||
New swallows the *testing.T struct and prints failed assertions using t.Error.
|
||||
Example: assertions.New(t).So(1, should.Equal, 1)
|
||||
|
||||
#### func (*Assertion) Failed
|
||||
|
||||
```go
|
||||
func (this *Assertion) Failed() bool
|
||||
```
|
||||
Failed reports whether any calls to So (on this Assertion instance) have failed.
|
||||
|
||||
#### func (*Assertion) So
|
||||
|
||||
```go
|
||||
func (this *Assertion) So(actual interface{}, assert assertion, expected ...interface{}) bool
|
||||
```
|
||||
So calls the standalone So function and additionally, calls t.Error in failure
|
||||
scenarios.
|
||||
|
||||
#### type FailureView
|
||||
|
||||
```go
|
||||
type FailureView struct {
|
||||
Message string `json:"Message"`
|
||||
Expected string `json:"Expected"`
|
||||
Actual string `json:"Actual"`
|
||||
}
|
||||
```
|
||||
|
||||
This struct is also declared in
|
||||
github.com/smartystreets/goconvey/convey/reporting. The json struct tags should
|
||||
be equal in both declarations.
|
||||
|
||||
#### type Serializer
|
||||
|
||||
```go
|
||||
type Serializer interface {
|
||||
// contains filtered or unexported methods
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,5 @@
|
||||
*.6
|
||||
6.out
|
||||
_obj/
|
||||
_test/
|
||||
_testmain.go
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
[](https://godoc.org/github.com/smartystreets/assertions/internal/oglematchers)
|
||||
|
||||
`oglematchers` is a package for the Go programming language containing a set of
|
||||
matchers, useful in a testing or mocking framework, inspired by and mostly
|
||||
compatible with [Google Test][googletest] for C++ and
|
||||
[Google JS Test][google-js-test]. The package is used by the
|
||||
[ogletest][ogletest] testing framework and [oglemock][oglemock] mocking
|
||||
framework, which may be more directly useful to you, but can be generically used
|
||||
elsewhere as well.
|
||||
|
||||
A "matcher" is simply an object with a `Matches` method defining a set of golang
|
||||
values matched by the matcher, and a `Description` method describing that set.
|
||||
For example, here are some matchers:
|
||||
|
||||
```go
|
||||
// Numbers
|
||||
Equals(17.13)
|
||||
LessThan(19)
|
||||
|
||||
// Strings
|
||||
Equals("taco")
|
||||
HasSubstr("burrito")
|
||||
MatchesRegex("t.*o")
|
||||
|
||||
// Combining matchers
|
||||
AnyOf(LessThan(17), GreaterThan(19))
|
||||
```
|
||||
|
||||
There are lots more; see [here][reference] for a reference. You can also add
|
||||
your own simply by implementing the `oglematchers.Matcher` interface.
|
||||
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
First, make sure you have installed Go 1.0.2 or newer. See
|
||||
[here][golang-install] for instructions.
|
||||
|
||||
Use the following command to install `oglematchers` and keep it up to date:
|
||||
|
||||
go get -u github.com/smartystreets/assertions/internal/oglematchers
|
||||
|
||||
|
||||
Documentation
|
||||
-------------
|
||||
|
||||
See [here][reference] for documentation. Alternatively, you can install the
|
||||
package and then use `godoc`:
|
||||
|
||||
godoc github.com/smartystreets/assertions/internal/oglematchers
|
||||
|
||||
|
||||
[reference]: http://godoc.org/github.com/smartystreets/assertions/internal/oglematchers
|
||||
[golang-install]: http://golang.org/doc/install.html
|
||||
[googletest]: http://code.google.com/p/googletest/
|
||||
[google-js-test]: http://code.google.com/p/google-js-test/
|
||||
[ogletest]: http://github.com/smartystreets/assertions/internal/ogletest
|
||||
[oglemock]: http://github.com/smartystreets/assertions/internal/oglemock
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
#ignore
|
||||
-timeout=1s
|
||||
#-covermode=count
|
||||
#-coverpkg=github.com/smartystreets/goconvey/convey,github.com/smartystreets/goconvey/convey/gotest,github.com/smartystreets/goconvey/convey/reporting
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
#ignore
|
||||
-timeout=1s
|
||||
Generated
Vendored
-202
@@ -1,202 +0,0 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
Reference in New Issue
Block a user