update gomega godep
This commit is contained in:
14
vendor/github.com/onsi/gomega/.travis.yml
generated
vendored
14
vendor/github.com/onsi/gomega/.travis.yml
generated
vendored
@@ -1,12 +1,18 @@
|
||||
language: go
|
||||
|
||||
go:
|
||||
- 1.5
|
||||
- 1.6.2
|
||||
- stable
|
||||
- 1.9.x
|
||||
- 1.10.x
|
||||
- 1.11.x
|
||||
- tip
|
||||
|
||||
env:
|
||||
- GO111MODULE=on
|
||||
|
||||
install:
|
||||
- go get -v ./...
|
||||
- go build ./...
|
||||
- go get github.com/onsi/ginkgo
|
||||
- go install github.com/onsi/ginkgo/ginkgo
|
||||
|
||||
script: $HOME/gopath/bin/ginkgo -r --randomizeAllSpecs --failOnPending --randomizeSuites --race
|
||||
script: make test
|
||||
|
57
vendor/github.com/onsi/gomega/CHANGELOG.md
generated
vendored
57
vendor/github.com/onsi/gomega/CHANGELOG.md
generated
vendored
@@ -1,4 +1,57 @@
|
||||
## HEAD
|
||||
## 1.4.3
|
||||
|
||||
### Fixes:
|
||||
|
||||
- ensure file name and line numbers are correctly reported for XUnit [6fff58f]
|
||||
- Fixed matcher for content-type (#305) [69d9b43]
|
||||
|
||||
## 1.4.2
|
||||
|
||||
### Fixes:
|
||||
|
||||
- Add go.mod and go.sum files to define the gomega go module [f3de367, a085d30]
|
||||
- Work around go vet issue with Go v1.11 (#300) [40dd6ad]
|
||||
- Better output when using with go XUnit-style tests, fixes #255 (#297) [29a4b97]
|
||||
- Fix MatchJSON fail to parse json.RawMessage (#298) [ae19f1b]
|
||||
- show threshold in failure message of BeNumericallyMatcher (#293) [4bbecc8]
|
||||
|
||||
## 1.4.1
|
||||
|
||||
### Fixes:
|
||||
|
||||
- Update documentation formatting and examples (#289) [9be8410]
|
||||
- allow 'Receive' matcher to be used with concrete types (#286) [41673fd]
|
||||
- Fix data race in ghttp server (#283) [7ac6b01]
|
||||
- Travis badge should only show master [cc102ab]
|
||||
|
||||
## 1.4.0
|
||||
|
||||
### Features
|
||||
- Make string pretty diff user configurable (#273) [eb112ce, 649b44d]
|
||||
|
||||
### Fixes
|
||||
- Use httputil.DumpRequest to pretty-print unhandled requests (#278) [a4ff0fc, b7d1a52]
|
||||
- fix typo floa32 > float32 (#272) [041ae3b, 6e33911]
|
||||
- Fix link to documentation on adding your own matchers (#270) [bb2c830, fcebc62]
|
||||
- Use setters and getters to avoid race condition (#262) [13057c3, a9c79f1]
|
||||
- Avoid sending a signal if the process is not alive (#259) [b8043e5, 4fc1762]
|
||||
- Improve message from AssignableToTypeOf when expected value is nil (#281) [9c1fb20]
|
||||
|
||||
## 1.3.0
|
||||
|
||||
Improvements:
|
||||
|
||||
- The `Equal` matcher matches byte slices more performantly.
|
||||
- Improved how `MatchError` matches error strings.
|
||||
- `MatchXML` ignores the order of xml node attributes.
|
||||
- Improve support for XUnit style golang tests. ([#254](https://github.com/onsi/gomega/issues/254))
|
||||
|
||||
Bug Fixes:
|
||||
|
||||
- Diff generation now handles multi-byte sequences correctly.
|
||||
- Multiple goroutines can now call `gexec.Build` concurrently.
|
||||
|
||||
## 1.2.0
|
||||
|
||||
Improvements:
|
||||
|
||||
@@ -14,6 +67,8 @@ Improvements:
|
||||
- `ghttp` servers can take an `io.Writer`. `ghttp` will write a line to the writer when each request arrives.
|
||||
- Added `WithTransform` matcher to allow munging input data before feeding into the relevant matcher
|
||||
- Added boolean `And`, `Or`, and `Not` matchers to allow creating composite matchers
|
||||
- Added `gbytes.TimeoutCloser`, `gbytes.TimeoutReader`, and `gbytes.TimeoutWriter` - these are convenience wrappers that timeout if the underlying Closer/Reader/Writer does not return within the alloted time.
|
||||
- Added `gbytes.BufferReader` - this constructs a `gbytes.Buffer` that asynchronously reads the passed-in `io.Reader` into its buffer.
|
||||
|
||||
Bug Fixes:
|
||||
- gexec: `session.Wait` now uses `EventuallyWithOffset` to get the right line number in the failure.
|
||||
|
14
vendor/github.com/onsi/gomega/CONTRIBUTING.md
generated
vendored
Normal file
14
vendor/github.com/onsi/gomega/CONTRIBUTING.md
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
# Contributing to Gomega
|
||||
|
||||
Your contributions to Gomega are essential for its long-term maintenance and improvement. To make a contribution:
|
||||
|
||||
- Please **open an issue first** - describe what problem you are trying to solve and give the community a forum for input and feedback ahead of investing time in writing code!
|
||||
- Ensure adequate test coverage:
|
||||
- Make sure to add appropriate unit tests
|
||||
- Please run all tests locally (`ginkgo -r -p`) and make sure they go green before submitting the PR
|
||||
- Please run following linter locally `go vet ./...` and make sure output does not contain any warnings
|
||||
- Update the documentation. In addition to standard `godoc` comments Gomega has extensive documentation on the `gh-pages` branch. If relevant, please submit a docs PR to that branch alongside your code PR.
|
||||
|
||||
If you're a committer, check out RELEASING.md to learn how to cut a release.
|
||||
|
||||
Thanks for supporting Gomega!
|
6
vendor/github.com/onsi/gomega/Makefile
generated
vendored
Normal file
6
vendor/github.com/onsi/gomega/Makefile
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
test:
|
||||
[ -z "`gofmt -s -w -l -e .`" ]
|
||||
go vet
|
||||
ginkgo -p -r --randomizeAllSpecs --failOnPending --randomizeSuites --race
|
||||
|
||||
.PHONY: test
|
4
vendor/github.com/onsi/gomega/README.md
generated
vendored
4
vendor/github.com/onsi/gomega/README.md
generated
vendored
@@ -1,10 +1,10 @@
|
||||

|
||||
|
||||
[](https://travis-ci.org/onsi/gomega)
|
||||
[](https://travis-ci.org/onsi/gomega)
|
||||
|
||||
Jump straight to the [docs](http://onsi.github.io/gomega/) to learn about Gomega, including a list of [all available matchers](http://onsi.github.io/gomega/#provided-matchers).
|
||||
|
||||
To discuss Gomega and get updates, join the [google group](https://groups.google.com/d/forum/ginkgo-and-gomega).
|
||||
If you have a question, comment, bug report, feature request, etc. please open a GitHub issue.
|
||||
|
||||
## [Ginkgo](http://github.com/onsi/ginkgo): a BDD Testing Framework for Golang
|
||||
|
||||
|
12
vendor/github.com/onsi/gomega/RELEASING.md
generated
vendored
Normal file
12
vendor/github.com/onsi/gomega/RELEASING.md
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
A Gomega release is a tagged sha and a GitHub release. To cut a release:
|
||||
|
||||
1. Ensure CHANGELOG.md is up to date.
|
||||
- Use `git log --pretty=format:'- %s [%h]' HEAD...vX.X.X` to list all the commits since the last release
|
||||
- Categorize the changes into
|
||||
- Breaking Changes (requires a major version)
|
||||
- New Features (minor version)
|
||||
- Fixes (fix version)
|
||||
- Maintenance (which in general should not be mentioned in `CHANGELOG.md` as they have no user impact)
|
||||
2. Update GOMEGA_VERSION in `gomega_dsl.go`
|
||||
3. Push a commit with the version number as the commit message (e.g. `v1.3.0`)
|
||||
4. Create a new [GitHub release](https://help.github.com/articles/creating-releases/) with the version number as the tag (e.g. `v1.3.0`). List the key changes in the release notes.
|
131
vendor/github.com/onsi/gomega/format/format.go
generated
vendored
131
vendor/github.com/onsi/gomega/format/format.go
generated
vendored
@@ -6,8 +6,9 @@ package format
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Use MaxDepth to set the maximum recursion depth when printing deeply nested objects
|
||||
@@ -22,6 +23,28 @@ Note that GoString and String don't always have all the information you need to
|
||||
*/
|
||||
var UseStringerRepresentation = false
|
||||
|
||||
/*
|
||||
Print the content of context objects. By default it will be suppressed.
|
||||
|
||||
Set PrintContextObjects = true to enable printing of the context internals.
|
||||
*/
|
||||
var PrintContextObjects = false
|
||||
|
||||
// TruncatedDiff choose if we should display a truncated pretty diff or not
|
||||
var TruncatedDiff = true
|
||||
|
||||
// Ctx interface defined here to keep backwards compatability with go < 1.7
|
||||
// It matches the context.Context interface
|
||||
type Ctx interface {
|
||||
Deadline() (deadline time.Time, ok bool)
|
||||
Done() <-chan struct{}
|
||||
Err() error
|
||||
Value(key interface{}) interface{}
|
||||
}
|
||||
|
||||
var contextType = reflect.TypeOf((*Ctx)(nil)).Elem()
|
||||
var timeType = reflect.TypeOf(time.Time{})
|
||||
|
||||
//The default indentation string emitted by the format package
|
||||
var Indent = " "
|
||||
|
||||
@@ -44,11 +67,85 @@ If expected is omited, then the message looks like:
|
||||
func Message(actual interface{}, message string, expected ...interface{}) string {
|
||||
if len(expected) == 0 {
|
||||
return fmt.Sprintf("Expected\n%s\n%s", Object(actual, 1), message)
|
||||
} else {
|
||||
return fmt.Sprintf("Expected\n%s\n%s\n%s", Object(actual, 1), message, Object(expected[0], 1))
|
||||
}
|
||||
return fmt.Sprintf("Expected\n%s\n%s\n%s", Object(actual, 1), message, Object(expected[0], 1))
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Generates a nicely formatted matcher success / failure message
|
||||
|
||||
Much like Message(...), but it attempts to pretty print diffs in strings
|
||||
|
||||
Expected
|
||||
<string>: "...aaaaabaaaaa..."
|
||||
to equal |
|
||||
<string>: "...aaaaazaaaaa..."
|
||||
|
||||
*/
|
||||
|
||||
func MessageWithDiff(actual, message, expected string) string {
|
||||
if TruncatedDiff && len(actual) >= truncateThreshold && len(expected) >= truncateThreshold {
|
||||
diffPoint := findFirstMismatch(actual, expected)
|
||||
formattedActual := truncateAndFormat(actual, diffPoint)
|
||||
formattedExpected := truncateAndFormat(expected, diffPoint)
|
||||
|
||||
spacesBeforeFormattedMismatch := findFirstMismatch(formattedActual, formattedExpected)
|
||||
|
||||
tabLength := 4
|
||||
spaceFromMessageToActual := tabLength + len("<string>: ") - len(message)
|
||||
padding := strings.Repeat(" ", spaceFromMessageToActual+spacesBeforeFormattedMismatch) + "|"
|
||||
return Message(formattedActual, message+padding, formattedExpected)
|
||||
}
|
||||
return Message(actual, message, expected)
|
||||
}
|
||||
|
||||
func truncateAndFormat(str string, index int) string {
|
||||
leftPadding := `...`
|
||||
rightPadding := `...`
|
||||
|
||||
start := index - charactersAroundMismatchToInclude
|
||||
if start < 0 {
|
||||
start = 0
|
||||
leftPadding = ""
|
||||
}
|
||||
|
||||
// slice index must include the mis-matched character
|
||||
lengthOfMismatchedCharacter := 1
|
||||
end := index + charactersAroundMismatchToInclude + lengthOfMismatchedCharacter
|
||||
if end > len(str) {
|
||||
end = len(str)
|
||||
rightPadding = ""
|
||||
|
||||
}
|
||||
return fmt.Sprintf("\"%s\"", leftPadding+str[start:end]+rightPadding)
|
||||
}
|
||||
|
||||
func findFirstMismatch(a, b string) int {
|
||||
aSlice := strings.Split(a, "")
|
||||
bSlice := strings.Split(b, "")
|
||||
|
||||
for index, str := range aSlice {
|
||||
if index > len(bSlice)-1 {
|
||||
return index
|
||||
}
|
||||
if str != bSlice[index] {
|
||||
return index
|
||||
}
|
||||
}
|
||||
|
||||
if len(b) > len(a) {
|
||||
return len(a) + 1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
const (
|
||||
truncateThreshold = 50
|
||||
charactersAroundMismatchToInclude = 5
|
||||
)
|
||||
|
||||
/*
|
||||
Pretty prints the passed in object at the passed in indentation level.
|
||||
|
||||
@@ -57,6 +154,8 @@ Object recurses into deeply nested objects emitting pretty-printed representatio
|
||||
Modify format.MaxDepth to control how deep the recursion is allowed to go
|
||||
Set format.UseStringerRepresentation to true to return object.GoString() or object.String() when available instead of
|
||||
recursing into the object.
|
||||
|
||||
Set PrintContextObjects to true to print the content of objects implementing context.Context
|
||||
*/
|
||||
func Object(object interface{}, indentation uint) string {
|
||||
indent := strings.Repeat(Indent, int(indentation))
|
||||
@@ -124,6 +223,12 @@ func formatValue(value reflect.Value, indentation uint) string {
|
||||
}
|
||||
}
|
||||
|
||||
if !PrintContextObjects {
|
||||
if value.Type().Implements(contextType) && indentation > 1 {
|
||||
return "<suppressed context>"
|
||||
}
|
||||
}
|
||||
|
||||
switch value.Kind() {
|
||||
case reflect.Bool:
|
||||
return fmt.Sprintf("%v", value.Bool())
|
||||
@@ -152,15 +257,18 @@ func formatValue(value reflect.Value, indentation uint) string {
|
||||
case reflect.Map:
|
||||
return formatMap(value, indentation)
|
||||
case reflect.Struct:
|
||||
if value.Type() == timeType && value.CanInterface() {
|
||||
t, _ := value.Interface().(time.Time)
|
||||
return t.Format(time.RFC3339Nano)
|
||||
}
|
||||
return formatStruct(value, indentation)
|
||||
case reflect.Interface:
|
||||
return formatValue(value.Elem(), indentation)
|
||||
default:
|
||||
if value.CanInterface() {
|
||||
return fmt.Sprintf("%#v", value.Interface())
|
||||
} else {
|
||||
return fmt.Sprintf("%#v", value)
|
||||
}
|
||||
return fmt.Sprintf("%#v", value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,7 +295,7 @@ func formatString(object interface{}, indentation uint) string {
|
||||
}
|
||||
|
||||
func formatSlice(v reflect.Value, indentation uint) string {
|
||||
if v.Kind() == reflect.Slice && v.Type().Elem().Kind() == reflect.Uint8 && isPrintableString(string(v.Bytes())){
|
||||
if v.Kind() == reflect.Slice && v.Type().Elem().Kind() == reflect.Uint8 && isPrintableString(string(v.Bytes())) {
|
||||
return formatString(v.Bytes(), indentation)
|
||||
}
|
||||
|
||||
@@ -204,9 +312,8 @@ func formatSlice(v reflect.Value, indentation uint) string {
|
||||
if longest > longFormThreshold {
|
||||
indenter := strings.Repeat(Indent, int(indentation))
|
||||
return fmt.Sprintf("[\n%s%s,\n%s]", indenter+Indent, strings.Join(result, ",\n"+indenter+Indent), indenter)
|
||||
} else {
|
||||
return fmt.Sprintf("[%s]", strings.Join(result, ", "))
|
||||
}
|
||||
return fmt.Sprintf("[%s]", strings.Join(result, ", "))
|
||||
}
|
||||
|
||||
func formatMap(v reflect.Value, indentation uint) string {
|
||||
@@ -216,7 +323,7 @@ func formatMap(v reflect.Value, indentation uint) string {
|
||||
longest := 0
|
||||
for i, key := range v.MapKeys() {
|
||||
value := v.MapIndex(key)
|
||||
result[i] = fmt.Sprintf("%s: %s", formatValue(key, 0), formatValue(value, indentation+1))
|
||||
result[i] = fmt.Sprintf("%s: %s", formatValue(key, indentation+1), formatValue(value, indentation+1))
|
||||
if len(result[i]) > longest {
|
||||
longest = len(result[i])
|
||||
}
|
||||
@@ -225,9 +332,8 @@ func formatMap(v reflect.Value, indentation uint) string {
|
||||
if longest > longFormThreshold {
|
||||
indenter := strings.Repeat(Indent, int(indentation))
|
||||
return fmt.Sprintf("{\n%s%s,\n%s}", indenter+Indent, strings.Join(result, ",\n"+indenter+Indent), indenter)
|
||||
} else {
|
||||
return fmt.Sprintf("{%s}", strings.Join(result, ", "))
|
||||
}
|
||||
return fmt.Sprintf("{%s}", strings.Join(result, ", "))
|
||||
}
|
||||
|
||||
func formatStruct(v reflect.Value, indentation uint) string {
|
||||
@@ -248,9 +354,8 @@ func formatStruct(v reflect.Value, indentation uint) string {
|
||||
if longest > longFormThreshold {
|
||||
indenter := strings.Repeat(Indent, int(indentation))
|
||||
return fmt.Sprintf("{\n%s%s,\n%s}", indenter+Indent, strings.Join(result, ",\n"+indenter+Indent), indenter)
|
||||
} else {
|
||||
return fmt.Sprintf("{%s}", strings.Join(result, ", "))
|
||||
}
|
||||
return fmt.Sprintf("{%s}", strings.Join(result, ", "))
|
||||
}
|
||||
|
||||
func isNilValue(a reflect.Value) bool {
|
||||
|
15
vendor/github.com/onsi/gomega/go.mod
generated
vendored
Normal file
15
vendor/github.com/onsi/gomega/go.mod
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
module github.com/onsi/gomega
|
||||
|
||||
require (
|
||||
github.com/fsnotify/fsnotify v1.4.7 // indirect
|
||||
github.com/golang/protobuf v1.2.0
|
||||
github.com/hpcloud/tail v1.0.0 // indirect
|
||||
github.com/onsi/ginkgo v1.6.0
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f // indirect
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e // indirect
|
||||
golang.org/x/text v0.3.0 // indirect
|
||||
gopkg.in/fsnotify.v1 v1.4.7 // indirect
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
|
||||
gopkg.in/yaml.v2 v2.2.1
|
||||
)
|
24
vendor/github.com/onsi/gomega/go.sum
generated
vendored
Normal file
24
vendor/github.com/onsi/gomega/go.sum
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/onsi/ginkgo v1.6.0 h1:Ix8l273rp3QzYgXSR+c8d1fTG7UPgYkOSELPhiY/YGw=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
348
vendor/github.com/onsi/gomega/gomega_dsl.go
generated
vendored
348
vendor/github.com/onsi/gomega/gomega_dsl.go
generated
vendored
@@ -24,56 +24,82 @@ import (
|
||||
"github.com/onsi/gomega/types"
|
||||
)
|
||||
|
||||
const GOMEGA_VERSION = "1.0"
|
||||
const GOMEGA_VERSION = "1.4.3"
|
||||
|
||||
const nilFailHandlerPanic = `You are trying to make an assertion, but Gomega's fail handler is nil.
|
||||
If you're using Ginkgo then you probably forgot to put your assertion in an It().
|
||||
Alternatively, you may have forgotten to register a fail handler with RegisterFailHandler() or RegisterTestingT().
|
||||
Depending on your vendoring solution you may be inadvertently importing gomega and subpackages (e.g. ghhtp, gexec,...) from different locations.
|
||||
`
|
||||
|
||||
var globalFailHandler types.GomegaFailHandler
|
||||
var globalFailWrapper *types.GomegaFailWrapper
|
||||
|
||||
var defaultEventuallyTimeout = time.Second
|
||||
var defaultEventuallyPollingInterval = 10 * time.Millisecond
|
||||
var defaultConsistentlyDuration = 100 * time.Millisecond
|
||||
var defaultConsistentlyPollingInterval = 10 * time.Millisecond
|
||||
|
||||
//RegisterFailHandler connects Ginkgo to Gomega. When a matcher fails
|
||||
//the fail handler passed into RegisterFailHandler is called.
|
||||
// RegisterFailHandler connects Ginkgo to Gomega. When a matcher fails
|
||||
// the fail handler passed into RegisterFailHandler is called.
|
||||
func RegisterFailHandler(handler types.GomegaFailHandler) {
|
||||
globalFailHandler = handler
|
||||
RegisterFailHandlerWithT(testingtsupport.EmptyTWithHelper{}, handler)
|
||||
}
|
||||
|
||||
//RegisterTestingT connects Gomega to Golang's XUnit style
|
||||
//Testing.T tests. You'll need to call this at the top of each XUnit style test:
|
||||
// RegisterFailHandlerWithT ensures that the given types.TWithHelper and fail handler
|
||||
// are used globally.
|
||||
func RegisterFailHandlerWithT(t types.TWithHelper, handler types.GomegaFailHandler) {
|
||||
if handler == nil {
|
||||
globalFailWrapper = nil
|
||||
return
|
||||
}
|
||||
|
||||
globalFailWrapper = &types.GomegaFailWrapper{
|
||||
Fail: handler,
|
||||
TWithHelper: t,
|
||||
}
|
||||
}
|
||||
|
||||
// RegisterTestingT connects Gomega to Golang's XUnit style
|
||||
// Testing.T tests. It is now deprecated and you should use NewWithT() instead.
|
||||
//
|
||||
// func TestFarmHasCow(t *testing.T) {
|
||||
// RegisterTestingT(t)
|
||||
// Legacy Documentation:
|
||||
//
|
||||
// f := farm.New([]string{"Cow", "Horse"})
|
||||
// Expect(f.HasCow()).To(BeTrue(), "Farm should have cow")
|
||||
// }
|
||||
// You'll need to call this at the top of each XUnit style test:
|
||||
//
|
||||
// func TestFarmHasCow(t *testing.T) {
|
||||
// RegisterTestingT(t)
|
||||
//
|
||||
// f := farm.New([]string{"Cow", "Horse"})
|
||||
// Expect(f.HasCow()).To(BeTrue(), "Farm should have cow")
|
||||
// }
|
||||
//
|
||||
// Note that this *testing.T is registered *globally* by Gomega (this is why you don't have to
|
||||
// pass `t` down to the matcher itself). This means that you cannot run the XUnit style tests
|
||||
// in parallel as the global fail handler cannot point to more than one testing.T at a time.
|
||||
//
|
||||
// NewWithT() does not have this limitation
|
||||
//
|
||||
// (As an aside: Ginkgo gets around this limitation by running parallel tests in different *processes*).
|
||||
func RegisterTestingT(t types.GomegaTestingT) {
|
||||
RegisterFailHandler(testingtsupport.BuildTestingTGomegaFailHandler(t))
|
||||
tWithHelper, hasHelper := t.(types.TWithHelper)
|
||||
if !hasHelper {
|
||||
RegisterFailHandler(testingtsupport.BuildTestingTGomegaFailWrapper(t).Fail)
|
||||
return
|
||||
}
|
||||
RegisterFailHandlerWithT(tWithHelper, testingtsupport.BuildTestingTGomegaFailWrapper(t).Fail)
|
||||
}
|
||||
|
||||
//InterceptGomegaHandlers runs a given callback and returns an array of
|
||||
//failure messages generated by any Gomega assertions within the callback.
|
||||
// InterceptGomegaFailures runs a given callback and returns an array of
|
||||
// failure messages generated by any Gomega assertions within the callback.
|
||||
//
|
||||
//This is accomplished by temporarily replacing the *global* fail handler
|
||||
//with a fail handler that simply annotates failures. The original fail handler
|
||||
//is reset when InterceptGomegaFailures returns.
|
||||
// This is accomplished by temporarily replacing the *global* fail handler
|
||||
// with a fail handler that simply annotates failures. The original fail handler
|
||||
// is reset when InterceptGomegaFailures returns.
|
||||
//
|
||||
//This is most useful when testing custom matchers, but can also be used to check
|
||||
//on a value using a Gomega assertion without causing a test failure.
|
||||
// This is most useful when testing custom matchers, but can also be used to check
|
||||
// on a value using a Gomega assertion without causing a test failure.
|
||||
func InterceptGomegaFailures(f func()) []string {
|
||||
originalHandler := globalFailHandler
|
||||
originalHandler := globalFailWrapper.Fail
|
||||
failures := []string{}
|
||||
RegisterFailHandler(func(message string, callerSkip ...int) {
|
||||
failures = append(failures, message)
|
||||
@@ -83,109 +109,109 @@ func InterceptGomegaFailures(f func()) []string {
|
||||
return failures
|
||||
}
|
||||
|
||||
//Ω wraps an actual value allowing assertions to be made on it:
|
||||
// Ω("foo").Should(Equal("foo"))
|
||||
// Ω wraps an actual value allowing assertions to be made on it:
|
||||
// Ω("foo").Should(Equal("foo"))
|
||||
//
|
||||
//If Ω is passed more than one argument it will pass the *first* argument to the matcher.
|
||||
//All subsequent arguments will be required to be nil/zero.
|
||||
// If Ω is passed more than one argument it will pass the *first* argument to the matcher.
|
||||
// All subsequent arguments will be required to be nil/zero.
|
||||
//
|
||||
//This is convenient if you want to make an assertion on a method/function that returns
|
||||
//a value and an error - a common patter in Go.
|
||||
// This is convenient if you want to make an assertion on a method/function that returns
|
||||
// a value and an error - a common patter in Go.
|
||||
//
|
||||
//For example, given a function with signature:
|
||||
// func MyAmazingThing() (int, error)
|
||||
// For example, given a function with signature:
|
||||
// func MyAmazingThing() (int, error)
|
||||
//
|
||||
//Then:
|
||||
// Then:
|
||||
// Ω(MyAmazingThing()).Should(Equal(3))
|
||||
//Will succeed only if `MyAmazingThing()` returns `(3, nil)`
|
||||
// Will succeed only if `MyAmazingThing()` returns `(3, nil)`
|
||||
//
|
||||
//Ω and Expect are identical
|
||||
func Ω(actual interface{}, extra ...interface{}) GomegaAssertion {
|
||||
// Ω and Expect are identical
|
||||
func Ω(actual interface{}, extra ...interface{}) Assertion {
|
||||
return ExpectWithOffset(0, actual, extra...)
|
||||
}
|
||||
|
||||
//Expect wraps an actual value allowing assertions to be made on it:
|
||||
// Expect("foo").To(Equal("foo"))
|
||||
// Expect wraps an actual value allowing assertions to be made on it:
|
||||
// Expect("foo").To(Equal("foo"))
|
||||
//
|
||||
//If Expect is passed more than one argument it will pass the *first* argument to the matcher.
|
||||
//All subsequent arguments will be required to be nil/zero.
|
||||
// If Expect is passed more than one argument it will pass the *first* argument to the matcher.
|
||||
// All subsequent arguments will be required to be nil/zero.
|
||||
//
|
||||
//This is convenient if you want to make an assertion on a method/function that returns
|
||||
//a value and an error - a common patter in Go.
|
||||
// This is convenient if you want to make an assertion on a method/function that returns
|
||||
// a value and an error - a common patter in Go.
|
||||
//
|
||||
//For example, given a function with signature:
|
||||
// func MyAmazingThing() (int, error)
|
||||
// For example, given a function with signature:
|
||||
// func MyAmazingThing() (int, error)
|
||||
//
|
||||
//Then:
|
||||
// Then:
|
||||
// Expect(MyAmazingThing()).Should(Equal(3))
|
||||
//Will succeed only if `MyAmazingThing()` returns `(3, nil)`
|
||||
// Will succeed only if `MyAmazingThing()` returns `(3, nil)`
|
||||
//
|
||||
//Expect and Ω are identical
|
||||
func Expect(actual interface{}, extra ...interface{}) GomegaAssertion {
|
||||
// Expect and Ω are identical
|
||||
func Expect(actual interface{}, extra ...interface{}) Assertion {
|
||||
return ExpectWithOffset(0, actual, extra...)
|
||||
}
|
||||
|
||||
//ExpectWithOffset wraps an actual value allowing assertions to be made on it:
|
||||
// ExpectWithOffset wraps an actual value allowing assertions to be made on it:
|
||||
// ExpectWithOffset(1, "foo").To(Equal("foo"))
|
||||
//
|
||||
//Unlike `Expect` and `Ω`, `ExpectWithOffset` takes an additional integer argument
|
||||
//this is used to modify the call-stack offset when computing line numbers.
|
||||
// Unlike `Expect` and `Ω`, `ExpectWithOffset` takes an additional integer argument
|
||||
// this is used to modify the call-stack offset when computing line numbers.
|
||||
//
|
||||
//This is most useful in helper functions that make assertions. If you want Gomega's
|
||||
//error message to refer to the calling line in the test (as opposed to the line in the helper function)
|
||||
//set the first argument of `ExpectWithOffset` appropriately.
|
||||
func ExpectWithOffset(offset int, actual interface{}, extra ...interface{}) GomegaAssertion {
|
||||
if globalFailHandler == nil {
|
||||
// This is most useful in helper functions that make assertions. If you want Gomega's
|
||||
// error message to refer to the calling line in the test (as opposed to the line in the helper function)
|
||||
// set the first argument of `ExpectWithOffset` appropriately.
|
||||
func ExpectWithOffset(offset int, actual interface{}, extra ...interface{}) Assertion {
|
||||
if globalFailWrapper == nil {
|
||||
panic(nilFailHandlerPanic)
|
||||
}
|
||||
return assertion.New(actual, globalFailHandler, offset, extra...)
|
||||
return assertion.New(actual, globalFailWrapper, offset, extra...)
|
||||
}
|
||||
|
||||
//Eventually wraps an actual value allowing assertions to be made on it.
|
||||
//The assertion is tried periodically until it passes or a timeout occurs.
|
||||
// Eventually wraps an actual value allowing assertions to be made on it.
|
||||
// The assertion is tried periodically until it passes or a timeout occurs.
|
||||
//
|
||||
//Both the timeout and polling interval are configurable as optional arguments:
|
||||
//The first optional argument is the timeout
|
||||
//The second optional argument is the polling interval
|
||||
// Both the timeout and polling interval are configurable as optional arguments:
|
||||
// The first optional argument is the timeout
|
||||
// The second optional argument is the polling interval
|
||||
//
|
||||
//Both intervals can either be specified as time.Duration, parsable duration strings or as floats/integers. In the
|
||||
//last case they are interpreted as seconds.
|
||||
// Both intervals can either be specified as time.Duration, parsable duration strings or as floats/integers. In the
|
||||
// last case they are interpreted as seconds.
|
||||
//
|
||||
//If Eventually is passed an actual that is a function taking no arguments and returning at least one value,
|
||||
//then Eventually will call the function periodically and try the matcher against the function's first return value.
|
||||
// If Eventually is passed an actual that is a function taking no arguments and returning at least one value,
|
||||
// then Eventually will call the function periodically and try the matcher against the function's first return value.
|
||||
//
|
||||
//Example:
|
||||
// Example:
|
||||
//
|
||||
// Eventually(func() int {
|
||||
// return thingImPolling.Count()
|
||||
// }).Should(BeNumerically(">=", 17))
|
||||
//
|
||||
//Note that this example could be rewritten:
|
||||
// Note that this example could be rewritten:
|
||||
//
|
||||
// Eventually(thingImPolling.Count).Should(BeNumerically(">=", 17))
|
||||
//
|
||||
//If the function returns more than one value, then Eventually will pass the first value to the matcher and
|
||||
//assert that all other values are nil/zero.
|
||||
//This allows you to pass Eventually a function that returns a value and an error - a common pattern in Go.
|
||||
// If the function returns more than one value, then Eventually will pass the first value to the matcher and
|
||||
// assert that all other values are nil/zero.
|
||||
// This allows you to pass Eventually a function that returns a value and an error - a common pattern in Go.
|
||||
//
|
||||
//For example, consider a method that returns a value and an error:
|
||||
// For example, consider a method that returns a value and an error:
|
||||
// func FetchFromDB() (string, error)
|
||||
//
|
||||
//Then
|
||||
// Then
|
||||
// Eventually(FetchFromDB).Should(Equal("hasselhoff"))
|
||||
//
|
||||
//Will pass only if the the returned error is nil and the returned string passes the matcher.
|
||||
// Will pass only if the the returned error is nil and the returned string passes the matcher.
|
||||
//
|
||||
//Eventually's default timeout is 1 second, and its default polling interval is 10ms
|
||||
func Eventually(actual interface{}, intervals ...interface{}) GomegaAsyncAssertion {
|
||||
// Eventually's default timeout is 1 second, and its default polling interval is 10ms
|
||||
func Eventually(actual interface{}, intervals ...interface{}) AsyncAssertion {
|
||||
return EventuallyWithOffset(0, actual, intervals...)
|
||||
}
|
||||
|
||||
//EventuallyWithOffset operates like Eventually but takes an additional
|
||||
//initial argument to indicate an offset in the call stack. This is useful when building helper
|
||||
//functions that contain matchers. To learn more, read about `ExpectWithOffset`.
|
||||
func EventuallyWithOffset(offset int, actual interface{}, intervals ...interface{}) GomegaAsyncAssertion {
|
||||
if globalFailHandler == nil {
|
||||
// EventuallyWithOffset operates like Eventually but takes an additional
|
||||
// initial argument to indicate an offset in the call stack. This is useful when building helper
|
||||
// functions that contain matchers. To learn more, read about `ExpectWithOffset`.
|
||||
func EventuallyWithOffset(offset int, actual interface{}, intervals ...interface{}) AsyncAssertion {
|
||||
if globalFailWrapper == nil {
|
||||
panic(nilFailHandlerPanic)
|
||||
}
|
||||
timeoutInterval := defaultEventuallyTimeout
|
||||
@@ -196,41 +222,41 @@ func EventuallyWithOffset(offset int, actual interface{}, intervals ...interface
|
||||
if len(intervals) > 1 {
|
||||
pollingInterval = toDuration(intervals[1])
|
||||
}
|
||||
return asyncassertion.New(asyncassertion.AsyncAssertionTypeEventually, actual, globalFailHandler, timeoutInterval, pollingInterval, offset)
|
||||
return asyncassertion.New(asyncassertion.AsyncAssertionTypeEventually, actual, globalFailWrapper, timeoutInterval, pollingInterval, offset)
|
||||
}
|
||||
|
||||
//Consistently wraps an actual value allowing assertions to be made on it.
|
||||
//The assertion is tried periodically and is required to pass for a period of time.
|
||||
// Consistently wraps an actual value allowing assertions to be made on it.
|
||||
// The assertion is tried periodically and is required to pass for a period of time.
|
||||
//
|
||||
//Both the total time and polling interval are configurable as optional arguments:
|
||||
//The first optional argument is the duration that Consistently will run for
|
||||
//The second optional argument is the polling interval
|
||||
// Both the total time and polling interval are configurable as optional arguments:
|
||||
// The first optional argument is the duration that Consistently will run for
|
||||
// The second optional argument is the polling interval
|
||||
//
|
||||
//Both intervals can either be specified as time.Duration, parsable duration strings or as floats/integers. In the
|
||||
//last case they are interpreted as seconds.
|
||||
// Both intervals can either be specified as time.Duration, parsable duration strings or as floats/integers. In the
|
||||
// last case they are interpreted as seconds.
|
||||
//
|
||||
//If Consistently is passed an actual that is a function taking no arguments and returning at least one value,
|
||||
//then Consistently will call the function periodically and try the matcher against the function's first return value.
|
||||
// If Consistently is passed an actual that is a function taking no arguments and returning at least one value,
|
||||
// then Consistently will call the function periodically and try the matcher against the function's first return value.
|
||||
//
|
||||
//If the function returns more than one value, then Consistently will pass the first value to the matcher and
|
||||
//assert that all other values are nil/zero.
|
||||
//This allows you to pass Consistently a function that returns a value and an error - a common pattern in Go.
|
||||
// If the function returns more than one value, then Consistently will pass the first value to the matcher and
|
||||
// assert that all other values are nil/zero.
|
||||
// This allows you to pass Consistently a function that returns a value and an error - a common pattern in Go.
|
||||
//
|
||||
//Consistently is useful in cases where you want to assert that something *does not happen* over a period of tiem.
|
||||
//For example, you want to assert that a goroutine does *not* send data down a channel. In this case, you could:
|
||||
// Consistently is useful in cases where you want to assert that something *does not happen* over a period of tiem.
|
||||
// For example, you want to assert that a goroutine does *not* send data down a channel. In this case, you could:
|
||||
//
|
||||
// Consistently(channel).ShouldNot(Receive())
|
||||
// Consistently(channel).ShouldNot(Receive())
|
||||
//
|
||||
//Consistently's default duration is 100ms, and its default polling interval is 10ms
|
||||
func Consistently(actual interface{}, intervals ...interface{}) GomegaAsyncAssertion {
|
||||
// Consistently's default duration is 100ms, and its default polling interval is 10ms
|
||||
func Consistently(actual interface{}, intervals ...interface{}) AsyncAssertion {
|
||||
return ConsistentlyWithOffset(0, actual, intervals...)
|
||||
}
|
||||
|
||||
//ConsistentlyWithOffset operates like Consistnetly but takes an additional
|
||||
//initial argument to indicate an offset in the call stack. This is useful when building helper
|
||||
//functions that contain matchers. To learn more, read about `ExpectWithOffset`.
|
||||
func ConsistentlyWithOffset(offset int, actual interface{}, intervals ...interface{}) GomegaAsyncAssertion {
|
||||
if globalFailHandler == nil {
|
||||
// ConsistentlyWithOffset operates like Consistnetly but takes an additional
|
||||
// initial argument to indicate an offset in the call stack. This is useful when building helper
|
||||
// functions that contain matchers. To learn more, read about `ExpectWithOffset`.
|
||||
func ConsistentlyWithOffset(offset int, actual interface{}, intervals ...interface{}) AsyncAssertion {
|
||||
if globalFailWrapper == nil {
|
||||
panic(nilFailHandlerPanic)
|
||||
}
|
||||
timeoutInterval := defaultConsistentlyDuration
|
||||
@@ -241,62 +267,65 @@ func ConsistentlyWithOffset(offset int, actual interface{}, intervals ...interfa
|
||||
if len(intervals) > 1 {
|
||||
pollingInterval = toDuration(intervals[1])
|
||||
}
|
||||
return asyncassertion.New(asyncassertion.AsyncAssertionTypeConsistently, actual, globalFailHandler, timeoutInterval, pollingInterval, offset)
|
||||
return asyncassertion.New(asyncassertion.AsyncAssertionTypeConsistently, actual, globalFailWrapper, timeoutInterval, pollingInterval, offset)
|
||||
}
|
||||
|
||||
//Set the default timeout duration for Eventually. Eventually will repeatedly poll your condition until it succeeds, or until this timeout elapses.
|
||||
// SetDefaultEventuallyTimeout sets the default timeout duration for Eventually. Eventually will repeatedly poll your condition until it succeeds, or until this timeout elapses.
|
||||
func SetDefaultEventuallyTimeout(t time.Duration) {
|
||||
defaultEventuallyTimeout = t
|
||||
}
|
||||
|
||||
//Set the default polling interval for Eventually.
|
||||
// SetDefaultEventuallyPollingInterval sets the default polling interval for Eventually.
|
||||
func SetDefaultEventuallyPollingInterval(t time.Duration) {
|
||||
defaultEventuallyPollingInterval = t
|
||||
}
|
||||
|
||||
//Set the default duration for Consistently. Consistently will verify that your condition is satsified for this long.
|
||||
// SetDefaultConsistentlyDuration sets the default duration for Consistently. Consistently will verify that your condition is satsified for this long.
|
||||
func SetDefaultConsistentlyDuration(t time.Duration) {
|
||||
defaultConsistentlyDuration = t
|
||||
}
|
||||
|
||||
//Set the default polling interval for Consistently.
|
||||
// SetDefaultConsistentlyPollingInterval sets the default polling interval for Consistently.
|
||||
func SetDefaultConsistentlyPollingInterval(t time.Duration) {
|
||||
defaultConsistentlyPollingInterval = t
|
||||
}
|
||||
|
||||
//GomegaAsyncAssertion is returned by Eventually and Consistently and polls the actual value passed into Eventually against
|
||||
//the matcher passed to the Should and ShouldNot methods.
|
||||
// AsyncAssertion is returned by Eventually and Consistently and polls the actual value passed into Eventually against
|
||||
// the matcher passed to the Should and ShouldNot methods.
|
||||
//
|
||||
//Both Should and ShouldNot take a variadic optionalDescription argument. This is passed on to
|
||||
//fmt.Sprintf() and is used to annotate failure messages. This allows you to make your failure messages more
|
||||
//descriptive
|
||||
// Both Should and ShouldNot take a variadic optionalDescription argument. This is passed on to
|
||||
// fmt.Sprintf() and is used to annotate failure messages. This allows you to make your failure messages more
|
||||
// descriptive.
|
||||
//
|
||||
//Both Should and ShouldNot return a boolean that is true if the assertion passed and false if it failed.
|
||||
// Both Should and ShouldNot return a boolean that is true if the assertion passed and false if it failed.
|
||||
//
|
||||
//Example:
|
||||
// Example:
|
||||
//
|
||||
// Eventually(myChannel).Should(Receive(), "Something should have come down the pipe.")
|
||||
// Consistently(myChannel).ShouldNot(Receive(), "Nothing should have come down the pipe.")
|
||||
type GomegaAsyncAssertion interface {
|
||||
// Eventually(myChannel).Should(Receive(), "Something should have come down the pipe.")
|
||||
// Consistently(myChannel).ShouldNot(Receive(), "Nothing should have come down the pipe.")
|
||||
type AsyncAssertion interface {
|
||||
Should(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
|
||||
ShouldNot(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
|
||||
}
|
||||
|
||||
//GomegaAssertion is returned by Ω and Expect and compares the actual value to the matcher
|
||||
//passed to the Should/ShouldNot and To/ToNot/NotTo methods.
|
||||
// GomegaAsyncAssertion is deprecated in favor of AsyncAssertion, which does not stutter.
|
||||
type GomegaAsyncAssertion = AsyncAssertion
|
||||
|
||||
// Assertion is returned by Ω and Expect and compares the actual value to the matcher
|
||||
// passed to the Should/ShouldNot and To/ToNot/NotTo methods.
|
||||
//
|
||||
//Typically Should/ShouldNot are used with Ω and To/ToNot/NotTo are used with Expect
|
||||
//though this is not enforced.
|
||||
// Typically Should/ShouldNot are used with Ω and To/ToNot/NotTo are used with Expect
|
||||
// though this is not enforced.
|
||||
//
|
||||
//All methods take a variadic optionalDescription argument. This is passed on to fmt.Sprintf()
|
||||
//and is used to annotate failure messages.
|
||||
// All methods take a variadic optionalDescription argument. This is passed on to fmt.Sprintf()
|
||||
// and is used to annotate failure messages.
|
||||
//
|
||||
//All methods return a bool that is true if hte assertion passed and false if it failed.
|
||||
// All methods return a bool that is true if hte assertion passed and false if it failed.
|
||||
//
|
||||
//Example:
|
||||
// Example:
|
||||
//
|
||||
// Ω(farm.HasCow()).Should(BeTrue(), "Farm %v should have a cow", farm)
|
||||
type GomegaAssertion interface {
|
||||
// Ω(farm.HasCow()).Should(BeTrue(), "Farm %v should have a cow", farm)
|
||||
type Assertion interface {
|
||||
Should(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
|
||||
ShouldNot(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
|
||||
|
||||
@@ -305,9 +334,74 @@ type GomegaAssertion interface {
|
||||
NotTo(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
|
||||
}
|
||||
|
||||
//OmegaMatcher is deprecated in favor of the better-named and better-organized types.GomegaMatcher but sticks around to support existing code that uses it
|
||||
// GomegaAssertion is deprecated in favor of Assertion, which does not stutter.
|
||||
type GomegaAssertion = Assertion
|
||||
|
||||
// OmegaMatcher is deprecated in favor of the better-named and better-organized types.GomegaMatcher but sticks around to support existing code that uses it
|
||||
type OmegaMatcher types.GomegaMatcher
|
||||
|
||||
// WithT wraps a *testing.T and provides `Expect`, `Eventually`, and `Consistently` methods. This allows you to leverage
|
||||
// Gomega's rich ecosystem of matchers in standard `testing` test suites.
|
||||
//
|
||||
// Use `NewWithT` to instantiate a `WithT`
|
||||
type WithT struct {
|
||||
t types.GomegaTestingT
|
||||
}
|
||||
|
||||
// GomegaWithT is deprecated in favor of gomega.WithT, which does not stutter.
|
||||
type GomegaWithT = WithT
|
||||
|
||||
// NewWithT takes a *testing.T and returngs a `gomega.WithT` allowing you to use `Expect`, `Eventually`, and `Consistently` along with
|
||||
// Gomega's rich ecosystem of matchers in standard `testing` test suits.
|
||||
//
|
||||
// func TestFarmHasCow(t *testing.T) {
|
||||
// g := gomega.NewWithT(t)
|
||||
//
|
||||
// f := farm.New([]string{"Cow", "Horse"})
|
||||
// g.Expect(f.HasCow()).To(BeTrue(), "Farm should have cow")
|
||||
// }
|
||||
func NewWithT(t types.GomegaTestingT) *WithT {
|
||||
return &WithT{
|
||||
t: t,
|
||||
}
|
||||
}
|
||||
|
||||
// NewGomegaWithT is deprecated in favor of gomega.NewWithT, which does not stutter.
|
||||
func NewGomegaWithT(t types.GomegaTestingT) *GomegaWithT {
|
||||
return NewWithT(t)
|
||||
}
|
||||
|
||||
// Expect is used to make assertions. See documentation for Expect.
|
||||
func (g *WithT) Expect(actual interface{}, extra ...interface{}) Assertion {
|
||||
return assertion.New(actual, testingtsupport.BuildTestingTGomegaFailWrapper(g.t), 0, extra...)
|
||||
}
|
||||
|
||||
// Eventually is used to make asynchronous assertions. See documentation for Eventually.
|
||||
func (g *WithT) Eventually(actual interface{}, intervals ...interface{}) AsyncAssertion {
|
||||
timeoutInterval := defaultEventuallyTimeout
|
||||
pollingInterval := defaultEventuallyPollingInterval
|
||||
if len(intervals) > 0 {
|
||||
timeoutInterval = toDuration(intervals[0])
|
||||
}
|
||||
if len(intervals) > 1 {
|
||||
pollingInterval = toDuration(intervals[1])
|
||||
}
|
||||
return asyncassertion.New(asyncassertion.AsyncAssertionTypeEventually, actual, testingtsupport.BuildTestingTGomegaFailWrapper(g.t), timeoutInterval, pollingInterval, 0)
|
||||
}
|
||||
|
||||
// Consistently is used to make asynchronous assertions. See documentation for Consistently.
|
||||
func (g *WithT) Consistently(actual interface{}, intervals ...interface{}) AsyncAssertion {
|
||||
timeoutInterval := defaultConsistentlyDuration
|
||||
pollingInterval := defaultConsistentlyPollingInterval
|
||||
if len(intervals) > 0 {
|
||||
timeoutInterval = toDuration(intervals[0])
|
||||
}
|
||||
if len(intervals) > 1 {
|
||||
pollingInterval = toDuration(intervals[1])
|
||||
}
|
||||
return asyncassertion.New(asyncassertion.AsyncAssertionTypeConsistently, actual, testingtsupport.BuildTestingTGomegaFailWrapper(g.t), timeoutInterval, pollingInterval, 0)
|
||||
}
|
||||
|
||||
func toDuration(input interface{}) time.Duration {
|
||||
duration, ok := input.(time.Duration)
|
||||
if ok {
|
||||
|
1
vendor/github.com/onsi/gomega/gstruct/BUILD
generated
vendored
1
vendor/github.com/onsi/gomega/gstruct/BUILD
generated
vendored
@@ -6,6 +6,7 @@ go_library(
|
||||
"elements.go",
|
||||
"fields.go",
|
||||
"ignore.go",
|
||||
"keys.go",
|
||||
"pointer.go",
|
||||
"types.go",
|
||||
],
|
||||
|
48
vendor/github.com/onsi/gomega/gstruct/elements.go
generated
vendored
48
vendor/github.com/onsi/gomega/gstruct/elements.go
generated
vendored
@@ -13,10 +13,14 @@ import (
|
||||
|
||||
//MatchAllElements succeeds if every element of a slice matches the element matcher it maps to
|
||||
//through the id function, and every element matcher is matched.
|
||||
// Expect([]string{"a", "b"}).To(MatchAllElements(idFn, matchers.Elements{
|
||||
// "a": BeEqual("a"),
|
||||
// "b": BeEqual("b"),
|
||||
// })
|
||||
// idFn := func(element interface{}) string {
|
||||
// return fmt.Sprintf("%v", element)
|
||||
// }
|
||||
//
|
||||
// Expect([]string{"a", "b"}).To(MatchAllElements(idFn, Elements{
|
||||
// "a": Equal("a"),
|
||||
// "b": Equal("b"),
|
||||
// }))
|
||||
func MatchAllElements(identifier Identifier, elements Elements) types.GomegaMatcher {
|
||||
return &ElementsMatcher{
|
||||
Identifier: identifier,
|
||||
@@ -26,16 +30,27 @@ func MatchAllElements(identifier Identifier, elements Elements) types.GomegaMatc
|
||||
|
||||
//MatchElements succeeds if each element of a slice matches the element matcher it maps to
|
||||
//through the id function. It can ignore extra elements and/or missing elements.
|
||||
// Expect([]string{"a", "c"}).To(MatchElements(idFn, IgnoreMissing|IgnoreExtra, matchers.Elements{
|
||||
// "a": BeEqual("a")
|
||||
// "b": BeEqual("b"),
|
||||
// })
|
||||
// idFn := func(element interface{}) string {
|
||||
// return fmt.Sprintf("%v", element)
|
||||
// }
|
||||
//
|
||||
// Expect([]string{"a", "b", "c"}).To(MatchElements(idFn, IgnoreExtras, Elements{
|
||||
// "a": Equal("a"),
|
||||
// "b": Equal("b"),
|
||||
// }))
|
||||
// Expect([]string{"a", "c"}).To(MatchElements(idFn, IgnoreMissing, Elements{
|
||||
// "a": Equal("a"),
|
||||
// "b": Equal("b"),
|
||||
// "c": Equal("c"),
|
||||
// "d": Equal("d"),
|
||||
// }))
|
||||
func MatchElements(identifier Identifier, options Options, elements Elements) types.GomegaMatcher {
|
||||
return &ElementsMatcher{
|
||||
Identifier: identifier,
|
||||
Elements: elements,
|
||||
IgnoreExtras: options&IgnoreExtras != 0,
|
||||
IgnoreMissing: options&IgnoreMissing != 0,
|
||||
Identifier: identifier,
|
||||
Elements: elements,
|
||||
IgnoreExtras: options&IgnoreExtras != 0,
|
||||
IgnoreMissing: options&IgnoreMissing != 0,
|
||||
AllowDuplicates: options&AllowDuplicates != 0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +67,8 @@ type ElementsMatcher struct {
|
||||
IgnoreExtras bool
|
||||
// Whether to ignore missing elements or consider it an error.
|
||||
IgnoreMissing bool
|
||||
// Whether to key duplicates when matching IDs.
|
||||
AllowDuplicates bool
|
||||
|
||||
// State.
|
||||
failures []error
|
||||
@@ -88,10 +105,11 @@ func (m *ElementsMatcher) matchElements(actual interface{}) (errs []error) {
|
||||
for i := 0; i < val.Len(); i++ {
|
||||
element := val.Index(i).Interface()
|
||||
id := m.Identifier(element)
|
||||
// TODO: Add options to ignore & match duplicates.
|
||||
if elements[id] {
|
||||
errs = append(errs, fmt.Errorf("found duplicate element ID %s", id))
|
||||
continue
|
||||
if !m.AllowDuplicates {
|
||||
errs = append(errs, fmt.Errorf("found duplicate element ID %s", id))
|
||||
continue
|
||||
}
|
||||
}
|
||||
elements[id] = true
|
||||
|
||||
|
43
vendor/github.com/onsi/gomega/gstruct/fields.go
generated
vendored
43
vendor/github.com/onsi/gomega/gstruct/fields.go
generated
vendored
@@ -14,10 +14,21 @@ import (
|
||||
|
||||
//MatchAllFields succeeds if every field of a struct matches the field matcher associated with
|
||||
//it, and every element matcher is matched.
|
||||
// Expect([]string{"a", "b"}).To(MatchAllFields(idFn, gstruct.Fields{
|
||||
// "a": BeEqual("a"),
|
||||
// "b": BeEqual("b"),
|
||||
// })
|
||||
// actual := struct{
|
||||
// A int
|
||||
// B []bool
|
||||
// C string
|
||||
// }{
|
||||
// A: 5,
|
||||
// B: []bool{true, false},
|
||||
// C: "foo",
|
||||
// }
|
||||
//
|
||||
// Expect(actual).To(MatchAllFields(Fields{
|
||||
// "A": Equal(5),
|
||||
// "B": ConsistOf(true, false),
|
||||
// "C": Equal("foo"),
|
||||
// }))
|
||||
func MatchAllFields(fields Fields) types.GomegaMatcher {
|
||||
return &FieldsMatcher{
|
||||
Fields: fields,
|
||||
@@ -26,10 +37,26 @@ func MatchAllFields(fields Fields) types.GomegaMatcher {
|
||||
|
||||
//MatchFields succeeds if each element of a struct matches the field matcher associated with
|
||||
//it. It can ignore extra fields and/or missing fields.
|
||||
// Expect([]string{"a", "c"}).To(MatchFields(idFn, IgnoreMissing|IgnoreExtra, gstruct.Fields{
|
||||
// "a": BeEqual("a")
|
||||
// "b": BeEqual("b"),
|
||||
// })
|
||||
// actual := struct{
|
||||
// A int
|
||||
// B []bool
|
||||
// C string
|
||||
// }{
|
||||
// A: 5,
|
||||
// B: []bool{true, false},
|
||||
// C: "foo",
|
||||
// }
|
||||
//
|
||||
// Expect(actual).To(MatchFields(IgnoreExtras, Fields{
|
||||
// "A": Equal(5),
|
||||
// "B": ConsistOf(true, false),
|
||||
// }))
|
||||
// Expect(actual).To(MatchFields(IgnoreMissing, Fields{
|
||||
// "A": Equal(5),
|
||||
// "B": ConsistOf(true, false),
|
||||
// "C": Equal("foo"),
|
||||
// "D": Equal("extra"),
|
||||
// }))
|
||||
func MatchFields(options Options, fields Fields) types.GomegaMatcher {
|
||||
return &FieldsMatcher{
|
||||
Fields: fields,
|
||||
|
124
vendor/github.com/onsi/gomega/gstruct/keys.go
generated
vendored
Normal file
124
vendor/github.com/onsi/gomega/gstruct/keys.go
generated
vendored
Normal file
@@ -0,0 +1,124 @@
|
||||
package gstruct
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
errorsutil "github.com/onsi/gomega/gstruct/errors"
|
||||
"github.com/onsi/gomega/types"
|
||||
)
|
||||
|
||||
func MatchAllKeys(keys Keys) types.GomegaMatcher {
|
||||
return &KeysMatcher{
|
||||
Keys: keys,
|
||||
}
|
||||
}
|
||||
|
||||
func MatchKeys(options Options, keys Keys) types.GomegaMatcher {
|
||||
return &KeysMatcher{
|
||||
Keys: keys,
|
||||
IgnoreExtras: options&IgnoreExtras != 0,
|
||||
IgnoreMissing: options&IgnoreMissing != 0,
|
||||
}
|
||||
}
|
||||
|
||||
type KeysMatcher struct {
|
||||
// Matchers for each key.
|
||||
Keys Keys
|
||||
|
||||
// Whether to ignore extra keys or consider it an error.
|
||||
IgnoreExtras bool
|
||||
// Whether to ignore missing keys or consider it an error.
|
||||
IgnoreMissing bool
|
||||
|
||||
// State.
|
||||
failures []error
|
||||
}
|
||||
|
||||
type Keys map[interface{}]types.GomegaMatcher
|
||||
|
||||
func (m *KeysMatcher) Match(actual interface{}) (success bool, err error) {
|
||||
if reflect.TypeOf(actual).Kind() != reflect.Map {
|
||||
return false, fmt.Errorf("%v is type %T, expected map", actual, actual)
|
||||
}
|
||||
|
||||
m.failures = m.matchKeys(actual)
|
||||
if len(m.failures) > 0 {
|
||||
return false, nil
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (m *KeysMatcher) matchKeys(actual interface{}) (errs []error) {
|
||||
actualValue := reflect.ValueOf(actual)
|
||||
keys := map[interface{}]bool{}
|
||||
for _, keyValue := range actualValue.MapKeys() {
|
||||
key := keyValue.Interface()
|
||||
keys[key] = true
|
||||
|
||||
err := func() (err error) {
|
||||
// This test relies heavily on reflect, which tends to panic.
|
||||
// Recover here to provide more useful error messages in that case.
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
err = fmt.Errorf("panic checking %+v: %v\n%s", actual, r, debug.Stack())
|
||||
}
|
||||
}()
|
||||
|
||||
matcher, ok := m.Keys[key]
|
||||
if !ok {
|
||||
if !m.IgnoreExtras {
|
||||
return fmt.Errorf("unexpected key %s: %+v", key, actual)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
valValue := actualValue.MapIndex(keyValue)
|
||||
|
||||
match, err := matcher.Match(valValue.Interface())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !match {
|
||||
if nesting, ok := matcher.(errorsutil.NestingMatcher); ok {
|
||||
return errorsutil.AggregateError(nesting.Failures())
|
||||
}
|
||||
return errors.New(matcher.FailureMessage(valValue))
|
||||
}
|
||||
return nil
|
||||
}()
|
||||
if err != nil {
|
||||
errs = append(errs, errorsutil.Nest(fmt.Sprintf(".%#v", key), err))
|
||||
}
|
||||
}
|
||||
|
||||
for key := range m.Keys {
|
||||
if !keys[key] && !m.IgnoreMissing {
|
||||
errs = append(errs, fmt.Errorf("missing expected key %s", key))
|
||||
}
|
||||
}
|
||||
|
||||
return errs
|
||||
}
|
||||
|
||||
func (m *KeysMatcher) FailureMessage(actual interface{}) (message string) {
|
||||
failures := make([]string, len(m.failures))
|
||||
for i := range m.failures {
|
||||
failures[i] = m.failures[i].Error()
|
||||
}
|
||||
return format.Message(reflect.TypeOf(actual).Name(),
|
||||
fmt.Sprintf("to match keys: {\n%v\n}\n", strings.Join(failures, "\n")))
|
||||
}
|
||||
|
||||
func (m *KeysMatcher) NegatedFailureMessage(actual interface{}) (message string) {
|
||||
return format.Message(actual, "not to match keys")
|
||||
}
|
||||
|
||||
func (m *KeysMatcher) Failures() []error {
|
||||
return m.failures
|
||||
}
|
4
vendor/github.com/onsi/gomega/gstruct/types.go
generated
vendored
4
vendor/github.com/onsi/gomega/gstruct/types.go
generated
vendored
@@ -8,4 +8,8 @@ const (
|
||||
IgnoreExtras Options = 1 << iota
|
||||
//IgnoreMissing tells the matcher to ignore missing elements or fields, rather than triggering a failure.
|
||||
IgnoreMissing
|
||||
//AllowDuplicates tells the matcher to permit multiple members of the slice to produce the same ID when
|
||||
//considered by the indentifier function. All members that map to a given key must still match successfully
|
||||
//with the matcher that is provided for that key.
|
||||
AllowDuplicates
|
||||
)
|
||||
|
19
vendor/github.com/onsi/gomega/internal/assertion/assertion.go
generated
vendored
19
vendor/github.com/onsi/gomega/internal/assertion/assertion.go
generated
vendored
@@ -9,37 +9,42 @@ import (
|
||||
|
||||
type Assertion struct {
|
||||
actualInput interface{}
|
||||
fail types.GomegaFailHandler
|
||||
failWrapper *types.GomegaFailWrapper
|
||||
offset int
|
||||
extra []interface{}
|
||||
}
|
||||
|
||||
func New(actualInput interface{}, fail types.GomegaFailHandler, offset int, extra ...interface{}) *Assertion {
|
||||
func New(actualInput interface{}, failWrapper *types.GomegaFailWrapper, offset int, extra ...interface{}) *Assertion {
|
||||
return &Assertion{
|
||||
actualInput: actualInput,
|
||||
fail: fail,
|
||||
failWrapper: failWrapper,
|
||||
offset: offset,
|
||||
extra: extra,
|
||||
}
|
||||
}
|
||||
|
||||
func (assertion *Assertion) Should(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
|
||||
assertion.failWrapper.TWithHelper.Helper()
|
||||
return assertion.vetExtras(optionalDescription...) && assertion.match(matcher, true, optionalDescription...)
|
||||
}
|
||||
|
||||
func (assertion *Assertion) ShouldNot(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
|
||||
assertion.failWrapper.TWithHelper.Helper()
|
||||
return assertion.vetExtras(optionalDescription...) && assertion.match(matcher, false, optionalDescription...)
|
||||
}
|
||||
|
||||
func (assertion *Assertion) To(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
|
||||
assertion.failWrapper.TWithHelper.Helper()
|
||||
return assertion.vetExtras(optionalDescription...) && assertion.match(matcher, true, optionalDescription...)
|
||||
}
|
||||
|
||||
func (assertion *Assertion) ToNot(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
|
||||
assertion.failWrapper.TWithHelper.Helper()
|
||||
return assertion.vetExtras(optionalDescription...) && assertion.match(matcher, false, optionalDescription...)
|
||||
}
|
||||
|
||||
func (assertion *Assertion) NotTo(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
|
||||
assertion.failWrapper.TWithHelper.Helper()
|
||||
return assertion.vetExtras(optionalDescription...) && assertion.match(matcher, false, optionalDescription...)
|
||||
}
|
||||
|
||||
@@ -55,8 +60,9 @@ func (assertion *Assertion) buildDescription(optionalDescription ...interface{})
|
||||
func (assertion *Assertion) match(matcher types.GomegaMatcher, desiredMatch bool, optionalDescription ...interface{}) bool {
|
||||
matches, err := matcher.Match(assertion.actualInput)
|
||||
description := assertion.buildDescription(optionalDescription...)
|
||||
assertion.failWrapper.TWithHelper.Helper()
|
||||
if err != nil {
|
||||
assertion.fail(description+err.Error(), 2+assertion.offset)
|
||||
assertion.failWrapper.Fail(description+err.Error(), 2+assertion.offset)
|
||||
return false
|
||||
}
|
||||
if matches != desiredMatch {
|
||||
@@ -66,7 +72,7 @@ func (assertion *Assertion) match(matcher types.GomegaMatcher, desiredMatch bool
|
||||
} else {
|
||||
message = matcher.NegatedFailureMessage(assertion.actualInput)
|
||||
}
|
||||
assertion.fail(description+message, 2+assertion.offset)
|
||||
assertion.failWrapper.Fail(description+message, 2+assertion.offset)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -80,7 +86,8 @@ func (assertion *Assertion) vetExtras(optionalDescription ...interface{}) bool {
|
||||
}
|
||||
|
||||
description := assertion.buildDescription(optionalDescription...)
|
||||
assertion.fail(description+message, 2+assertion.offset)
|
||||
assertion.failWrapper.TWithHelper.Helper()
|
||||
assertion.failWrapper.Fail(description+message, 2+assertion.offset)
|
||||
return false
|
||||
}
|
||||
|
||||
|
13
vendor/github.com/onsi/gomega/internal/asyncassertion/async_assertion.go
generated
vendored
13
vendor/github.com/onsi/gomega/internal/asyncassertion/async_assertion.go
generated
vendored
@@ -22,11 +22,11 @@ type AsyncAssertion struct {
|
||||
actualInput interface{}
|
||||
timeoutInterval time.Duration
|
||||
pollingInterval time.Duration
|
||||
fail types.GomegaFailHandler
|
||||
failWrapper *types.GomegaFailWrapper
|
||||
offset int
|
||||
}
|
||||
|
||||
func New(asyncType AsyncAssertionType, actualInput interface{}, fail types.GomegaFailHandler, timeoutInterval time.Duration, pollingInterval time.Duration, offset int) *AsyncAssertion {
|
||||
func New(asyncType AsyncAssertionType, actualInput interface{}, failWrapper *types.GomegaFailWrapper, timeoutInterval time.Duration, pollingInterval time.Duration, offset int) *AsyncAssertion {
|
||||
actualType := reflect.TypeOf(actualInput)
|
||||
if actualType.Kind() == reflect.Func {
|
||||
if actualType.NumIn() != 0 || actualType.NumOut() == 0 {
|
||||
@@ -37,7 +37,7 @@ func New(asyncType AsyncAssertionType, actualInput interface{}, fail types.Gomeg
|
||||
return &AsyncAssertion{
|
||||
asyncType: asyncType,
|
||||
actualInput: actualInput,
|
||||
fail: fail,
|
||||
failWrapper: failWrapper,
|
||||
timeoutInterval: timeoutInterval,
|
||||
pollingInterval: pollingInterval,
|
||||
offset: offset,
|
||||
@@ -45,10 +45,12 @@ func New(asyncType AsyncAssertionType, actualInput interface{}, fail types.Gomeg
|
||||
}
|
||||
|
||||
func (assertion *AsyncAssertion) Should(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
|
||||
assertion.failWrapper.TWithHelper.Helper()
|
||||
return assertion.match(matcher, true, optionalDescription...)
|
||||
}
|
||||
|
||||
func (assertion *AsyncAssertion) ShouldNot(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool {
|
||||
assertion.failWrapper.TWithHelper.Helper()
|
||||
return assertion.match(matcher, false, optionalDescription...)
|
||||
}
|
||||
|
||||
@@ -110,6 +112,8 @@ func (assertion *AsyncAssertion) match(matcher types.GomegaMatcher, desiredMatch
|
||||
matches, err = matcher.Match(value)
|
||||
}
|
||||
|
||||
assertion.failWrapper.TWithHelper.Helper()
|
||||
|
||||
fail := func(preamble string) {
|
||||
errMsg := ""
|
||||
message := ""
|
||||
@@ -122,7 +126,8 @@ func (assertion *AsyncAssertion) match(matcher types.GomegaMatcher, desiredMatch
|
||||
message = matcher.NegatedFailureMessage(value)
|
||||
}
|
||||
}
|
||||
assertion.fail(fmt.Sprintf("%s after %.3fs.\n%s%s%s", preamble, time.Since(timer).Seconds(), description, message, errMsg), 3+assertion.offset)
|
||||
assertion.failWrapper.TWithHelper.Helper()
|
||||
assertion.failWrapper.Fail(fmt.Sprintf("%s after %.3fs.\n%s%s%s", preamble, time.Since(timer).Seconds(), description, message, errMsg), 3+assertion.offset)
|
||||
}
|
||||
|
||||
if assertion.asyncType == AsyncAssertionTypeEventually {
|
||||
|
46
vendor/github.com/onsi/gomega/internal/testingtsupport/testing_t_support.go
generated
vendored
46
vendor/github.com/onsi/gomega/internal/testingtsupport/testing_t_support.go
generated
vendored
@@ -8,30 +8,50 @@ import (
|
||||
"github.com/onsi/gomega/types"
|
||||
)
|
||||
|
||||
var StackTracePruneRE = regexp.MustCompile(`\/gomega\/|\/ginkgo\/|\/pkg\/testing\/|\/pkg\/runtime\/`)
|
||||
|
||||
type EmptyTWithHelper struct{}
|
||||
|
||||
func (e EmptyTWithHelper) Helper() {}
|
||||
|
||||
type gomegaTestingT interface {
|
||||
Errorf(format string, args ...interface{})
|
||||
Fatalf(format string, args ...interface{})
|
||||
}
|
||||
|
||||
func BuildTestingTGomegaFailHandler(t gomegaTestingT) types.GomegaFailHandler {
|
||||
return func(message string, callerSkip ...int) {
|
||||
skip := 1
|
||||
if len(callerSkip) > 0 {
|
||||
skip = callerSkip[0]
|
||||
func BuildTestingTGomegaFailWrapper(t gomegaTestingT) *types.GomegaFailWrapper {
|
||||
tWithHelper, hasHelper := t.(types.TWithHelper)
|
||||
if !hasHelper {
|
||||
tWithHelper = EmptyTWithHelper{}
|
||||
}
|
||||
|
||||
fail := func(message string, callerSkip ...int) {
|
||||
if hasHelper {
|
||||
tWithHelper.Helper()
|
||||
t.Fatalf("\n%s", message)
|
||||
} else {
|
||||
skip := 2
|
||||
if len(callerSkip) > 0 {
|
||||
skip += callerSkip[0]
|
||||
}
|
||||
stackTrace := pruneStack(string(debug.Stack()), skip)
|
||||
t.Fatalf("\n%s\n%s\n", stackTrace, message)
|
||||
}
|
||||
stackTrace := pruneStack(string(debug.Stack()), skip)
|
||||
t.Errorf("\n%s\n%s", stackTrace, message)
|
||||
}
|
||||
|
||||
return &types.GomegaFailWrapper{
|
||||
Fail: fail,
|
||||
TWithHelper: tWithHelper,
|
||||
}
|
||||
}
|
||||
|
||||
func pruneStack(fullStackTrace string, skip int) string {
|
||||
stack := strings.Split(fullStackTrace, "\n")
|
||||
if len(stack) > 2*(skip+1) {
|
||||
stack = stack[2*(skip+1):]
|
||||
stack := strings.Split(fullStackTrace, "\n")[1:]
|
||||
if len(stack) > 2*skip {
|
||||
stack = stack[2*skip:]
|
||||
}
|
||||
prunedStack := []string{}
|
||||
re := regexp.MustCompile(`\/ginkgo\/|\/pkg\/testing\/|\/pkg\/runtime\/`)
|
||||
for i := 0; i < len(stack)/2; i++ {
|
||||
if !re.Match([]byte(stack[i*2])) {
|
||||
if !StackTracePruneRE.Match([]byte(stack[i*2])) {
|
||||
prunedStack = append(prunedStack, stack[i*2])
|
||||
prunedStack = append(prunedStack, stack[i*2+1])
|
||||
}
|
||||
|
87
vendor/github.com/onsi/gomega/matchers.go
generated
vendored
87
vendor/github.com/onsi/gomega/matchers.go
generated
vendored
@@ -53,7 +53,7 @@ func BeFalse() types.GomegaMatcher {
|
||||
//HaveOccurred succeeds if actual is a non-nil error
|
||||
//The typical Go error checking pattern looks like:
|
||||
// err := SomethingThatMightFail()
|
||||
// Ω(err).ShouldNot(HaveOccurred())
|
||||
// Expect(err).ShouldNot(HaveOccurred())
|
||||
func HaveOccurred() types.GomegaMatcher {
|
||||
return &matchers.HaveOccurredMatcher{}
|
||||
}
|
||||
@@ -61,10 +61,10 @@ func HaveOccurred() types.GomegaMatcher {
|
||||
//Succeed passes if actual is a nil error
|
||||
//Succeed is intended to be used with functions that return a single error value. Instead of
|
||||
// err := SomethingThatMightFail()
|
||||
// Ω(err).ShouldNot(HaveOccurred())
|
||||
// Expect(err).ShouldNot(HaveOccurred())
|
||||
//
|
||||
//You can write:
|
||||
// Ω(SomethingThatMightFail()).Should(Succeed())
|
||||
// Expect(SomethingThatMightFail()).Should(Succeed())
|
||||
//
|
||||
//It is a mistake to use Succeed with a function that has multiple return values. Gomega's Ω and Expect
|
||||
//functions automatically trigger failure if any return values after the first return value are non-zero/non-nil.
|
||||
@@ -76,8 +76,8 @@ func Succeed() types.GomegaMatcher {
|
||||
//MatchError succeeds if actual is a non-nil error that matches the passed in string/error.
|
||||
//
|
||||
//These are valid use-cases:
|
||||
// Ω(err).Should(MatchError("an error")) //asserts that err.Error() == "an error"
|
||||
// Ω(err).Should(MatchError(SomeError)) //asserts that err == SomeError (via reflect.DeepEqual)
|
||||
// Expect(err).Should(MatchError("an error")) //asserts that err.Error() == "an error"
|
||||
// Expect(err).Should(MatchError(SomeError)) //asserts that err == SomeError (via reflect.DeepEqual)
|
||||
//
|
||||
//It is an error for err to be nil or an object that does not implement the Error interface
|
||||
func MatchError(expected interface{}) types.GomegaMatcher {
|
||||
@@ -106,11 +106,11 @@ func BeClosed() types.GomegaMatcher {
|
||||
//
|
||||
//Receive returns immediately and never blocks:
|
||||
//
|
||||
//- If there is nothing on the channel `c` then Ω(c).Should(Receive()) will fail and Ω(c).ShouldNot(Receive()) will pass.
|
||||
//- If there is nothing on the channel `c` then Expect(c).Should(Receive()) will fail and Ω(c).ShouldNot(Receive()) will pass.
|
||||
//
|
||||
//- If the channel `c` is closed then Ω(c).Should(Receive()) will fail and Ω(c).ShouldNot(Receive()) will pass.
|
||||
//- If the channel `c` is closed then Expect(c).Should(Receive()) will fail and Ω(c).ShouldNot(Receive()) will pass.
|
||||
//
|
||||
//- If there is something on the channel `c` ready to be read, then Ω(c).Should(Receive()) will pass and Ω(c).ShouldNot(Receive()) will fail.
|
||||
//- If there is something on the channel `c` ready to be read, then Expect(c).Should(Receive()) will pass and Ω(c).ShouldNot(Receive()) will fail.
|
||||
//
|
||||
//If you have a go-routine running in the background that will write to channel `c` you can:
|
||||
// Eventually(c).Should(Receive())
|
||||
@@ -121,7 +121,7 @@ func BeClosed() types.GomegaMatcher {
|
||||
// Consistently(c).ShouldNot(Receive())
|
||||
//
|
||||
//You can pass `Receive` a matcher. If you do so, it will match the received object against the matcher. For example:
|
||||
// Ω(c).Should(Receive(Equal("foo")))
|
||||
// Expect(c).Should(Receive(Equal("foo")))
|
||||
//
|
||||
//When given a matcher, `Receive` will always fail if there is nothing to be received on the channel.
|
||||
//
|
||||
@@ -134,8 +134,8 @@ func BeClosed() types.GomegaMatcher {
|
||||
//Finally, if you want to have a reference to the value *sent* to the channel you can pass the `Receive` matcher a pointer to a variable of the appropriate type:
|
||||
// var myThing thing
|
||||
// Eventually(thingChan).Should(Receive(&myThing))
|
||||
// Ω(myThing.Sprocket).Should(Equal("foo"))
|
||||
// Ω(myThing.IsValid()).Should(BeTrue())
|
||||
// Expect(myThing.Sprocket).Should(Equal("foo"))
|
||||
// Expect(myThing.IsValid()).Should(BeTrue())
|
||||
func Receive(args ...interface{}) types.GomegaMatcher {
|
||||
var arg interface{}
|
||||
if len(args) > 0 {
|
||||
@@ -153,9 +153,9 @@ func Receive(args ...interface{}) types.GomegaMatcher {
|
||||
//
|
||||
//BeSent never blocks:
|
||||
//
|
||||
//- If the channel `c` is not ready to receive then Ω(c).Should(BeSent("foo")) will fail immediately
|
||||
//- If the channel `c` is not ready to receive then Expect(c).Should(BeSent("foo")) will fail immediately
|
||||
//- If the channel `c` is eventually ready to receive then Eventually(c).Should(BeSent("foo")) will succeed.. presuming the channel becomes ready to receive before Eventually's timeout
|
||||
//- If the channel `c` is closed then Ω(c).Should(BeSent("foo")) and Ω(c).ShouldNot(BeSent("foo")) will both fail immediately
|
||||
//- If the channel `c` is closed then Expect(c).Should(BeSent("foo")) and Ω(c).ShouldNot(BeSent("foo")) will both fail immediately
|
||||
//
|
||||
//Of course, the value is actually sent to the channel. The point of `BeSent` is less to make an assertion about the availability of the channel (which is typically an implementation detail that your test should not be concerned with).
|
||||
//Rather, the point of `BeSent` is to make it possible to easily and expressively write tests that can timeout on blocked channel sends.
|
||||
@@ -176,7 +176,7 @@ func MatchRegexp(regexp string, args ...interface{}) types.GomegaMatcher {
|
||||
}
|
||||
|
||||
//ContainSubstring succeeds if actual is a string or stringer that contains the
|
||||
//passed-in regexp. Optional arguments can be provided to construct the substring
|
||||
//passed-in substring. Optional arguments can be provided to construct the substring
|
||||
//via fmt.Sprintf().
|
||||
func ContainSubstring(substr string, args ...interface{}) types.GomegaMatcher {
|
||||
return &matchers.ContainSubstringMatcher{
|
||||
@@ -214,6 +214,15 @@ func MatchJSON(json interface{}) types.GomegaMatcher {
|
||||
}
|
||||
}
|
||||
|
||||
//MatchXML succeeds if actual is a string or stringer of XML that matches
|
||||
//the expected XML. The XMLs are decoded and the resulting objects are compared via
|
||||
//reflect.DeepEqual so things like whitespaces shouldn't matter.
|
||||
func MatchXML(xml interface{}) types.GomegaMatcher {
|
||||
return &matchers.MatchXMLMatcher{
|
||||
XMLToMatch: xml,
|
||||
}
|
||||
}
|
||||
|
||||
//MatchYAML succeeds if actual is a string or stringer of YAML that matches
|
||||
//the expected YAML. The YAML's are decoded and the resulting objects are compared via
|
||||
//reflect.DeepEqual so things like key-ordering and whitespace shouldn't matter.
|
||||
@@ -250,7 +259,7 @@ func BeZero() types.GomegaMatcher {
|
||||
//ContainElement succeeds if actual contains the passed in element.
|
||||
//By default ContainElement() uses Equal() to perform the match, however a
|
||||
//matcher can be passed in instead:
|
||||
// Ω([]string{"Foo", "FooBar"}).Should(ContainElement(ContainSubstring("Bar")))
|
||||
// Expect([]string{"Foo", "FooBar"}).Should(ContainElement(ContainSubstring("Bar")))
|
||||
//
|
||||
//Actual must be an array, slice or map.
|
||||
//For maps, ContainElement searches through the map's values.
|
||||
@@ -260,19 +269,19 @@ func ContainElement(element interface{}) types.GomegaMatcher {
|
||||
}
|
||||
}
|
||||
|
||||
//ConsistOf succeeds if actual contains preciely the elements passed into the matcher. The ordering of the elements does not matter.
|
||||
//ConsistOf succeeds if actual contains precisely the elements passed into the matcher. The ordering of the elements does not matter.
|
||||
//By default ConsistOf() uses Equal() to match the elements, however custom matchers can be passed in instead. Here are some examples:
|
||||
//
|
||||
// Ω([]string{"Foo", "FooBar"}).Should(ConsistOf("FooBar", "Foo"))
|
||||
// Ω([]string{"Foo", "FooBar"}).Should(ConsistOf(ContainSubstring("Bar"), "Foo"))
|
||||
// Ω([]string{"Foo", "FooBar"}).Should(ConsistOf(ContainSubstring("Foo"), ContainSubstring("Foo")))
|
||||
// Expect([]string{"Foo", "FooBar"}).Should(ConsistOf("FooBar", "Foo"))
|
||||
// Expect([]string{"Foo", "FooBar"}).Should(ConsistOf(ContainSubstring("Bar"), "Foo"))
|
||||
// Expect([]string{"Foo", "FooBar"}).Should(ConsistOf(ContainSubstring("Foo"), ContainSubstring("Foo")))
|
||||
//
|
||||
//Actual must be an array, slice or map. For maps, ConsistOf matches against the map's values.
|
||||
//
|
||||
//You typically pass variadic arguments to ConsistOf (as in the examples above). However, if you need to pass in a slice you can provided that it
|
||||
//is the only element passed in to ConsistOf:
|
||||
//
|
||||
// Ω([]string{"Foo", "FooBar"}).Should(ConsistOf([]string{"FooBar", "Foo"}))
|
||||
// Expect([]string{"Foo", "FooBar"}).Should(ConsistOf([]string{"FooBar", "Foo"}))
|
||||
//
|
||||
//Note that Go's type system does not allow you to write this as ConsistOf([]string{"FooBar", "Foo"}...) as []string and []interface{} are different types - hence the need for this special rule.
|
||||
func ConsistOf(elements ...interface{}) types.GomegaMatcher {
|
||||
@@ -284,7 +293,7 @@ func ConsistOf(elements ...interface{}) types.GomegaMatcher {
|
||||
//HaveKey succeeds if actual is a map with the passed in key.
|
||||
//By default HaveKey uses Equal() to perform the match, however a
|
||||
//matcher can be passed in instead:
|
||||
// Ω(map[string]string{"Foo": "Bar", "BazFoo": "Duck"}).Should(HaveKey(MatchRegexp(`.+Foo$`)))
|
||||
// Expect(map[string]string{"Foo": "Bar", "BazFoo": "Duck"}).Should(HaveKey(MatchRegexp(`.+Foo$`)))
|
||||
func HaveKey(key interface{}) types.GomegaMatcher {
|
||||
return &matchers.HaveKeyMatcher{
|
||||
Key: key,
|
||||
@@ -294,8 +303,8 @@ func HaveKey(key interface{}) types.GomegaMatcher {
|
||||
//HaveKeyWithValue succeeds if actual is a map with the passed in key and value.
|
||||
//By default HaveKeyWithValue uses Equal() to perform the match, however a
|
||||
//matcher can be passed in instead:
|
||||
// Ω(map[string]string{"Foo": "Bar", "BazFoo": "Duck"}).Should(HaveKeyWithValue("Foo", "Bar"))
|
||||
// Ω(map[string]string{"Foo": "Bar", "BazFoo": "Duck"}).Should(HaveKeyWithValue(MatchRegexp(`.+Foo$`), "Bar"))
|
||||
// Expect(map[string]string{"Foo": "Bar", "BazFoo": "Duck"}).Should(HaveKeyWithValue("Foo", "Bar"))
|
||||
// Expect(map[string]string{"Foo": "Bar", "BazFoo": "Duck"}).Should(HaveKeyWithValue(MatchRegexp(`.+Foo$`), "Bar"))
|
||||
func HaveKeyWithValue(key interface{}, value interface{}) types.GomegaMatcher {
|
||||
return &matchers.HaveKeyWithValueMatcher{
|
||||
Key: key,
|
||||
@@ -305,15 +314,15 @@ func HaveKeyWithValue(key interface{}, value interface{}) types.GomegaMatcher {
|
||||
|
||||
//BeNumerically performs numerical assertions in a type-agnostic way.
|
||||
//Actual and expected should be numbers, though the specific type of
|
||||
//number is irrelevant (floa32, float64, uint8, etc...).
|
||||
//number is irrelevant (float32, float64, uint8, etc...).
|
||||
//
|
||||
//There are six, self-explanatory, supported comparators:
|
||||
// Ω(1.0).Should(BeNumerically("==", 1))
|
||||
// Ω(1.0).Should(BeNumerically("~", 0.999, 0.01))
|
||||
// Ω(1.0).Should(BeNumerically(">", 0.9))
|
||||
// Ω(1.0).Should(BeNumerically(">=", 1.0))
|
||||
// Ω(1.0).Should(BeNumerically("<", 3))
|
||||
// Ω(1.0).Should(BeNumerically("<=", 1.0))
|
||||
// Expect(1.0).Should(BeNumerically("==", 1))
|
||||
// Expect(1.0).Should(BeNumerically("~", 0.999, 0.01))
|
||||
// Expect(1.0).Should(BeNumerically(">", 0.9))
|
||||
// Expect(1.0).Should(BeNumerically(">=", 1.0))
|
||||
// Expect(1.0).Should(BeNumerically("<", 3))
|
||||
// Expect(1.0).Should(BeNumerically("<=", 1.0))
|
||||
func BeNumerically(comparator string, compareTo ...interface{}) types.GomegaMatcher {
|
||||
return &matchers.BeNumericallyMatcher{
|
||||
Comparator: comparator,
|
||||
@@ -323,8 +332,8 @@ func BeNumerically(comparator string, compareTo ...interface{}) types.GomegaMatc
|
||||
|
||||
//BeTemporally compares time.Time's like BeNumerically
|
||||
//Actual and expected must be time.Time. The comparators are the same as for BeNumerically
|
||||
// Ω(time.Now()).Should(BeTemporally(">", time.Time{}))
|
||||
// Ω(time.Now()).Should(BeTemporally("~", time.Now(), time.Second))
|
||||
// Expect(time.Now()).Should(BeTemporally(">", time.Time{}))
|
||||
// Expect(time.Now()).Should(BeTemporally("~", time.Now(), time.Second))
|
||||
func BeTemporally(comparator string, compareTo time.Time, threshold ...time.Duration) types.GomegaMatcher {
|
||||
return &matchers.BeTemporallyMatcher{
|
||||
Comparator: comparator,
|
||||
@@ -335,10 +344,10 @@ func BeTemporally(comparator string, compareTo time.Time, threshold ...time.Dura
|
||||
|
||||
//BeAssignableToTypeOf succeeds if actual is assignable to the type of expected.
|
||||
//It will return an error when one of the values is nil.
|
||||
// Ω(0).Should(BeAssignableToTypeOf(0)) // Same values
|
||||
// Ω(5).Should(BeAssignableToTypeOf(-1)) // different values same type
|
||||
// Ω("foo").Should(BeAssignableToTypeOf("bar")) // different values same type
|
||||
// Ω(struct{ Foo string }{}).Should(BeAssignableToTypeOf(struct{ Foo string }{}))
|
||||
// Expect(0).Should(BeAssignableToTypeOf(0)) // Same values
|
||||
// Expect(5).Should(BeAssignableToTypeOf(-1)) // different values same type
|
||||
// Expect("foo").Should(BeAssignableToTypeOf("bar")) // different values same type
|
||||
// Expect(struct{ Foo string }{}).Should(BeAssignableToTypeOf(struct{ Foo string }{}))
|
||||
func BeAssignableToTypeOf(expected interface{}) types.GomegaMatcher {
|
||||
return &matchers.AssignableToTypeOfMatcher{
|
||||
Expected: expected,
|
||||
@@ -357,13 +366,13 @@ func BeAnExistingFile() types.GomegaMatcher {
|
||||
return &matchers.BeAnExistingFileMatcher{}
|
||||
}
|
||||
|
||||
//BeARegularFile succeeds iff a file exists and is a regular file.
|
||||
//BeARegularFile succeeds if a file exists and is a regular file.
|
||||
//Actual must be a string representing the abs path to the file being checked.
|
||||
func BeARegularFile() types.GomegaMatcher {
|
||||
return &matchers.BeARegularFileMatcher{}
|
||||
}
|
||||
|
||||
//BeADirectory succeeds iff a file exists and is a directory.
|
||||
//BeADirectory succeeds if a file exists and is a directory.
|
||||
//Actual must be a string representing the abs path to the file being checked.
|
||||
func BeADirectory() types.GomegaMatcher {
|
||||
return &matchers.BeADirectoryMatcher{}
|
||||
@@ -379,7 +388,7 @@ func And(ms ...types.GomegaMatcher) types.GomegaMatcher {
|
||||
}
|
||||
|
||||
//SatisfyAll is an alias for And().
|
||||
// Ω("hi").Should(SatisfyAll(HaveLen(2), Equal("hi")))
|
||||
// Expect("hi").Should(SatisfyAll(HaveLen(2), Equal("hi")))
|
||||
func SatisfyAll(matchers ...types.GomegaMatcher) types.GomegaMatcher {
|
||||
return And(matchers...)
|
||||
}
|
||||
|
4
vendor/github.com/onsi/gomega/matchers/BUILD
generated
vendored
4
vendor/github.com/onsi/gomega/matchers/BUILD
generated
vendored
@@ -5,6 +5,7 @@ go_library(
|
||||
srcs = [
|
||||
"and.go",
|
||||
"assignable_to_type_of_matcher.go",
|
||||
"attributes_slice.go",
|
||||
"be_a_directory.go",
|
||||
"be_a_regular_file.go",
|
||||
"be_an_existing_file.go",
|
||||
@@ -33,11 +34,13 @@ go_library(
|
||||
"match_error_matcher.go",
|
||||
"match_json_matcher.go",
|
||||
"match_regexp_matcher.go",
|
||||
"match_xml_matcher.go",
|
||||
"match_yaml_matcher.go",
|
||||
"not.go",
|
||||
"or.go",
|
||||
"panic_matcher.go",
|
||||
"receive_matcher.go",
|
||||
"semi_structured_data_support.go",
|
||||
"succeed_matcher.go",
|
||||
"type_support.go",
|
||||
"with_transform.go",
|
||||
@@ -50,6 +53,7 @@ go_library(
|
||||
"//vendor/github.com/onsi/gomega/internal/oraclematcher:go_default_library",
|
||||
"//vendor/github.com/onsi/gomega/matchers/support/goraph/bipartitegraph:go_default_library",
|
||||
"//vendor/github.com/onsi/gomega/types:go_default_library",
|
||||
"//vendor/golang.org/x/net/html/charset:go_default_library",
|
||||
"//vendor/gopkg.in/yaml.v2:go_default_library",
|
||||
],
|
||||
)
|
||||
|
5
vendor/github.com/onsi/gomega/matchers/and.go
generated
vendored
5
vendor/github.com/onsi/gomega/matchers/and.go
generated
vendored
@@ -57,8 +57,7 @@ func (m *AndMatcher) MatchMayChangeInTheFuture(actual interface{}) bool {
|
||||
}
|
||||
}
|
||||
return false // none of were going to change
|
||||
} else {
|
||||
// one of the matchers failed.. it must be able to change in order to affect the result
|
||||
return oraclematcher.MatchMayChangeInTheFuture(m.firstFailedMatcher, actual)
|
||||
}
|
||||
// one of the matchers failed.. it must be able to change in order to affect the result
|
||||
return oraclematcher.MatchMayChangeInTheFuture(m.firstFailedMatcher, actual)
|
||||
}
|
||||
|
6
vendor/github.com/onsi/gomega/matchers/assignable_to_type_of_matcher.go
generated
vendored
6
vendor/github.com/onsi/gomega/matchers/assignable_to_type_of_matcher.go
generated
vendored
@@ -12,8 +12,12 @@ type AssignableToTypeOfMatcher struct {
|
||||
}
|
||||
|
||||
func (matcher *AssignableToTypeOfMatcher) Match(actual interface{}) (success bool, err error) {
|
||||
if actual == nil || matcher.Expected == nil {
|
||||
if actual == nil && matcher.Expected == nil {
|
||||
return false, fmt.Errorf("Refusing to compare <nil> to <nil>.\nBe explicit and use BeNil() instead. This is to avoid mistakes where both sides of an assertion are erroneously uninitialized.")
|
||||
} else if matcher.Expected == nil {
|
||||
return false, fmt.Errorf("Refusing to compare type to <nil>.\nBe explicit and use BeNil() instead. This is to avoid mistakes where both sides of an assertion are erroneously uninitialized.")
|
||||
} else if actual == nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
actualType := reflect.TypeOf(actual)
|
||||
|
14
vendor/github.com/onsi/gomega/matchers/attributes_slice.go
generated
vendored
Normal file
14
vendor/github.com/onsi/gomega/matchers/attributes_slice.go
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
package matchers
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type attributesSlice []xml.Attr
|
||||
|
||||
func (attrs attributesSlice) Len() int { return len(attrs) }
|
||||
func (attrs attributesSlice) Less(i, j int) bool {
|
||||
return strings.Compare(attrs[i].Name.Local, attrs[j].Name.Local) == -1
|
||||
}
|
||||
func (attrs attributesSlice) Swap(i, j int) { attrs[i], attrs[j] = attrs[j], attrs[i] }
|
7
vendor/github.com/onsi/gomega/matchers/be_closed_matcher.go
generated
vendored
7
vendor/github.com/onsi/gomega/matchers/be_closed_matcher.go
generated
vendored
@@ -2,8 +2,9 @@ package matchers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/onsi/gomega/format"
|
||||
"reflect"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
)
|
||||
|
||||
type BeClosedMatcher struct {
|
||||
@@ -22,8 +23,8 @@ func (matcher *BeClosedMatcher) Match(actual interface{}) (success bool, err err
|
||||
}
|
||||
|
||||
winnerIndex, _, open := reflect.Select([]reflect.SelectCase{
|
||||
reflect.SelectCase{Dir: reflect.SelectRecv, Chan: channelValue},
|
||||
reflect.SelectCase{Dir: reflect.SelectDefault},
|
||||
{Dir: reflect.SelectRecv, Chan: channelValue},
|
||||
{Dir: reflect.SelectDefault},
|
||||
})
|
||||
|
||||
var closed bool
|
||||
|
1
vendor/github.com/onsi/gomega/matchers/be_empty_matcher.go
generated
vendored
1
vendor/github.com/onsi/gomega/matchers/be_empty_matcher.go
generated
vendored
@@ -2,6 +2,7 @@ package matchers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
)
|
||||
|
||||
|
3
vendor/github.com/onsi/gomega/matchers/be_equivalent_to_matcher.go
generated
vendored
3
vendor/github.com/onsi/gomega/matchers/be_equivalent_to_matcher.go
generated
vendored
@@ -2,8 +2,9 @@ package matchers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/onsi/gomega/format"
|
||||
"reflect"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
)
|
||||
|
||||
type BeEquivalentToMatcher struct {
|
||||
|
1
vendor/github.com/onsi/gomega/matchers/be_false_matcher.go
generated
vendored
1
vendor/github.com/onsi/gomega/matchers/be_false_matcher.go
generated
vendored
@@ -2,6 +2,7 @@ package matchers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
)
|
||||
|
||||
|
19
vendor/github.com/onsi/gomega/matchers/be_numerically_matcher.go
generated
vendored
19
vendor/github.com/onsi/gomega/matchers/be_numerically_matcher.go
generated
vendored
@@ -2,8 +2,9 @@ package matchers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/onsi/gomega/format"
|
||||
"math"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
)
|
||||
|
||||
type BeNumericallyMatcher struct {
|
||||
@@ -12,11 +13,23 @@ type BeNumericallyMatcher struct {
|
||||
}
|
||||
|
||||
func (matcher *BeNumericallyMatcher) FailureMessage(actual interface{}) (message string) {
|
||||
return format.Message(actual, fmt.Sprintf("to be %s", matcher.Comparator), matcher.CompareTo[0])
|
||||
return matcher.FormatFailureMessage(actual, false)
|
||||
}
|
||||
|
||||
func (matcher *BeNumericallyMatcher) NegatedFailureMessage(actual interface{}) (message string) {
|
||||
return format.Message(actual, fmt.Sprintf("not to be %s", matcher.Comparator), matcher.CompareTo[0])
|
||||
return matcher.FormatFailureMessage(actual, true)
|
||||
}
|
||||
|
||||
func (matcher *BeNumericallyMatcher) FormatFailureMessage(actual interface{}, negated bool) (message string) {
|
||||
if len(matcher.CompareTo) == 1 {
|
||||
message = fmt.Sprintf("to be %s", matcher.Comparator)
|
||||
} else {
|
||||
message = fmt.Sprintf("to be within %v of %s", matcher.CompareTo[1], matcher.Comparator)
|
||||
}
|
||||
if negated {
|
||||
message = "not " + message
|
||||
}
|
||||
return format.Message(actual, message, matcher.CompareTo[0])
|
||||
}
|
||||
|
||||
func (matcher *BeNumericallyMatcher) Match(actual interface{}) (success bool, err error) {
|
||||
|
4
vendor/github.com/onsi/gomega/matchers/be_sent_matcher.go
generated
vendored
4
vendor/github.com/onsi/gomega/matchers/be_sent_matcher.go
generated
vendored
@@ -42,8 +42,8 @@ func (matcher *BeSentMatcher) Match(actual interface{}) (success bool, err error
|
||||
}()
|
||||
|
||||
winnerIndex, _, _ := reflect.Select([]reflect.SelectCase{
|
||||
reflect.SelectCase{Dir: reflect.SelectSend, Chan: channelValue, Send: argValue},
|
||||
reflect.SelectCase{Dir: reflect.SelectDefault},
|
||||
{Dir: reflect.SelectSend, Chan: channelValue, Send: argValue},
|
||||
{Dir: reflect.SelectDefault},
|
||||
})
|
||||
|
||||
var didSend bool
|
||||
|
3
vendor/github.com/onsi/gomega/matchers/be_temporally_matcher.go
generated
vendored
3
vendor/github.com/onsi/gomega/matchers/be_temporally_matcher.go
generated
vendored
@@ -2,8 +2,9 @@ package matchers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/onsi/gomega/format"
|
||||
"time"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
)
|
||||
|
||||
type BeTemporallyMatcher struct {
|
||||
|
1
vendor/github.com/onsi/gomega/matchers/be_true_matcher.go
generated
vendored
1
vendor/github.com/onsi/gomega/matchers/be_true_matcher.go
generated
vendored
@@ -2,6 +2,7 @@ package matchers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
)
|
||||
|
||||
|
3
vendor/github.com/onsi/gomega/matchers/be_zero_matcher.go
generated
vendored
3
vendor/github.com/onsi/gomega/matchers/be_zero_matcher.go
generated
vendored
@@ -1,8 +1,9 @@
|
||||
package matchers
|
||||
|
||||
import (
|
||||
"github.com/onsi/gomega/format"
|
||||
"reflect"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
)
|
||||
|
||||
type BeZeroMatcher struct {
|
||||
|
3
vendor/github.com/onsi/gomega/matchers/contain_substring_matcher.go
generated
vendored
3
vendor/github.com/onsi/gomega/matchers/contain_substring_matcher.go
generated
vendored
@@ -2,8 +2,9 @@ package matchers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/onsi/gomega/format"
|
||||
"strings"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
)
|
||||
|
||||
type ContainSubstringMatcher struct {
|
||||
|
15
vendor/github.com/onsi/gomega/matchers/equal_matcher.go
generated
vendored
15
vendor/github.com/onsi/gomega/matchers/equal_matcher.go
generated
vendored
@@ -1,6 +1,7 @@
|
||||
package matchers
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
@@ -15,10 +16,24 @@ func (matcher *EqualMatcher) Match(actual interface{}) (success bool, err error)
|
||||
if actual == nil && matcher.Expected == nil {
|
||||
return false, fmt.Errorf("Refusing to compare <nil> to <nil>.\nBe explicit and use BeNil() instead. This is to avoid mistakes where both sides of an assertion are erroneously uninitialized.")
|
||||
}
|
||||
// Shortcut for byte slices.
|
||||
// Comparing long byte slices with reflect.DeepEqual is very slow,
|
||||
// so use bytes.Equal if actual and expected are both byte slices.
|
||||
if actualByteSlice, ok := actual.([]byte); ok {
|
||||
if expectedByteSlice, ok := matcher.Expected.([]byte); ok {
|
||||
return bytes.Equal(actualByteSlice, expectedByteSlice), nil
|
||||
}
|
||||
}
|
||||
return reflect.DeepEqual(actual, matcher.Expected), nil
|
||||
}
|
||||
|
||||
func (matcher *EqualMatcher) FailureMessage(actual interface{}) (message string) {
|
||||
actualString, actualOK := actual.(string)
|
||||
expectedString, expectedOK := matcher.Expected.(string)
|
||||
if actualOK && expectedOK {
|
||||
return format.MessageWithDiff(actualString, "to equal", expectedString)
|
||||
}
|
||||
|
||||
return format.Message(actual, "to equal", matcher.Expected)
|
||||
}
|
||||
|
||||
|
3
vendor/github.com/onsi/gomega/matchers/have_key_matcher.go
generated
vendored
3
vendor/github.com/onsi/gomega/matchers/have_key_matcher.go
generated
vendored
@@ -2,8 +2,9 @@ package matchers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/onsi/gomega/format"
|
||||
"reflect"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
)
|
||||
|
||||
type HaveKeyMatcher struct {
|
||||
|
3
vendor/github.com/onsi/gomega/matchers/have_key_with_value_matcher.go
generated
vendored
3
vendor/github.com/onsi/gomega/matchers/have_key_with_value_matcher.go
generated
vendored
@@ -2,8 +2,9 @@ package matchers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/onsi/gomega/format"
|
||||
"reflect"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
)
|
||||
|
||||
type HaveKeyWithValueMatcher struct {
|
||||
|
1
vendor/github.com/onsi/gomega/matchers/have_len_matcher.go
generated
vendored
1
vendor/github.com/onsi/gomega/matchers/have_len_matcher.go
generated
vendored
@@ -2,6 +2,7 @@ package matchers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
)
|
||||
|
||||
|
2
vendor/github.com/onsi/gomega/matchers/have_occurred_matcher.go
generated
vendored
2
vendor/github.com/onsi/gomega/matchers/have_occurred_matcher.go
generated
vendored
@@ -29,5 +29,5 @@ func (matcher *HaveOccurredMatcher) FailureMessage(actual interface{}) (message
|
||||
}
|
||||
|
||||
func (matcher *HaveOccurredMatcher) NegatedFailureMessage(actual interface{}) (message string) {
|
||||
return fmt.Sprintf("Expected error:\n%s\n%s\n%s", format.Object(actual, 1), format.IndentString(actual.(error).Error(), 1), "not to have occurred")
|
||||
return fmt.Sprintf("Unexpected error:\n%s\n%s\n%s", format.Object(actual, 1), format.IndentString(actual.(error).Error(), 1), "occurred")
|
||||
}
|
||||
|
1
vendor/github.com/onsi/gomega/matchers/have_prefix_matcher.go
generated
vendored
1
vendor/github.com/onsi/gomega/matchers/have_prefix_matcher.go
generated
vendored
@@ -2,6 +2,7 @@ package matchers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
)
|
||||
|
||||
|
1
vendor/github.com/onsi/gomega/matchers/have_suffix_matcher.go
generated
vendored
1
vendor/github.com/onsi/gomega/matchers/have_suffix_matcher.go
generated
vendored
@@ -2,6 +2,7 @@ package matchers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
)
|
||||
|
||||
|
11
vendor/github.com/onsi/gomega/matchers/match_error_matcher.go
generated
vendored
11
vendor/github.com/onsi/gomega/matchers/match_error_matcher.go
generated
vendored
@@ -2,8 +2,9 @@ package matchers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/onsi/gomega/format"
|
||||
"reflect"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
)
|
||||
|
||||
type MatchErrorMatcher struct {
|
||||
@@ -21,14 +22,14 @@ func (matcher *MatchErrorMatcher) Match(actual interface{}) (success bool, err e
|
||||
|
||||
actualErr := actual.(error)
|
||||
|
||||
if isString(matcher.Expected) {
|
||||
return reflect.DeepEqual(actualErr.Error(), matcher.Expected), nil
|
||||
}
|
||||
|
||||
if isError(matcher.Expected) {
|
||||
return reflect.DeepEqual(actualErr, matcher.Expected), nil
|
||||
}
|
||||
|
||||
if isString(matcher.Expected) {
|
||||
return actualErr.Error() == matcher.Expected, nil
|
||||
}
|
||||
|
||||
var subMatcher omegaMatcher
|
||||
var hasSubMatcher bool
|
||||
if matcher.Expected != nil {
|
||||
|
13
vendor/github.com/onsi/gomega/matchers/match_json_matcher.go
generated
vendored
13
vendor/github.com/onsi/gomega/matchers/match_json_matcher.go
generated
vendored
@@ -4,13 +4,13 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
)
|
||||
|
||||
type MatchJSONMatcher struct {
|
||||
JSONToMatch interface{}
|
||||
JSONToMatch interface{}
|
||||
firstFailurePath []interface{}
|
||||
}
|
||||
|
||||
func (matcher *MatchJSONMatcher) Match(actual interface{}) (success bool, err error) {
|
||||
@@ -25,18 +25,19 @@ func (matcher *MatchJSONMatcher) Match(actual interface{}) (success bool, err er
|
||||
// this is guarded by prettyPrint
|
||||
json.Unmarshal([]byte(actualString), &aval)
|
||||
json.Unmarshal([]byte(expectedString), &eval)
|
||||
|
||||
return reflect.DeepEqual(aval, eval), nil
|
||||
var equal bool
|
||||
equal, matcher.firstFailurePath = deepEqual(aval, eval)
|
||||
return equal, nil
|
||||
}
|
||||
|
||||
func (matcher *MatchJSONMatcher) FailureMessage(actual interface{}) (message string) {
|
||||
actualString, expectedString, _ := matcher.prettyPrint(actual)
|
||||
return format.Message(actualString, "to match JSON of", expectedString)
|
||||
return formattedMessage(format.Message(actualString, "to match JSON of", expectedString), matcher.firstFailurePath)
|
||||
}
|
||||
|
||||
func (matcher *MatchJSONMatcher) NegatedFailureMessage(actual interface{}) (message string) {
|
||||
actualString, expectedString, _ := matcher.prettyPrint(actual)
|
||||
return format.Message(actualString, "not to match JSON of", expectedString)
|
||||
return formattedMessage(format.Message(actualString, "not to match JSON of", expectedString), matcher.firstFailurePath)
|
||||
}
|
||||
|
||||
func (matcher *MatchJSONMatcher) prettyPrint(actual interface{}) (actualFormatted, expectedFormatted string, err error) {
|
||||
|
3
vendor/github.com/onsi/gomega/matchers/match_regexp_matcher.go
generated
vendored
3
vendor/github.com/onsi/gomega/matchers/match_regexp_matcher.go
generated
vendored
@@ -2,8 +2,9 @@ package matchers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/onsi/gomega/format"
|
||||
"regexp"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
)
|
||||
|
||||
type MatchRegexpMatcher struct {
|
||||
|
134
vendor/github.com/onsi/gomega/matchers/match_xml_matcher.go
generated
vendored
Normal file
134
vendor/github.com/onsi/gomega/matchers/match_xml_matcher.go
generated
vendored
Normal file
@@ -0,0 +1,134 @@
|
||||
package matchers
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
"golang.org/x/net/html/charset"
|
||||
)
|
||||
|
||||
type MatchXMLMatcher struct {
|
||||
XMLToMatch interface{}
|
||||
}
|
||||
|
||||
func (matcher *MatchXMLMatcher) Match(actual interface{}) (success bool, err error) {
|
||||
actualString, expectedString, err := matcher.formattedPrint(actual)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
aval, err := parseXmlContent(actualString)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("Actual '%s' should be valid XML, but it is not.\nUnderlying error:%s", actualString, err)
|
||||
}
|
||||
|
||||
eval, err := parseXmlContent(expectedString)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("Expected '%s' should be valid XML, but it is not.\nUnderlying error:%s", expectedString, err)
|
||||
}
|
||||
|
||||
return reflect.DeepEqual(aval, eval), nil
|
||||
}
|
||||
|
||||
func (matcher *MatchXMLMatcher) FailureMessage(actual interface{}) (message string) {
|
||||
actualString, expectedString, _ := matcher.formattedPrint(actual)
|
||||
return fmt.Sprintf("Expected\n%s\nto match XML of\n%s", actualString, expectedString)
|
||||
}
|
||||
|
||||
func (matcher *MatchXMLMatcher) NegatedFailureMessage(actual interface{}) (message string) {
|
||||
actualString, expectedString, _ := matcher.formattedPrint(actual)
|
||||
return fmt.Sprintf("Expected\n%s\nnot to match XML of\n%s", actualString, expectedString)
|
||||
}
|
||||
|
||||
func (matcher *MatchXMLMatcher) formattedPrint(actual interface{}) (actualString, expectedString string, err error) {
|
||||
var ok bool
|
||||
actualString, ok = toString(actual)
|
||||
if !ok {
|
||||
return "", "", fmt.Errorf("MatchXMLMatcher matcher requires a string, stringer, or []byte. Got actual:\n%s", format.Object(actual, 1))
|
||||
}
|
||||
expectedString, ok = toString(matcher.XMLToMatch)
|
||||
if !ok {
|
||||
return "", "", fmt.Errorf("MatchXMLMatcher matcher requires a string, stringer, or []byte. Got expected:\n%s", format.Object(matcher.XMLToMatch, 1))
|
||||
}
|
||||
return actualString, expectedString, nil
|
||||
}
|
||||
|
||||
func parseXmlContent(content string) (*xmlNode, error) {
|
||||
allNodes := []*xmlNode{}
|
||||
|
||||
dec := newXmlDecoder(strings.NewReader(content))
|
||||
for {
|
||||
tok, err := dec.Token()
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
return nil, fmt.Errorf("failed to decode next token: %v", err) // untested section
|
||||
}
|
||||
|
||||
lastNodeIndex := len(allNodes) - 1
|
||||
var lastNode *xmlNode
|
||||
if len(allNodes) > 0 {
|
||||
lastNode = allNodes[lastNodeIndex]
|
||||
} else {
|
||||
lastNode = &xmlNode{}
|
||||
}
|
||||
|
||||
switch tok := tok.(type) {
|
||||
case xml.StartElement:
|
||||
attrs := attributesSlice(tok.Attr)
|
||||
sort.Sort(attrs)
|
||||
allNodes = append(allNodes, &xmlNode{XMLName: tok.Name, XMLAttr: tok.Attr})
|
||||
case xml.EndElement:
|
||||
if len(allNodes) > 1 {
|
||||
allNodes[lastNodeIndex-1].Nodes = append(allNodes[lastNodeIndex-1].Nodes, lastNode)
|
||||
allNodes = allNodes[:lastNodeIndex]
|
||||
}
|
||||
case xml.CharData:
|
||||
lastNode.Content = append(lastNode.Content, tok.Copy()...)
|
||||
case xml.Comment:
|
||||
lastNode.Comments = append(lastNode.Comments, tok.Copy()) // untested section
|
||||
case xml.ProcInst:
|
||||
lastNode.ProcInsts = append(lastNode.ProcInsts, tok.Copy())
|
||||
}
|
||||
}
|
||||
|
||||
if len(allNodes) == 0 {
|
||||
return nil, errors.New("found no nodes")
|
||||
}
|
||||
firstNode := allNodes[0]
|
||||
trimParentNodesContentSpaces(firstNode)
|
||||
|
||||
return firstNode, nil
|
||||
}
|
||||
|
||||
func newXmlDecoder(reader io.Reader) *xml.Decoder {
|
||||
dec := xml.NewDecoder(reader)
|
||||
dec.CharsetReader = charset.NewReaderLabel
|
||||
return dec
|
||||
}
|
||||
|
||||
func trimParentNodesContentSpaces(node *xmlNode) {
|
||||
if len(node.Nodes) > 0 {
|
||||
node.Content = bytes.TrimSpace(node.Content)
|
||||
for _, childNode := range node.Nodes {
|
||||
trimParentNodesContentSpaces(childNode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type xmlNode struct {
|
||||
XMLName xml.Name
|
||||
Comments []xml.Comment
|
||||
ProcInsts []xml.ProcInst
|
||||
XMLAttr []xml.Attr
|
||||
Content []byte
|
||||
Nodes []*xmlNode
|
||||
}
|
16
vendor/github.com/onsi/gomega/matchers/match_yaml_matcher.go
generated
vendored
16
vendor/github.com/onsi/gomega/matchers/match_yaml_matcher.go
generated
vendored
@@ -2,7 +2,6 @@ package matchers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
@@ -10,7 +9,8 @@ import (
|
||||
)
|
||||
|
||||
type MatchYAMLMatcher struct {
|
||||
YAMLToMatch interface{}
|
||||
YAMLToMatch interface{}
|
||||
firstFailurePath []interface{}
|
||||
}
|
||||
|
||||
func (matcher *MatchYAMLMatcher) Match(actual interface{}) (success bool, err error) {
|
||||
@@ -29,17 +29,19 @@ func (matcher *MatchYAMLMatcher) Match(actual interface{}) (success bool, err er
|
||||
return false, fmt.Errorf("Expected '%s' should be valid YAML, but it is not.\nUnderlying error:%s", expectedString, err)
|
||||
}
|
||||
|
||||
return reflect.DeepEqual(aval, eval), nil
|
||||
var equal bool
|
||||
equal, matcher.firstFailurePath = deepEqual(aval, eval)
|
||||
return equal, nil
|
||||
}
|
||||
|
||||
func (matcher *MatchYAMLMatcher) FailureMessage(actual interface{}) (message string) {
|
||||
actualString, expectedString, _ := matcher.toNormalisedStrings(actual)
|
||||
return format.Message(actualString, "to match YAML of", expectedString)
|
||||
return formattedMessage(format.Message(actualString, "to match YAML of", expectedString), matcher.firstFailurePath)
|
||||
}
|
||||
|
||||
func (matcher *MatchYAMLMatcher) NegatedFailureMessage(actual interface{}) (message string) {
|
||||
actualString, expectedString, _ := matcher.toNormalisedStrings(actual)
|
||||
return format.Message(actualString, "not to match YAML of", expectedString)
|
||||
return formattedMessage(format.Message(actualString, "not to match YAML of", expectedString), matcher.firstFailurePath)
|
||||
}
|
||||
|
||||
func (matcher *MatchYAMLMatcher) toNormalisedStrings(actual interface{}) (actualFormatted, expectedFormatted string, err error) {
|
||||
@@ -51,11 +53,11 @@ func normalise(input string) string {
|
||||
var val interface{}
|
||||
err := yaml.Unmarshal([]byte(input), &val)
|
||||
if err != nil {
|
||||
panic(err) // guarded by Match
|
||||
panic(err) // unreachable since Match already calls Unmarshal
|
||||
}
|
||||
output, err := yaml.Marshal(val)
|
||||
if err != nil {
|
||||
panic(err) // guarded by Unmarshal
|
||||
panic(err) // untested section, unreachable since we Unmarshal above
|
||||
}
|
||||
return strings.TrimSpace(string(output))
|
||||
}
|
||||
|
10
vendor/github.com/onsi/gomega/matchers/panic_matcher.go
generated
vendored
10
vendor/github.com/onsi/gomega/matchers/panic_matcher.go
generated
vendored
@@ -2,11 +2,14 @@ package matchers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/onsi/gomega/format"
|
||||
"reflect"
|
||||
|
||||
"github.com/onsi/gomega/format"
|
||||
)
|
||||
|
||||
type PanicMatcher struct{}
|
||||
type PanicMatcher struct {
|
||||
object interface{}
|
||||
}
|
||||
|
||||
func (matcher *PanicMatcher) Match(actual interface{}) (success bool, err error) {
|
||||
if actual == nil {
|
||||
@@ -24,6 +27,7 @@ func (matcher *PanicMatcher) Match(actual interface{}) (success bool, err error)
|
||||
success = false
|
||||
defer func() {
|
||||
if e := recover(); e != nil {
|
||||
matcher.object = e
|
||||
success = true
|
||||
}
|
||||
}()
|
||||
@@ -38,5 +42,5 @@ func (matcher *PanicMatcher) FailureMessage(actual interface{}) (message string)
|
||||
}
|
||||
|
||||
func (matcher *PanicMatcher) NegatedFailureMessage(actual interface{}) (message string) {
|
||||
return format.Message(actual, "not to panic")
|
||||
return format.Message(actual, fmt.Sprintf("not to panic, but panicked with\n%s", format.Object(matcher.object, 1)))
|
||||
}
|
||||
|
34
vendor/github.com/onsi/gomega/matchers/receive_matcher.go
generated
vendored
34
vendor/github.com/onsi/gomega/matchers/receive_matcher.go
generated
vendored
@@ -35,17 +35,12 @@ func (matcher *ReceiveMatcher) Match(actual interface{}) (success bool, err erro
|
||||
if argType.Kind() != reflect.Ptr {
|
||||
return false, fmt.Errorf("Cannot assign a value from the channel:\n%s\nTo:\n%s\nYou need to pass a pointer!", format.Object(actual, 1), format.Object(matcher.Arg, 1))
|
||||
}
|
||||
|
||||
assignable := channelType.Elem().AssignableTo(argType.Elem())
|
||||
if !assignable {
|
||||
return false, fmt.Errorf("Cannot assign a value from the channel:\n%s\nTo:\n%s", format.Object(actual, 1), format.Object(matcher.Arg, 1))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
winnerIndex, value, open := reflect.Select([]reflect.SelectCase{
|
||||
reflect.SelectCase{Dir: reflect.SelectRecv, Chan: channelValue},
|
||||
reflect.SelectCase{Dir: reflect.SelectDefault},
|
||||
{Dir: reflect.SelectRecv, Chan: channelValue},
|
||||
{Dir: reflect.SelectDefault},
|
||||
})
|
||||
|
||||
var closed bool
|
||||
@@ -64,21 +59,30 @@ func (matcher *ReceiveMatcher) Match(actual interface{}) (success bool, err erro
|
||||
if didReceive {
|
||||
matcher.receivedValue = value
|
||||
return subMatcher.Match(matcher.receivedValue.Interface())
|
||||
} else {
|
||||
return false, nil
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if didReceive {
|
||||
if matcher.Arg != nil {
|
||||
outValue := reflect.ValueOf(matcher.Arg)
|
||||
reflect.Indirect(outValue).Set(value)
|
||||
|
||||
if value.Type().AssignableTo(outValue.Elem().Type()) {
|
||||
outValue.Elem().Set(value)
|
||||
return true, nil
|
||||
}
|
||||
if value.Type().Kind() == reflect.Interface && value.Elem().Type().AssignableTo(outValue.Elem().Type()) {
|
||||
outValue.Elem().Set(value.Elem())
|
||||
return true, nil
|
||||
} else {
|
||||
return false, fmt.Errorf("Cannot assign a value from the channel:\n%s\nType:\n%s\nTo:\n%s", format.Object(actual, 1), format.Object(value.Interface(), 1), format.Object(matcher.Arg, 1))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true, nil
|
||||
} else {
|
||||
return false, nil
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (matcher *ReceiveMatcher) FailureMessage(actual interface{}) (message string) {
|
||||
@@ -94,9 +98,8 @@ func (matcher *ReceiveMatcher) FailureMessage(actual interface{}) (message strin
|
||||
return subMatcher.FailureMessage(matcher.receivedValue.Interface())
|
||||
}
|
||||
return "When passed a matcher, ReceiveMatcher's channel *must* receive something."
|
||||
} else {
|
||||
return format.Message(actual, "to receive something."+closedAddendum)
|
||||
}
|
||||
return format.Message(actual, "to receive something."+closedAddendum)
|
||||
}
|
||||
|
||||
func (matcher *ReceiveMatcher) NegatedFailureMessage(actual interface{}) (message string) {
|
||||
@@ -112,9 +115,8 @@ func (matcher *ReceiveMatcher) NegatedFailureMessage(actual interface{}) (messag
|
||||
return subMatcher.NegatedFailureMessage(matcher.receivedValue.Interface())
|
||||
}
|
||||
return "When passed a matcher, ReceiveMatcher's channel *must* receive something."
|
||||
} else {
|
||||
return format.Message(actual, "not to receive anything."+closedAddendum)
|
||||
}
|
||||
return format.Message(actual, "not to receive anything."+closedAddendum)
|
||||
}
|
||||
|
||||
func (matcher *ReceiveMatcher) MatchMayChangeInTheFuture(actual interface{}) bool {
|
||||
|
92
vendor/github.com/onsi/gomega/matchers/semi_structured_data_support.go
generated
vendored
Normal file
92
vendor/github.com/onsi/gomega/matchers/semi_structured_data_support.go
generated
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
package matchers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func formattedMessage(comparisonMessage string, failurePath []interface{}) string {
|
||||
var diffMessage string
|
||||
if len(failurePath) == 0 {
|
||||
diffMessage = ""
|
||||
} else {
|
||||
diffMessage = fmt.Sprintf("\n\nfirst mismatched key: %s", formattedFailurePath(failurePath))
|
||||
}
|
||||
return fmt.Sprintf("%s%s", comparisonMessage, diffMessage)
|
||||
}
|
||||
|
||||
func formattedFailurePath(failurePath []interface{}) string {
|
||||
formattedPaths := []string{}
|
||||
for i := len(failurePath) - 1; i >= 0; i-- {
|
||||
switch p := failurePath[i].(type) {
|
||||
case int:
|
||||
formattedPaths = append(formattedPaths, fmt.Sprintf(`[%d]`, p))
|
||||
default:
|
||||
if i != len(failurePath)-1 {
|
||||
formattedPaths = append(formattedPaths, ".")
|
||||
}
|
||||
formattedPaths = append(formattedPaths, fmt.Sprintf(`"%s"`, p))
|
||||
}
|
||||
}
|
||||
return strings.Join(formattedPaths, "")
|
||||
}
|
||||
|
||||
func deepEqual(a interface{}, b interface{}) (bool, []interface{}) {
|
||||
var errorPath []interface{}
|
||||
if reflect.TypeOf(a) != reflect.TypeOf(b) {
|
||||
return false, errorPath
|
||||
}
|
||||
|
||||
switch a.(type) {
|
||||
case []interface{}:
|
||||
if len(a.([]interface{})) != len(b.([]interface{})) {
|
||||
return false, errorPath
|
||||
}
|
||||
|
||||
for i, v := range a.([]interface{}) {
|
||||
elementEqual, keyPath := deepEqual(v, b.([]interface{})[i])
|
||||
if !elementEqual {
|
||||
return false, append(keyPath, i)
|
||||
}
|
||||
}
|
||||
return true, errorPath
|
||||
|
||||
case map[interface{}]interface{}:
|
||||
if len(a.(map[interface{}]interface{})) != len(b.(map[interface{}]interface{})) {
|
||||
return false, errorPath
|
||||
}
|
||||
|
||||
for k, v1 := range a.(map[interface{}]interface{}) {
|
||||
v2, ok := b.(map[interface{}]interface{})[k]
|
||||
if !ok {
|
||||
return false, errorPath
|
||||
}
|
||||
elementEqual, keyPath := deepEqual(v1, v2)
|
||||
if !elementEqual {
|
||||
return false, append(keyPath, k)
|
||||
}
|
||||
}
|
||||
return true, errorPath
|
||||
|
||||
case map[string]interface{}:
|
||||
if len(a.(map[string]interface{})) != len(b.(map[string]interface{})) {
|
||||
return false, errorPath
|
||||
}
|
||||
|
||||
for k, v1 := range a.(map[string]interface{}) {
|
||||
v2, ok := b.(map[string]interface{})[k]
|
||||
if !ok {
|
||||
return false, errorPath
|
||||
}
|
||||
elementEqual, keyPath := deepEqual(v1, v2)
|
||||
if !elementEqual {
|
||||
return false, append(keyPath, k)
|
||||
}
|
||||
}
|
||||
return true, errorPath
|
||||
|
||||
default:
|
||||
return a == b, errorPath
|
||||
}
|
||||
}
|
10
vendor/github.com/onsi/gomega/matchers/support/goraph/bipartitegraph/bipartitegraph.go
generated
vendored
10
vendor/github.com/onsi/gomega/matchers/support/goraph/bipartitegraph/bipartitegraph.go
generated
vendored
@@ -14,13 +14,13 @@ type BipartiteGraph struct {
|
||||
|
||||
func NewBipartiteGraph(leftValues, rightValues []interface{}, neighbours func(interface{}, interface{}) (bool, error)) (*BipartiteGraph, error) {
|
||||
left := NodeOrderedSet{}
|
||||
for i, _ := range leftValues {
|
||||
left = append(left, Node{i})
|
||||
for i := range leftValues {
|
||||
left = append(left, Node{Id: i})
|
||||
}
|
||||
|
||||
right := NodeOrderedSet{}
|
||||
for j, _ := range rightValues {
|
||||
right = append(right, Node{j + len(left)})
|
||||
for j := range rightValues {
|
||||
right = append(right, Node{Id: j + len(left)})
|
||||
}
|
||||
|
||||
edges := EdgeSet{}
|
||||
@@ -32,7 +32,7 @@ func NewBipartiteGraph(leftValues, rightValues []interface{}, neighbours func(in
|
||||
}
|
||||
|
||||
if neighbours {
|
||||
edges = append(edges, Edge{left[i], right[j]})
|
||||
edges = append(edges, Edge{Node1: left[i], Node2: right[j]})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -101,9 +101,8 @@ func (bg *BipartiteGraph) createSLAPGuideLayers(matching EdgeSet) (guideLayers [
|
||||
|
||||
if len(currentLayer) == 0 {
|
||||
return []NodeOrderedSet{}
|
||||
} else {
|
||||
guideLayers = append(guideLayers, currentLayer)
|
||||
}
|
||||
guideLayers = append(guideLayers, currentLayer)
|
||||
|
||||
done := false
|
||||
|
||||
@@ -152,9 +151,8 @@ func (bg *BipartiteGraph) createSLAPGuideLayers(matching EdgeSet) (guideLayers [
|
||||
|
||||
if len(currentLayer) == 0 {
|
||||
return []NodeOrderedSet{}
|
||||
} else {
|
||||
guideLayers = append(guideLayers, currentLayer)
|
||||
}
|
||||
guideLayers = append(guideLayers, currentLayer)
|
||||
}
|
||||
|
||||
return
|
||||
|
15
vendor/github.com/onsi/gomega/matchers/type_support.go
generated
vendored
15
vendor/github.com/onsi/gomega/matchers/type_support.go
generated
vendored
@@ -9,6 +9,7 @@ http://onsi.github.io/gomega/
|
||||
package matchers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
@@ -53,9 +54,8 @@ func toInteger(a interface{}) int64 {
|
||||
return int64(reflect.ValueOf(a).Uint())
|
||||
} else if isFloat(a) {
|
||||
return int64(reflect.ValueOf(a).Float())
|
||||
} else {
|
||||
panic(fmt.Sprintf("Expected a number! Got <%T> %#v", a, a))
|
||||
}
|
||||
panic(fmt.Sprintf("Expected a number! Got <%T> %#v", a, a))
|
||||
}
|
||||
|
||||
func toUnsignedInteger(a interface{}) uint64 {
|
||||
@@ -65,9 +65,8 @@ func toUnsignedInteger(a interface{}) uint64 {
|
||||
return reflect.ValueOf(a).Uint()
|
||||
} else if isFloat(a) {
|
||||
return uint64(reflect.ValueOf(a).Float())
|
||||
} else {
|
||||
panic(fmt.Sprintf("Expected a number! Got <%T> %#v", a, a))
|
||||
}
|
||||
panic(fmt.Sprintf("Expected a number! Got <%T> %#v", a, a))
|
||||
}
|
||||
|
||||
func toFloat(a interface{}) float64 {
|
||||
@@ -77,9 +76,8 @@ func toFloat(a interface{}) float64 {
|
||||
return float64(reflect.ValueOf(a).Uint())
|
||||
} else if isFloat(a) {
|
||||
return reflect.ValueOf(a).Float()
|
||||
} else {
|
||||
panic(fmt.Sprintf("Expected a number! Got <%T> %#v", a, a))
|
||||
}
|
||||
panic(fmt.Sprintf("Expected a number! Got <%T> %#v", a, a))
|
||||
}
|
||||
|
||||
func isError(a interface{}) bool {
|
||||
@@ -136,6 +134,11 @@ func toString(a interface{}) (string, bool) {
|
||||
return aStringer.String(), true
|
||||
}
|
||||
|
||||
aJSONRawMessage, isJSONRawMessage := a.(json.RawMessage)
|
||||
if isJSONRawMessage {
|
||||
return string(aJSONRawMessage), true
|
||||
}
|
||||
|
||||
return "", false
|
||||
}
|
||||
|
||||
|
13
vendor/github.com/onsi/gomega/types/types.go
generated
vendored
13
vendor/github.com/onsi/gomega/types/types.go
generated
vendored
@@ -1,15 +1,24 @@
|
||||
package types
|
||||
|
||||
type TWithHelper interface {
|
||||
Helper()
|
||||
}
|
||||
|
||||
type GomegaFailHandler func(message string, callerSkip ...int)
|
||||
|
||||
type GomegaFailWrapper struct {
|
||||
Fail GomegaFailHandler
|
||||
TWithHelper TWithHelper
|
||||
}
|
||||
|
||||
//A simple *testing.T interface wrapper
|
||||
type GomegaTestingT interface {
|
||||
Errorf(format string, args ...interface{})
|
||||
Fatalf(format string, args ...interface{})
|
||||
}
|
||||
|
||||
//All Gomega matchers must implement the GomegaMatcher interface
|
||||
//
|
||||
//For details on writing custom matchers, check out: http://onsi.github.io/gomega/#adding_your_own_matchers
|
||||
//For details on writing custom matchers, check out: http://onsi.github.io/gomega/#adding-your-own-matchers
|
||||
type GomegaMatcher interface {
|
||||
Match(actual interface{}) (success bool, err error)
|
||||
FailureMessage(actual interface{}) (message string)
|
||||
|
Reference in New Issue
Block a user