├── .gitignore ├── Gopkg.lock ├── Gopkg.toml ├── LICENSE ├── README.md ├── circle.yml ├── http.go ├── http_test.go └── vendor └── github.com ├── gopherjs └── gopherjs │ ├── LICENSE │ └── js │ └── js.go ├── jtolds └── gls │ ├── LICENSE │ ├── README.md │ ├── context.go │ ├── gen_sym.go │ ├── gid.go │ ├── id_pool.go │ ├── stack_tags.go │ ├── stack_tags_js.go │ └── stack_tags_main.go └── smartystreets ├── assertions ├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── collections.go ├── doc.go ├── equal_method.go ├── equality.go ├── filter.go ├── internal │ ├── go-render │ │ ├── LICENSE │ │ └── render │ │ │ └── render.go │ └── oglematchers │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── README.md │ │ ├── any_of.go │ │ ├── contains.go │ │ ├── deep_equals.go │ │ ├── equals.go │ │ ├── greater_or_equal.go │ │ ├── greater_than.go │ │ ├── less_or_equal.go │ │ ├── less_than.go │ │ ├── matcher.go │ │ ├── not.go │ │ └── transform_description.go ├── messages.go ├── panic.go ├── quantity.go ├── serializer.go ├── strings.go ├── time.go └── type.go └── goconvey ├── LICENSE.md ├── convey ├── assertions.go ├── context.go ├── convey.goconvey ├── discovery.go ├── doc.go ├── gotest │ └── utils.go ├── init.go ├── nilReporter.go └── reporting │ ├── console.go │ ├── doc.go │ ├── dot.go │ ├── gotest.go │ ├── init.go │ ├── json.go │ ├── printer.go │ ├── problems.go │ ├── reporter.go │ ├── reporting.goconvey │ ├── reports.go │ ├── statistics.go │ └── story.go └── web └── client └── resources └── fonts └── Open_Sans └── LICENSE.txt /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.dll 4 | *.so 5 | *.dylib 6 | 7 | # Test binary, build with `go test -c` 8 | *.test 9 | 10 | # Output of the go coverage tool, specifically when used with LiteIDE 11 | *.out 12 | 13 | # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 14 | .glide/ 15 | -------------------------------------------------------------------------------- /Gopkg.lock: -------------------------------------------------------------------------------- 1 | # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. 2 | 3 | 4 | [[projects]] 5 | branch = "master" 6 | name = "github.com/gopherjs/gopherjs" 7 | packages = ["js"] 8 | revision = "296de816d4fe28b61803072c3f89360e9d1823ff" 9 | 10 | [[projects]] 11 | name = "github.com/jtolds/gls" 12 | packages = ["."] 13 | revision = "77f18212c9c7edc9bd6a33d383a7b545ce62f064" 14 | version = "v4.2.1" 15 | 16 | [[projects]] 17 | name = "github.com/smartystreets/assertions" 18 | packages = [ 19 | ".", 20 | "internal/go-render/render", 21 | "internal/oglematchers" 22 | ] 23 | revision = "0b37b35ec7434b77e77a4bb29b79677cced992ea" 24 | version = "1.8.1" 25 | 26 | [[projects]] 27 | name = "github.com/smartystreets/goconvey" 28 | packages = [ 29 | "convey", 30 | "convey/gotest", 31 | "convey/reporting" 32 | ] 33 | revision = "9e8dc3f972df6c8fcc0375ef492c24d0bb204857" 34 | version = "1.6.3" 35 | 36 | [solve-meta] 37 | analyzer-name = "dep" 38 | analyzer-version = 1 39 | inputs-digest = "2cf2ce61d60ae89d8ae017320a79a291fc935233fbd9ba1953f989fb3ff89a8d" 40 | solver-name = "gps-cdcl" 41 | solver-version = 1 42 | -------------------------------------------------------------------------------- /Gopkg.toml: -------------------------------------------------------------------------------- 1 | # Gopkg.toml example 2 | # 3 | # Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md 4 | # for detailed Gopkg.toml documentation. 5 | # 6 | # required = ["github.com/user/thing/cmd/thing"] 7 | # ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] 8 | # 9 | # [[constraint]] 10 | # name = "github.com/user/project" 11 | # version = "1.0.0" 12 | # 13 | # [[constraint]] 14 | # name = "github.com/user/project2" 15 | # branch = "dev" 16 | # source = "github.com/myfork/project2" 17 | # 18 | # [[override]] 19 | # name = "github.com/x/y" 20 | # version = "2.4.0" 21 | # 22 | # [prune] 23 | # non-go = false 24 | # go-tests = true 25 | # unused-packages = true 26 | 27 | 28 | [prune] 29 | go-tests = true 30 | unused-packages = true 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 whao.mobile 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # httputils 2 | 一个实现了http连接池的http客户端 3 | -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | test: 2 | pre: 3 | - go get github.com/mattn/goveralls 4 | - go get github.com/smartystreets/goconvey/convey 5 | override: 6 | - go test -v -cover -race -coverprofile=/home/ubuntu/coverage.out 7 | post: 8 | - /home/ubuntu/.go_workspace/bin/goveralls -coverprofile=/home/ubuntu/coverage.out -service=circle-ci -repotoken=RzQjF56PMFDX7kEAVq5Oh89Om8jp7Nvoc -------------------------------------------------------------------------------- /http.go: -------------------------------------------------------------------------------- 1 | package httputils 2 | 3 | import ( 4 | "bytes" 5 | "io/ioutil" 6 | "net/http" 7 | "time" 8 | ) 9 | 10 | type HttpConPool struct { 11 | Conn *http.Client 12 | } 13 | 14 | // Get a http pool for http client 15 | func GetHttpPool(max_conn int, duration int64) *HttpConPool { 16 | hpool := new(HttpConPool) 17 | hpool.Conn = &http.Client{ 18 | Transport: &http.Transport{ 19 | MaxIdleConnsPerHost: max_conn, 20 | }, 21 | Timeout: time.Duration(duration) * time.Millisecond, 22 | } 23 | 24 | return hpool 25 | } 26 | 27 | // send a http request of post or get 28 | func (h *HttpConPool) Request(url string, method string, data string, header map[string]string) (interface{}, error) { 29 | req, err := http.NewRequest(method, url, bytes.NewBuffer([]byte(data))) 30 | if err != nil { 31 | return nil, err 32 | } 33 | 34 | for h, v := range header { 35 | req.Header.Set(h, v) 36 | } 37 | 38 | response, err := h.Conn.Do(req) 39 | 40 | if err != nil { 41 | return nil, err 42 | } else if response != nil { 43 | defer response.Body.Close() 44 | 45 | r_body, err := ioutil.ReadAll(response.Body) 46 | if err != nil { 47 | return nil, err 48 | } else { 49 | return string(r_body), nil 50 | } 51 | } else { 52 | return nil, nil 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /http_test.go: -------------------------------------------------------------------------------- 1 | package httputils 2 | 3 | import ( 4 | "testing" 5 | 6 | "net/http" 7 | 8 | . "github.com/smartystreets/goconvey/convey" 9 | ) 10 | 11 | func TestGetHttpPool(t *testing.T) { 12 | Convey("get a http pool", t, func() { 13 | hpool := GetHttpPool(100, 5000) 14 | So(hpool, ShouldNotBeNil) 15 | }) 16 | } 17 | 18 | func TestHttpConPool_Request(t *testing.T) { 19 | hpool := GetHttpPool(100, 100) 20 | resp, err := hpool.Request("http://www.baidu.com", http.MethodGet, "", map[string]string{}) 21 | Convey("test http get request", t, func() { 22 | if err != nil { 23 | So(resp, ShouldBeNil) 24 | } 25 | }) 26 | } 27 | -------------------------------------------------------------------------------- /vendor/github.com/gopherjs/gopherjs/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Richard Musiol. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 18 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 20 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /vendor/github.com/gopherjs/gopherjs/js/js.go: -------------------------------------------------------------------------------- 1 | // Package js provides functions for interacting with native JavaScript APIs. Calls to these functions are treated specially by GopherJS and translated directly to their corresponding JavaScript syntax. 2 | // 3 | // Use MakeWrapper to expose methods to JavaScript. When passing values directly, the following type conversions are performed: 4 | // 5 | // | Go type | JavaScript type | Conversions back to interface{} | 6 | // | --------------------- | --------------------- | ------------------------------- | 7 | // | bool | Boolean | bool | 8 | // | integers and floats | Number | float64 | 9 | // | string | String | string | 10 | // | []int8 | Int8Array | []int8 | 11 | // | []int16 | Int16Array | []int16 | 12 | // | []int32, []int | Int32Array | []int | 13 | // | []uint8 | Uint8Array | []uint8 | 14 | // | []uint16 | Uint16Array | []uint16 | 15 | // | []uint32, []uint | Uint32Array | []uint | 16 | // | []float32 | Float32Array | []float32 | 17 | // | []float64 | Float64Array | []float64 | 18 | // | all other slices | Array | []interface{} | 19 | // | arrays | see slice type | see slice type | 20 | // | functions | Function | func(...interface{}) *js.Object | 21 | // | time.Time | Date | time.Time | 22 | // | - | instanceof Node | *js.Object | 23 | // | maps, structs | instanceof Object | map[string]interface{} | 24 | // 25 | // Additionally, for a struct containing a *js.Object field, only the content of the field will be passed to JavaScript and vice versa. 26 | package js 27 | 28 | // Object is a container for a native JavaScript object. Calls to its methods are treated specially by GopherJS and translated directly to their JavaScript syntax. A nil pointer to Object is equal to JavaScript's "null". Object can not be used as a map key. 29 | type Object struct{ object *Object } 30 | 31 | // Get returns the object's property with the given key. 32 | func (o *Object) Get(key string) *Object { return o.object.Get(key) } 33 | 34 | // Set assigns the value to the object's property with the given key. 35 | func (o *Object) Set(key string, value interface{}) { o.object.Set(key, value) } 36 | 37 | // Delete removes the object's property with the given key. 38 | func (o *Object) Delete(key string) { o.object.Delete(key) } 39 | 40 | // Length returns the object's "length" property, converted to int. 41 | func (o *Object) Length() int { return o.object.Length() } 42 | 43 | // Index returns the i'th element of an array. 44 | func (o *Object) Index(i int) *Object { return o.object.Index(i) } 45 | 46 | // SetIndex sets the i'th element of an array. 47 | func (o *Object) SetIndex(i int, value interface{}) { o.object.SetIndex(i, value) } 48 | 49 | // Call calls the object's method with the given name. 50 | func (o *Object) Call(name string, args ...interface{}) *Object { return o.object.Call(name, args...) } 51 | 52 | // Invoke calls the object itself. This will fail if it is not a function. 53 | func (o *Object) Invoke(args ...interface{}) *Object { return o.object.Invoke(args...) } 54 | 55 | // New creates a new instance of this type object. This will fail if it not a function (constructor). 56 | func (o *Object) New(args ...interface{}) *Object { return o.object.New(args...) } 57 | 58 | // Bool returns the object converted to bool according to JavaScript type conversions. 59 | func (o *Object) Bool() bool { return o.object.Bool() } 60 | 61 | // String returns the object converted to string according to JavaScript type conversions. 62 | func (o *Object) String() string { return o.object.String() } 63 | 64 | // Int returns the object converted to int according to JavaScript type conversions (parseInt). 65 | func (o *Object) Int() int { return o.object.Int() } 66 | 67 | // Int64 returns the object converted to int64 according to JavaScript type conversions (parseInt). 68 | func (o *Object) Int64() int64 { return o.object.Int64() } 69 | 70 | // Uint64 returns the object converted to uint64 according to JavaScript type conversions (parseInt). 71 | func (o *Object) Uint64() uint64 { return o.object.Uint64() } 72 | 73 | // Float returns the object converted to float64 according to JavaScript type conversions (parseFloat). 74 | func (o *Object) Float() float64 { return o.object.Float() } 75 | 76 | // Interface returns the object converted to interface{}. See table in package comment for details. 77 | func (o *Object) Interface() interface{} { return o.object.Interface() } 78 | 79 | // Unsafe returns the object as an uintptr, which can be converted via unsafe.Pointer. Not intended for public use. 80 | func (o *Object) Unsafe() uintptr { return o.object.Unsafe() } 81 | 82 | // Error encapsulates JavaScript errors. Those are turned into a Go panic and may be recovered, giving an *Error that holds the JavaScript error object. 83 | type Error struct { 84 | *Object 85 | } 86 | 87 | // Error returns the message of the encapsulated JavaScript error object. 88 | func (err *Error) Error() string { 89 | return "JavaScript error: " + err.Get("message").String() 90 | } 91 | 92 | // Stack returns the stack property of the encapsulated JavaScript error object. 93 | func (err *Error) Stack() string { 94 | return err.Get("stack").String() 95 | } 96 | 97 | // Global gives JavaScript's global object ("window" for browsers and "GLOBAL" for Node.js). 98 | var Global *Object 99 | 100 | // Module gives the value of the "module" variable set by Node.js. Hint: Set a module export with 'js.Module.Get("exports").Set("exportName", ...)'. 101 | var Module *Object 102 | 103 | // Undefined gives the JavaScript value "undefined". 104 | var Undefined *Object 105 | 106 | // Debugger gets compiled to JavaScript's "debugger;" statement. 107 | func Debugger() {} 108 | 109 | // InternalObject returns the internal JavaScript object that represents i. Not intended for public use. 110 | func InternalObject(i interface{}) *Object { 111 | return nil 112 | } 113 | 114 | // MakeFunc wraps a function and gives access to the values of JavaScript's "this" and "arguments" keywords. 115 | func MakeFunc(fn func(this *Object, arguments []*Object) interface{}) *Object { 116 | return Global.Call("$makeFunc", InternalObject(fn)) 117 | } 118 | 119 | // Keys returns the keys of the given JavaScript object. 120 | func Keys(o *Object) []string { 121 | if o == nil || o == Undefined { 122 | return nil 123 | } 124 | a := Global.Get("Object").Call("keys", o) 125 | s := make([]string, a.Length()) 126 | for i := 0; i < a.Length(); i++ { 127 | s[i] = a.Index(i).String() 128 | } 129 | return s 130 | } 131 | 132 | // MakeWrapper creates a JavaScript object which has wrappers for the exported methods of i. Use explicit getter and setter methods to expose struct fields to JavaScript. 133 | func MakeWrapper(i interface{}) *Object { 134 | v := InternalObject(i) 135 | o := Global.Get("Object").New() 136 | o.Set("__internal_object__", v) 137 | methods := v.Get("constructor").Get("methods") 138 | for i := 0; i < methods.Length(); i++ { 139 | m := methods.Index(i) 140 | if m.Get("pkg").String() != "" { // not exported 141 | continue 142 | } 143 | o.Set(m.Get("name").String(), func(args ...*Object) *Object { 144 | return Global.Call("$externalizeFunction", v.Get(m.Get("prop").String()), m.Get("typ"), true).Call("apply", v, args) 145 | }) 146 | } 147 | return o 148 | } 149 | 150 | // NewArrayBuffer creates a JavaScript ArrayBuffer from a byte slice. 151 | func NewArrayBuffer(b []byte) *Object { 152 | slice := InternalObject(b) 153 | offset := slice.Get("$offset").Int() 154 | length := slice.Get("$length").Int() 155 | return slice.Get("$array").Get("buffer").Call("slice", offset, offset+length) 156 | } 157 | 158 | // M is a simple map type. It is intended as a shorthand for JavaScript objects (before conversion). 159 | type M map[string]interface{} 160 | 161 | // S is a simple slice type. It is intended as a shorthand for JavaScript arrays (before conversion). 162 | type S []interface{} 163 | 164 | func init() { 165 | // avoid dead code elimination 166 | e := Error{} 167 | _ = e 168 | } 169 | -------------------------------------------------------------------------------- /vendor/github.com/jtolds/gls/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Space Monkey, Inc. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software is furnished to do so, 8 | subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | -------------------------------------------------------------------------------- /vendor/github.com/jtolds/gls/README.md: -------------------------------------------------------------------------------- 1 | gls 2 | === 3 | 4 | Goroutine local storage 5 | 6 | ### IMPORTANT NOTE ### 7 | 8 | It is my duty to point you to https://blog.golang.org/context, which is how 9 | Google solves all of the problems you'd perhaps consider using this package 10 | for at scale. 11 | 12 | One downside to Google's approach is that *all* of your functions must have 13 | a new first argument, but after clearing that hurdle everything else is much 14 | better. 15 | 16 | If you aren't interested in this warning, read on. 17 | 18 | ### Huhwaht? Why? ### 19 | 20 | Every so often, a thread shows up on the 21 | [golang-nuts](https://groups.google.com/d/forum/golang-nuts) asking for some 22 | form of goroutine-local-storage, or some kind of goroutine id, or some kind of 23 | context. There are a few valid use cases for goroutine-local-storage, one of 24 | the most prominent being log line context. One poster was interested in being 25 | able to log an HTTP request context id in every log line in the same goroutine 26 | as the incoming HTTP request, without having to change every library and 27 | function call he was interested in logging. 28 | 29 | This would be pretty useful. Provided that you could get some kind of 30 | goroutine-local-storage, you could call 31 | [log.SetOutput](http://golang.org/pkg/log/#SetOutput) with your own logging 32 | writer that checks goroutine-local-storage for some context information and 33 | adds that context to your log lines. 34 | 35 | But alas, Andrew Gerrand's typically diplomatic answer to the question of 36 | goroutine-local variables was: 37 | 38 | > We wouldn't even be having this discussion if thread local storage wasn't 39 | > useful. But every feature comes at a cost, and in my opinion the cost of 40 | > threadlocals far outweighs their benefits. They're just not a good fit for 41 | > Go. 42 | 43 | So, yeah, that makes sense. That's a pretty good reason for why the language 44 | won't support a specific and (relatively) unuseful feature that requires some 45 | runtime changes, just for the sake of a little bit of log improvement. 46 | 47 | But does Go require runtime changes? 48 | 49 | ### How it works ### 50 | 51 | Go has pretty fantastic introspective and reflective features, but one thing Go 52 | doesn't give you is any kind of access to the stack pointer, or frame pointer, 53 | or goroutine id, or anything contextual about your current stack. It gives you 54 | access to your list of callers, but only along with program counters, which are 55 | fixed at compile time. 56 | 57 | But it does give you the stack. 58 | 59 | So, we define 16 special functions and embed base-16 tags into the stack using 60 | the call order of those 16 functions. Then, we can read our tags back out of 61 | the stack looking at the callers list. 62 | 63 | We then use these tags as an index into a traditional map for implementing 64 | this library. 65 | 66 | ### What are people saying? ### 67 | 68 | "Wow, that's horrifying." 69 | 70 | "This is the most terrible thing I have seen in a very long time." 71 | 72 | "Where is it getting a context from? Is this serializing all the requests? 73 | What the heck is the client being bound to? What are these tags? Why does he 74 | need callers? Oh god no. No no no." 75 | 76 | ### Docs ### 77 | 78 | Please see the docs at http://godoc.org/github.com/jtolds/gls 79 | 80 | ### Related ### 81 | 82 | If you're okay relying on the string format of the current runtime stacktrace 83 | including a unique goroutine id (not guaranteed by the spec or anything, but 84 | very unlikely to change within a Go release), you might be able to squeeze 85 | out a bit more performance by using this similar library, inspired by some 86 | code Brad Fitzpatrick wrote for debugging his HTTP/2 library: 87 | https://github.com/tylerb/gls (in contrast, jtolds/gls doesn't require 88 | any knowledge of the string format of the runtime stacktrace, which 89 | probably adds unnecessary overhead). 90 | -------------------------------------------------------------------------------- /vendor/github.com/jtolds/gls/context.go: -------------------------------------------------------------------------------- 1 | // Package gls implements goroutine-local storage. 2 | package gls 3 | 4 | import ( 5 | "sync" 6 | ) 7 | 8 | var ( 9 | mgrRegistry = make(map[*ContextManager]bool) 10 | mgrRegistryMtx sync.RWMutex 11 | ) 12 | 13 | // Values is simply a map of key types to value types. Used by SetValues to 14 | // set multiple values at once. 15 | type Values map[interface{}]interface{} 16 | 17 | // ContextManager is the main entrypoint for interacting with 18 | // Goroutine-local-storage. You can have multiple independent ContextManagers 19 | // at any given time. ContextManagers are usually declared globally for a given 20 | // class of context variables. You should use NewContextManager for 21 | // construction. 22 | type ContextManager struct { 23 | mtx sync.Mutex 24 | values map[uint]Values 25 | } 26 | 27 | // NewContextManager returns a brand new ContextManager. It also registers the 28 | // new ContextManager in the ContextManager registry which is used by the Go 29 | // method. ContextManagers are typically defined globally at package scope. 30 | func NewContextManager() *ContextManager { 31 | mgr := &ContextManager{values: make(map[uint]Values)} 32 | mgrRegistryMtx.Lock() 33 | defer mgrRegistryMtx.Unlock() 34 | mgrRegistry[mgr] = true 35 | return mgr 36 | } 37 | 38 | // Unregister removes a ContextManager from the global registry, used by the 39 | // Go method. Only intended for use when you're completely done with a 40 | // ContextManager. Use of Unregister at all is rare. 41 | func (m *ContextManager) Unregister() { 42 | mgrRegistryMtx.Lock() 43 | defer mgrRegistryMtx.Unlock() 44 | delete(mgrRegistry, m) 45 | } 46 | 47 | // SetValues takes a collection of values and a function to call for those 48 | // values to be set in. Anything further down the stack will have the set 49 | // values available through GetValue. SetValues will add new values or replace 50 | // existing values of the same key and will not mutate or change values for 51 | // previous stack frames. 52 | // SetValues is slow (makes a copy of all current and new values for the new 53 | // gls-context) in order to reduce the amount of lookups GetValue requires. 54 | func (m *ContextManager) SetValues(new_values Values, context_call func()) { 55 | if len(new_values) == 0 { 56 | context_call() 57 | return 58 | } 59 | 60 | mutated_keys := make([]interface{}, 0, len(new_values)) 61 | mutated_vals := make(Values, len(new_values)) 62 | 63 | EnsureGoroutineId(func(gid uint) { 64 | m.mtx.Lock() 65 | state, found := m.values[gid] 66 | if !found { 67 | state = make(Values, len(new_values)) 68 | m.values[gid] = state 69 | } 70 | m.mtx.Unlock() 71 | 72 | for key, new_val := range new_values { 73 | mutated_keys = append(mutated_keys, key) 74 | if old_val, ok := state[key]; ok { 75 | mutated_vals[key] = old_val 76 | } 77 | state[key] = new_val 78 | } 79 | 80 | defer func() { 81 | if !found { 82 | m.mtx.Lock() 83 | delete(m.values, gid) 84 | m.mtx.Unlock() 85 | return 86 | } 87 | 88 | for _, key := range mutated_keys { 89 | if val, ok := mutated_vals[key]; ok { 90 | state[key] = val 91 | } else { 92 | delete(state, key) 93 | } 94 | } 95 | }() 96 | 97 | context_call() 98 | }) 99 | } 100 | 101 | // GetValue will return a previously set value, provided that the value was set 102 | // by SetValues somewhere higher up the stack. If the value is not found, ok 103 | // will be false. 104 | func (m *ContextManager) GetValue(key interface{}) ( 105 | value interface{}, ok bool) { 106 | gid, ok := GetGoroutineId() 107 | if !ok { 108 | return nil, false 109 | } 110 | 111 | m.mtx.Lock() 112 | state, found := m.values[gid] 113 | m.mtx.Unlock() 114 | 115 | if !found { 116 | return nil, false 117 | } 118 | value, ok = state[key] 119 | return value, ok 120 | } 121 | 122 | func (m *ContextManager) getValues() Values { 123 | gid, ok := GetGoroutineId() 124 | if !ok { 125 | return nil 126 | } 127 | m.mtx.Lock() 128 | state, _ := m.values[gid] 129 | m.mtx.Unlock() 130 | return state 131 | } 132 | 133 | // Go preserves ContextManager values and Goroutine-local-storage across new 134 | // goroutine invocations. The Go method makes a copy of all existing values on 135 | // all registered context managers and makes sure they are still set after 136 | // kicking off the provided function in a new goroutine. If you don't use this 137 | // Go method instead of the standard 'go' keyword, you will lose values in 138 | // ContextManagers, as goroutines have brand new stacks. 139 | func Go(cb func()) { 140 | mgrRegistryMtx.RLock() 141 | defer mgrRegistryMtx.RUnlock() 142 | 143 | for mgr := range mgrRegistry { 144 | values := mgr.getValues() 145 | if len(values) > 0 { 146 | cb = func(mgr *ContextManager, cb func()) func() { 147 | return func() { mgr.SetValues(values, cb) } 148 | }(mgr, cb) 149 | } 150 | } 151 | 152 | go cb() 153 | } 154 | -------------------------------------------------------------------------------- /vendor/github.com/jtolds/gls/gen_sym.go: -------------------------------------------------------------------------------- 1 | package gls 2 | 3 | import ( 4 | "sync" 5 | ) 6 | 7 | var ( 8 | keyMtx sync.Mutex 9 | keyCounter uint64 10 | ) 11 | 12 | // ContextKey is a throwaway value you can use as a key to a ContextManager 13 | type ContextKey struct{ id uint64 } 14 | 15 | // GenSym will return a brand new, never-before-used ContextKey 16 | func GenSym() ContextKey { 17 | keyMtx.Lock() 18 | defer keyMtx.Unlock() 19 | keyCounter += 1 20 | return ContextKey{id: keyCounter} 21 | } 22 | -------------------------------------------------------------------------------- /vendor/github.com/jtolds/gls/gid.go: -------------------------------------------------------------------------------- 1 | package gls 2 | 3 | var ( 4 | stackTagPool = &idPool{} 5 | ) 6 | 7 | // Will return this goroutine's identifier if set. If you always need a 8 | // goroutine identifier, you should use EnsureGoroutineId which will make one 9 | // if there isn't one already. 10 | func GetGoroutineId() (gid uint, ok bool) { 11 | return readStackTag() 12 | } 13 | 14 | // Will call cb with the current goroutine identifier. If one hasn't already 15 | // been generated, one will be created and set first. The goroutine identifier 16 | // might be invalid after cb returns. 17 | func EnsureGoroutineId(cb func(gid uint)) { 18 | if gid, ok := readStackTag(); ok { 19 | cb(gid) 20 | return 21 | } 22 | gid := stackTagPool.Acquire() 23 | defer stackTagPool.Release(gid) 24 | addStackTag(gid, func() { cb(gid) }) 25 | } 26 | -------------------------------------------------------------------------------- /vendor/github.com/jtolds/gls/id_pool.go: -------------------------------------------------------------------------------- 1 | package gls 2 | 3 | // though this could probably be better at keeping ids smaller, the goal of 4 | // this class is to keep a registry of the smallest unique integer ids 5 | // per-process possible 6 | 7 | import ( 8 | "sync" 9 | ) 10 | 11 | type idPool struct { 12 | mtx sync.Mutex 13 | released []uint 14 | max_id uint 15 | } 16 | 17 | func (p *idPool) Acquire() (id uint) { 18 | p.mtx.Lock() 19 | defer p.mtx.Unlock() 20 | if len(p.released) > 0 { 21 | id = p.released[len(p.released)-1] 22 | p.released = p.released[:len(p.released)-1] 23 | return id 24 | } 25 | id = p.max_id 26 | p.max_id++ 27 | return id 28 | } 29 | 30 | func (p *idPool) Release(id uint) { 31 | p.mtx.Lock() 32 | defer p.mtx.Unlock() 33 | p.released = append(p.released, id) 34 | } 35 | -------------------------------------------------------------------------------- /vendor/github.com/jtolds/gls/stack_tags.go: -------------------------------------------------------------------------------- 1 | package gls 2 | 3 | // so, basically, we're going to encode integer tags in base-16 on the stack 4 | 5 | const ( 6 | bitWidth = 4 7 | stackBatchSize = 16 8 | ) 9 | 10 | var ( 11 | pc_lookup = make(map[uintptr]int8, 17) 12 | mark_lookup [16]func(uint, func()) 13 | ) 14 | 15 | func init() { 16 | setEntries := func(f func(uint, func()), v int8) { 17 | var ptr uintptr 18 | f(0, func() { 19 | ptr = findPtr() 20 | }) 21 | pc_lookup[ptr] = v 22 | if v >= 0 { 23 | mark_lookup[v] = f 24 | } 25 | } 26 | setEntries(github_com_jtolds_gls_markS, -0x1) 27 | setEntries(github_com_jtolds_gls_mark0, 0x0) 28 | setEntries(github_com_jtolds_gls_mark1, 0x1) 29 | setEntries(github_com_jtolds_gls_mark2, 0x2) 30 | setEntries(github_com_jtolds_gls_mark3, 0x3) 31 | setEntries(github_com_jtolds_gls_mark4, 0x4) 32 | setEntries(github_com_jtolds_gls_mark5, 0x5) 33 | setEntries(github_com_jtolds_gls_mark6, 0x6) 34 | setEntries(github_com_jtolds_gls_mark7, 0x7) 35 | setEntries(github_com_jtolds_gls_mark8, 0x8) 36 | setEntries(github_com_jtolds_gls_mark9, 0x9) 37 | setEntries(github_com_jtolds_gls_markA, 0xa) 38 | setEntries(github_com_jtolds_gls_markB, 0xb) 39 | setEntries(github_com_jtolds_gls_markC, 0xc) 40 | setEntries(github_com_jtolds_gls_markD, 0xd) 41 | setEntries(github_com_jtolds_gls_markE, 0xe) 42 | setEntries(github_com_jtolds_gls_markF, 0xf) 43 | } 44 | 45 | func addStackTag(tag uint, context_call func()) { 46 | if context_call == nil { 47 | return 48 | } 49 | github_com_jtolds_gls_markS(tag, context_call) 50 | } 51 | 52 | // these private methods are named this horrendous name so gopherjs support 53 | // is easier. it shouldn't add any runtime cost in non-js builds. 54 | func github_com_jtolds_gls_markS(tag uint, cb func()) { _m(tag, cb) } 55 | func github_com_jtolds_gls_mark0(tag uint, cb func()) { _m(tag, cb) } 56 | func github_com_jtolds_gls_mark1(tag uint, cb func()) { _m(tag, cb) } 57 | func github_com_jtolds_gls_mark2(tag uint, cb func()) { _m(tag, cb) } 58 | func github_com_jtolds_gls_mark3(tag uint, cb func()) { _m(tag, cb) } 59 | func github_com_jtolds_gls_mark4(tag uint, cb func()) { _m(tag, cb) } 60 | func github_com_jtolds_gls_mark5(tag uint, cb func()) { _m(tag, cb) } 61 | func github_com_jtolds_gls_mark6(tag uint, cb func()) { _m(tag, cb) } 62 | func github_com_jtolds_gls_mark7(tag uint, cb func()) { _m(tag, cb) } 63 | func github_com_jtolds_gls_mark8(tag uint, cb func()) { _m(tag, cb) } 64 | func github_com_jtolds_gls_mark9(tag uint, cb func()) { _m(tag, cb) } 65 | func github_com_jtolds_gls_markA(tag uint, cb func()) { _m(tag, cb) } 66 | func github_com_jtolds_gls_markB(tag uint, cb func()) { _m(tag, cb) } 67 | func github_com_jtolds_gls_markC(tag uint, cb func()) { _m(tag, cb) } 68 | func github_com_jtolds_gls_markD(tag uint, cb func()) { _m(tag, cb) } 69 | func github_com_jtolds_gls_markE(tag uint, cb func()) { _m(tag, cb) } 70 | func github_com_jtolds_gls_markF(tag uint, cb func()) { _m(tag, cb) } 71 | 72 | func _m(tag_remainder uint, cb func()) { 73 | if tag_remainder == 0 { 74 | cb() 75 | } else { 76 | mark_lookup[tag_remainder&0xf](tag_remainder>>bitWidth, cb) 77 | } 78 | } 79 | 80 | func readStackTag() (tag uint, ok bool) { 81 | var current_tag uint 82 | offset := 0 83 | for { 84 | batch, next_offset := getStack(offset, stackBatchSize) 85 | for _, pc := range batch { 86 | val, ok := pc_lookup[pc] 87 | if !ok { 88 | continue 89 | } 90 | if val < 0 { 91 | return current_tag, true 92 | } 93 | current_tag <<= bitWidth 94 | current_tag += uint(val) 95 | } 96 | if next_offset == 0 { 97 | break 98 | } 99 | offset = next_offset 100 | } 101 | return 0, false 102 | } 103 | 104 | func (m *ContextManager) preventInlining() { 105 | // dunno if findPtr or getStack are likely to get inlined in a future release 106 | // of go, but if they are inlined and their callers are inlined, that could 107 | // hork some things. let's do our best to explain to the compiler that we 108 | // really don't want those two functions inlined by saying they could change 109 | // at any time. assumes preventInlining doesn't get compiled out. 110 | // this whole thing is probably overkill. 111 | findPtr = m.values[0][0].(func() uintptr) 112 | getStack = m.values[0][1].(func(int, int) ([]uintptr, int)) 113 | } 114 | -------------------------------------------------------------------------------- /vendor/github.com/jtolds/gls/stack_tags_js.go: -------------------------------------------------------------------------------- 1 | // +build js 2 | 3 | package gls 4 | 5 | // This file is used for GopherJS builds, which don't have normal runtime 6 | // stack trace support 7 | 8 | import ( 9 | "strconv" 10 | "strings" 11 | 12 | "github.com/gopherjs/gopherjs/js" 13 | ) 14 | 15 | const ( 16 | jsFuncNamePrefix = "github_com_jtolds_gls_mark" 17 | ) 18 | 19 | func jsMarkStack() (f []uintptr) { 20 | lines := strings.Split( 21 | js.Global.Get("Error").New().Get("stack").String(), "\n") 22 | f = make([]uintptr, 0, len(lines)) 23 | for i, line := range lines { 24 | line = strings.TrimSpace(line) 25 | if line == "" { 26 | continue 27 | } 28 | if i == 0 { 29 | if line != "Error" { 30 | panic("didn't understand js stack trace") 31 | } 32 | continue 33 | } 34 | fields := strings.Fields(line) 35 | if len(fields) < 2 || fields[0] != "at" { 36 | panic("didn't understand js stack trace") 37 | } 38 | 39 | pos := strings.Index(fields[1], jsFuncNamePrefix) 40 | if pos < 0 { 41 | continue 42 | } 43 | pos += len(jsFuncNamePrefix) 44 | if pos >= len(fields[1]) { 45 | panic("didn't understand js stack trace") 46 | } 47 | char := string(fields[1][pos]) 48 | switch char { 49 | case "S": 50 | f = append(f, uintptr(0)) 51 | default: 52 | val, err := strconv.ParseUint(char, 16, 8) 53 | if err != nil { 54 | panic("didn't understand js stack trace") 55 | } 56 | f = append(f, uintptr(val)+1) 57 | } 58 | } 59 | return f 60 | } 61 | 62 | // variables to prevent inlining 63 | var ( 64 | findPtr = func() uintptr { 65 | funcs := jsMarkStack() 66 | if len(funcs) == 0 { 67 | panic("failed to find function pointer") 68 | } 69 | return funcs[0] 70 | } 71 | 72 | getStack = func(offset, amount int) (stack []uintptr, next_offset int) { 73 | return jsMarkStack(), 0 74 | } 75 | ) 76 | -------------------------------------------------------------------------------- /vendor/github.com/jtolds/gls/stack_tags_main.go: -------------------------------------------------------------------------------- 1 | // +build !js 2 | 3 | package gls 4 | 5 | // This file is used for standard Go builds, which have the expected runtime 6 | // support 7 | 8 | import ( 9 | "runtime" 10 | ) 11 | 12 | var ( 13 | findPtr = func() uintptr { 14 | var pc [1]uintptr 15 | n := runtime.Callers(4, pc[:]) 16 | if n != 1 { 17 | panic("failed to find function pointer") 18 | } 19 | return pc[0] 20 | } 21 | 22 | getStack = func(offset, amount int) (stack []uintptr, next_offset int) { 23 | stack = make([]uintptr, amount) 24 | stack = stack[:runtime.Callers(offset, stack)] 25 | if len(stack) < amount { 26 | return stack, 0 27 | } 28 | return stack, offset + len(stack) 29 | } 30 | ) 31 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | Thumbs.db 3 | *.iml 4 | /.idea 5 | coverage.out 6 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.x 5 | 6 | install: 7 | - go get -t ./... 8 | 9 | script: go test ./... -v 10 | 11 | sudo: false 12 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | In general, the code posted to the [SmartyStreets github organization](https://github.com/smartystreets) is created to solve specific problems at SmartyStreets that are ancillary to our core products in the address verification industry and may or may not be useful to other organizations or developers. Our reason for posting said code isn't necessarily to solicit feedback or contributions from the community but more as a showcase of some of the approaches to solving problems we have adopted. 4 | 5 | Having stated that, we do consider issues raised by other githubbers as well as contributions submitted via pull requests. When submitting such a pull request, please follow these guidelines: 6 | 7 | - _Look before you leap:_ If the changes you plan to make are significant, it's in everyone's best interest for you to discuss them with a SmartyStreets team member prior to opening a pull request. 8 | - _License and ownership:_ If modifying the `LICENSE.md` file, limit your changes to fixing typographical mistakes. Do NOT modify the actual terms in the license or the copyright by **SmartyStreets, LLC**. Code submitted to SmartyStreets projects becomes property of SmartyStreets and must be compatible with the associated license. 9 | - _Testing:_ If the code you are submitting resides in packages/modules covered by automated tests, be sure to add passing tests that cover your changes and assert expected behavior and state. Submit the additional test cases as part of your change set. 10 | - _Style:_ Match your approach to **naming** and **formatting** with the surrounding code. Basically, the code you submit shouldn't stand out. 11 | - "Naming" refers to such constructs as variables, methods, functions, classes, structs, interfaces, packages, modules, directories, files, etc... 12 | - "Formatting" refers to such constructs as whitespace, horizontal line length, vertical function length, vertical file length, indentation, curly braces, etc... 13 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 SmartyStreets, LLC 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | 21 | NOTE: Various optional and subordinate components carry their own licensing 22 | requirements and restrictions. Use of those components is subject to the terms 23 | and conditions outlined the respective license of each component. 24 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/collections.go: -------------------------------------------------------------------------------- 1 | package assertions 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | 7 | "github.com/smartystreets/assertions/internal/oglematchers" 8 | ) 9 | 10 | // ShouldContain receives exactly two parameters. The first is a slice and the 11 | // second is a proposed member. Membership is determined using ShouldEqual. 12 | func ShouldContain(actual interface{}, expected ...interface{}) string { 13 | if fail := need(1, expected); fail != success { 14 | return fail 15 | } 16 | 17 | if matchError := oglematchers.Contains(expected[0]).Matches(actual); matchError != nil { 18 | typeName := reflect.TypeOf(actual) 19 | 20 | if fmt.Sprintf("%v", matchError) == "which is not a slice or array" { 21 | return fmt.Sprintf(shouldHaveBeenAValidCollection, typeName) 22 | } 23 | return fmt.Sprintf(shouldHaveContained, typeName, expected[0]) 24 | } 25 | return success 26 | } 27 | 28 | // ShouldNotContain receives exactly two parameters. The first is a slice and the 29 | // second is a proposed member. Membership is determinied using ShouldEqual. 30 | func ShouldNotContain(actual interface{}, expected ...interface{}) string { 31 | if fail := need(1, expected); fail != success { 32 | return fail 33 | } 34 | typeName := reflect.TypeOf(actual) 35 | 36 | if matchError := oglematchers.Contains(expected[0]).Matches(actual); matchError != nil { 37 | if fmt.Sprintf("%v", matchError) == "which is not a slice or array" { 38 | return fmt.Sprintf(shouldHaveBeenAValidCollection, typeName) 39 | } 40 | return success 41 | } 42 | return fmt.Sprintf(shouldNotHaveContained, typeName, expected[0]) 43 | } 44 | 45 | // ShouldContainKey receives exactly two parameters. The first is a map and the 46 | // second is a proposed key. Keys are compared with a simple '=='. 47 | func ShouldContainKey(actual interface{}, expected ...interface{}) string { 48 | if fail := need(1, expected); fail != success { 49 | return fail 50 | } 51 | 52 | keys, isMap := mapKeys(actual) 53 | if !isMap { 54 | return fmt.Sprintf(shouldHaveBeenAValidMap, reflect.TypeOf(actual)) 55 | } 56 | 57 | if !keyFound(keys, expected[0]) { 58 | return fmt.Sprintf(shouldHaveContainedKey, reflect.TypeOf(actual), expected) 59 | } 60 | 61 | return "" 62 | } 63 | 64 | // ShouldNotContainKey receives exactly two parameters. The first is a map and the 65 | // second is a proposed absent key. Keys are compared with a simple '=='. 66 | func ShouldNotContainKey(actual interface{}, expected ...interface{}) string { 67 | if fail := need(1, expected); fail != success { 68 | return fail 69 | } 70 | 71 | keys, isMap := mapKeys(actual) 72 | if !isMap { 73 | return fmt.Sprintf(shouldHaveBeenAValidMap, reflect.TypeOf(actual)) 74 | } 75 | 76 | if keyFound(keys, expected[0]) { 77 | return fmt.Sprintf(shouldNotHaveContainedKey, reflect.TypeOf(actual), expected) 78 | } 79 | 80 | return "" 81 | } 82 | 83 | func mapKeys(m interface{}) ([]reflect.Value, bool) { 84 | value := reflect.ValueOf(m) 85 | if value.Kind() != reflect.Map { 86 | return nil, false 87 | } 88 | return value.MapKeys(), true 89 | } 90 | func keyFound(keys []reflect.Value, expectedKey interface{}) bool { 91 | found := false 92 | for _, key := range keys { 93 | if key.Interface() == expectedKey { 94 | found = true 95 | } 96 | } 97 | return found 98 | } 99 | 100 | // ShouldBeIn receives at least 2 parameters. The first is a proposed member of the collection 101 | // that is passed in either as the second parameter, or of the collection that is comprised 102 | // of all the remaining parameters. This assertion ensures that the proposed member is in 103 | // the collection (using ShouldEqual). 104 | func ShouldBeIn(actual interface{}, expected ...interface{}) string { 105 | if fail := atLeast(1, expected); fail != success { 106 | return fail 107 | } 108 | 109 | if len(expected) == 1 { 110 | return shouldBeIn(actual, expected[0]) 111 | } 112 | return shouldBeIn(actual, expected) 113 | } 114 | func shouldBeIn(actual interface{}, expected interface{}) string { 115 | if matchError := oglematchers.Contains(actual).Matches(expected); matchError != nil { 116 | return fmt.Sprintf(shouldHaveBeenIn, actual, reflect.TypeOf(expected)) 117 | } 118 | return success 119 | } 120 | 121 | // ShouldNotBeIn receives at least 2 parameters. The first is a proposed member of the collection 122 | // that is passed in either as the second parameter, or of the collection that is comprised 123 | // of all the remaining parameters. This assertion ensures that the proposed member is NOT in 124 | // the collection (using ShouldEqual). 125 | func ShouldNotBeIn(actual interface{}, expected ...interface{}) string { 126 | if fail := atLeast(1, expected); fail != success { 127 | return fail 128 | } 129 | 130 | if len(expected) == 1 { 131 | return shouldNotBeIn(actual, expected[0]) 132 | } 133 | return shouldNotBeIn(actual, expected) 134 | } 135 | func shouldNotBeIn(actual interface{}, expected interface{}) string { 136 | if matchError := oglematchers.Contains(actual).Matches(expected); matchError == nil { 137 | return fmt.Sprintf(shouldNotHaveBeenIn, actual, reflect.TypeOf(expected)) 138 | } 139 | return success 140 | } 141 | 142 | // ShouldBeEmpty receives a single parameter (actual) and determines whether or not 143 | // calling len(actual) would return `0`. It obeys the rules specified by the len 144 | // function for determining length: http://golang.org/pkg/builtin/#len 145 | func ShouldBeEmpty(actual interface{}, expected ...interface{}) string { 146 | if fail := need(0, expected); fail != success { 147 | return fail 148 | } 149 | 150 | if actual == nil { 151 | return success 152 | } 153 | 154 | value := reflect.ValueOf(actual) 155 | switch value.Kind() { 156 | case reflect.Slice: 157 | if value.Len() == 0 { 158 | return success 159 | } 160 | case reflect.Chan: 161 | if value.Len() == 0 { 162 | return success 163 | } 164 | case reflect.Map: 165 | if value.Len() == 0 { 166 | return success 167 | } 168 | case reflect.String: 169 | if value.Len() == 0 { 170 | return success 171 | } 172 | case reflect.Ptr: 173 | elem := value.Elem() 174 | kind := elem.Kind() 175 | if (kind == reflect.Slice || kind == reflect.Array) && elem.Len() == 0 { 176 | return success 177 | } 178 | } 179 | 180 | return fmt.Sprintf(shouldHaveBeenEmpty, actual) 181 | } 182 | 183 | // ShouldNotBeEmpty receives a single parameter (actual) and determines whether or not 184 | // calling len(actual) would return a value greater than zero. It obeys the rules 185 | // specified by the `len` function for determining length: http://golang.org/pkg/builtin/#len 186 | func ShouldNotBeEmpty(actual interface{}, expected ...interface{}) string { 187 | if fail := need(0, expected); fail != success { 188 | return fail 189 | } 190 | 191 | if empty := ShouldBeEmpty(actual, expected...); empty != success { 192 | return success 193 | } 194 | return fmt.Sprintf(shouldNotHaveBeenEmpty, actual) 195 | } 196 | 197 | // ShouldHaveLength receives 2 parameters. The first is a collection to check 198 | // the length of, the second being the expected length. It obeys the rules 199 | // specified by the len function for determining length: 200 | // http://golang.org/pkg/builtin/#len 201 | func ShouldHaveLength(actual interface{}, expected ...interface{}) string { 202 | if fail := need(1, expected); fail != success { 203 | return fail 204 | } 205 | 206 | var expectedLen int64 207 | lenValue := reflect.ValueOf(expected[0]) 208 | switch lenValue.Kind() { 209 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: 210 | expectedLen = lenValue.Int() 211 | case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: 212 | expectedLen = int64(lenValue.Uint()) 213 | default: 214 | return fmt.Sprintf(shouldHaveBeenAValidInteger, reflect.TypeOf(expected[0])) 215 | } 216 | 217 | if expectedLen < 0 { 218 | return fmt.Sprintf(shouldHaveBeenAValidLength, expected[0]) 219 | } 220 | 221 | value := reflect.ValueOf(actual) 222 | switch value.Kind() { 223 | case reflect.Slice, 224 | reflect.Chan, 225 | reflect.Map, 226 | reflect.String: 227 | if int64(value.Len()) == expectedLen { 228 | return success 229 | } else { 230 | return fmt.Sprintf(shouldHaveHadLength, actual, value.Len(), expectedLen) 231 | } 232 | case reflect.Ptr: 233 | elem := value.Elem() 234 | kind := elem.Kind() 235 | if kind == reflect.Slice || kind == reflect.Array { 236 | if int64(elem.Len()) == expectedLen { 237 | return success 238 | } else { 239 | return fmt.Sprintf(shouldHaveHadLength, actual, elem.Len(), expectedLen) 240 | } 241 | } 242 | } 243 | return fmt.Sprintf(shouldHaveBeenAValidCollection, reflect.TypeOf(actual)) 244 | } 245 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/doc.go: -------------------------------------------------------------------------------- 1 | // Package assertions contains the implementations for all assertions which 2 | // are referenced in goconvey's `convey` package 3 | // (github.com/smartystreets/goconvey/convey) and gunit (github.com/smartystreets/gunit) 4 | // for use with the So(...) method. 5 | // They can also be used in traditional Go test functions and even in 6 | // applications. 7 | // 8 | // Many of the assertions lean heavily on work done by Aaron Jacobs in his excellent oglematchers library. 9 | // (https://github.com/jacobsa/oglematchers) 10 | // The ShouldResemble assertion leans heavily on work done by Daniel Jacques in his very helpful go-render library. 11 | // (https://github.com/luci/go-render) 12 | package assertions 13 | 14 | import ( 15 | "fmt" 16 | "runtime" 17 | ) 18 | 19 | // By default we use a no-op serializer. The actual Serializer provides a JSON 20 | // representation of failure results on selected assertions so the goconvey 21 | // web UI can display a convenient diff. 22 | var serializer Serializer = new(noopSerializer) 23 | 24 | // GoConveyMode provides control over JSON serialization of failures. When 25 | // using the assertions in this package from the convey package JSON results 26 | // are very helpful and can be rendered in a DIFF view. In that case, this function 27 | // will be called with a true value to enable the JSON serialization. By default, 28 | // the assertions in this package will not serializer a JSON result, making 29 | // standalone usage more convenient. 30 | func GoConveyMode(yes bool) { 31 | if yes { 32 | serializer = newSerializer() 33 | } else { 34 | serializer = new(noopSerializer) 35 | } 36 | } 37 | 38 | type testingT interface { 39 | Error(args ...interface{}) 40 | } 41 | 42 | type Assertion struct { 43 | t testingT 44 | failed bool 45 | } 46 | 47 | // New swallows the *testing.T struct and prints failed assertions using t.Error. 48 | // Example: assertions.New(t).So(1, should.Equal, 1) 49 | func New(t testingT) *Assertion { 50 | return &Assertion{t: t} 51 | } 52 | 53 | // Failed reports whether any calls to So (on this Assertion instance) have failed. 54 | func (this *Assertion) Failed() bool { 55 | return this.failed 56 | } 57 | 58 | // So calls the standalone So function and additionally, calls t.Error in failure scenarios. 59 | func (this *Assertion) So(actual interface{}, assert assertion, expected ...interface{}) bool { 60 | ok, result := So(actual, assert, expected...) 61 | if !ok { 62 | this.failed = true 63 | _, file, line, _ := runtime.Caller(1) 64 | this.t.Error(fmt.Sprintf("\n%s:%d\n%s", file, line, result)) 65 | } 66 | return ok 67 | } 68 | 69 | // So is a convenience function (as opposed to an inconvenience function?) 70 | // for running assertions on arbitrary arguments in any context, be it for testing or even 71 | // application logging. It allows you to perform assertion-like behavior (and get nicely 72 | // formatted messages detailing discrepancies) but without the program blowing up or panicking. 73 | // All that is required is to import this package and call `So` with one of the assertions 74 | // exported by this package as the second parameter. 75 | // The first return parameter is a boolean indicating if the assertion was true. The second 76 | // return parameter is the well-formatted message showing why an assertion was incorrect, or 77 | // blank if the assertion was correct. 78 | // 79 | // Example: 80 | // 81 | // if ok, message := So(x, ShouldBeGreaterThan, y); !ok { 82 | // log.Println(message) 83 | // } 84 | // 85 | // For an alternative implementation of So (that provides more flexible return options) 86 | // see the `So` function in the package at github.com/smartystreets/assertions/assert. 87 | func So(actual interface{}, assert assertion, expected ...interface{}) (bool, string) { 88 | if result := so(actual, assert, expected...); len(result) == 0 { 89 | return true, result 90 | } else { 91 | return false, result 92 | } 93 | } 94 | 95 | // so is like So, except that it only returns the string message, which is blank if the 96 | // assertion passed. Used to facilitate testing. 97 | func so(actual interface{}, assert func(interface{}, ...interface{}) string, expected ...interface{}) string { 98 | return assert(actual, expected...) 99 | } 100 | 101 | // assertion is an alias for a function with a signature that the So() 102 | // function can handle. Any future or custom assertions should conform to this 103 | // method signature. The return value should be an empty string if the assertion 104 | // passes and a well-formed failure message if not. 105 | type assertion func(actual interface{}, expected ...interface{}) string 106 | 107 | //////////////////////////////////////////////////////////////////////////// 108 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/equal_method.go: -------------------------------------------------------------------------------- 1 | package assertions 2 | 3 | import "reflect" 4 | 5 | type equalityMethodSpecification struct { 6 | a interface{} 7 | b interface{} 8 | 9 | aType reflect.Type 10 | bType reflect.Type 11 | 12 | equalMethod reflect.Value 13 | } 14 | 15 | func newEqualityMethodSpecification(a, b interface{}) *equalityMethodSpecification { 16 | return &equalityMethodSpecification{ 17 | a: a, 18 | b: b, 19 | } 20 | } 21 | 22 | func (this *equalityMethodSpecification) IsSatisfied() bool { 23 | if !this.bothAreSameType() { 24 | return false 25 | } 26 | if !this.typeHasEqualMethod() { 27 | return false 28 | } 29 | if !this.equalMethodReceivesSameTypeForComparison() { 30 | return false 31 | } 32 | if !this.equalMethodReturnsBool() { 33 | return false 34 | } 35 | return true 36 | } 37 | 38 | func (this *equalityMethodSpecification) bothAreSameType() bool { 39 | this.aType = reflect.TypeOf(this.a) 40 | if this.aType == nil { 41 | return false 42 | } 43 | if this.aType.Kind() == reflect.Ptr { 44 | this.aType = this.aType.Elem() 45 | } 46 | this.bType = reflect.TypeOf(this.b) 47 | return this.aType == this.bType 48 | } 49 | func (this *equalityMethodSpecification) typeHasEqualMethod() bool { 50 | aInstance := reflect.ValueOf(this.a) 51 | this.equalMethod = aInstance.MethodByName("Equal") 52 | return this.equalMethod != reflect.Value{} 53 | } 54 | 55 | func (this *equalityMethodSpecification) equalMethodReceivesSameTypeForComparison() bool { 56 | signature := this.equalMethod.Type() 57 | return signature.NumIn() == 1 && signature.In(0) == this.aType 58 | } 59 | 60 | func (this *equalityMethodSpecification) equalMethodReturnsBool() bool { 61 | signature := this.equalMethod.Type() 62 | return signature.NumOut() == 1 && signature.Out(0) == reflect.TypeOf(true) 63 | } 64 | 65 | func (this *equalityMethodSpecification) AreEqual() bool { 66 | a := reflect.ValueOf(this.a) 67 | b := reflect.ValueOf(this.b) 68 | return areEqual(a, b) && areEqual(b, a) 69 | } 70 | func areEqual(receiver reflect.Value, argument reflect.Value) bool { 71 | equalMethod := receiver.MethodByName("Equal") 72 | argumentList := []reflect.Value{argument} 73 | result := equalMethod.Call(argumentList) 74 | return result[0].Bool() 75 | } 76 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/equality.go: -------------------------------------------------------------------------------- 1 | package assertions 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "math" 7 | "reflect" 8 | "strings" 9 | 10 | "github.com/smartystreets/assertions/internal/go-render/render" 11 | "github.com/smartystreets/assertions/internal/oglematchers" 12 | ) 13 | 14 | // ShouldEqual receives exactly two parameters and does an equality check 15 | // using the following semantics: 16 | // 1. If the expected and actual values implement an Equal method in the form 17 | // `func (this T) Equal(that T) bool` then call the method. If true, they are equal. 18 | // 2. The expected and actual values are judged equal or not by oglematchers.Equals. 19 | func ShouldEqual(actual interface{}, expected ...interface{}) string { 20 | if message := need(1, expected); message != success { 21 | return message 22 | } 23 | return shouldEqual(actual, expected[0]) 24 | } 25 | func shouldEqual(actual, expected interface{}) (message string) { 26 | defer func() { 27 | if r := recover(); r != nil { 28 | message = serializer.serialize(expected, actual, fmt.Sprintf(shouldHaveBeenEqual, expected, actual)) 29 | } 30 | }() 31 | 32 | if specification := newEqualityMethodSpecification(expected, actual); specification.IsSatisfied() { 33 | if specification.AreEqual() { 34 | return success 35 | } else { 36 | message = fmt.Sprintf(shouldHaveBeenEqual, expected, actual) 37 | return serializer.serialize(expected, actual, message) 38 | } 39 | } 40 | if matchError := oglematchers.Equals(expected).Matches(actual); matchError != nil { 41 | expectedSyntax := fmt.Sprintf("%v", expected) 42 | actualSyntax := fmt.Sprintf("%v", actual) 43 | if expectedSyntax == actualSyntax && reflect.TypeOf(expected) != reflect.TypeOf(actual) { 44 | message = fmt.Sprintf(shouldHaveBeenEqualTypeMismatch, expected, expected, actual, actual) 45 | } else { 46 | message = fmt.Sprintf(shouldHaveBeenEqual, expected, actual) 47 | } 48 | return serializer.serialize(expected, actual, message) 49 | } 50 | 51 | return success 52 | } 53 | 54 | // ShouldNotEqual receives exactly two parameters and does an inequality check. 55 | // See ShouldEqual for details on how equality is determined. 56 | func ShouldNotEqual(actual interface{}, expected ...interface{}) string { 57 | if fail := need(1, expected); fail != success { 58 | return fail 59 | } else if ShouldEqual(actual, expected[0]) == success { 60 | return fmt.Sprintf(shouldNotHaveBeenEqual, actual, expected[0]) 61 | } 62 | return success 63 | } 64 | 65 | // ShouldAlmostEqual makes sure that two parameters are close enough to being equal. 66 | // The acceptable delta may be specified with a third argument, 67 | // or a very small default delta will be used. 68 | func ShouldAlmostEqual(actual interface{}, expected ...interface{}) string { 69 | actualFloat, expectedFloat, deltaFloat, err := cleanAlmostEqualInput(actual, expected...) 70 | 71 | if err != "" { 72 | return err 73 | } 74 | 75 | if math.Abs(actualFloat-expectedFloat) <= deltaFloat { 76 | return success 77 | } else { 78 | return fmt.Sprintf(shouldHaveBeenAlmostEqual, actualFloat, expectedFloat) 79 | } 80 | } 81 | 82 | // ShouldNotAlmostEqual is the inverse of ShouldAlmostEqual 83 | func ShouldNotAlmostEqual(actual interface{}, expected ...interface{}) string { 84 | actualFloat, expectedFloat, deltaFloat, err := cleanAlmostEqualInput(actual, expected...) 85 | 86 | if err != "" { 87 | return err 88 | } 89 | 90 | if math.Abs(actualFloat-expectedFloat) > deltaFloat { 91 | return success 92 | } else { 93 | return fmt.Sprintf(shouldHaveNotBeenAlmostEqual, actualFloat, expectedFloat) 94 | } 95 | } 96 | 97 | func cleanAlmostEqualInput(actual interface{}, expected ...interface{}) (float64, float64, float64, string) { 98 | deltaFloat := 0.0000000001 99 | 100 | if len(expected) == 0 { 101 | return 0.0, 0.0, 0.0, "This assertion requires exactly one comparison value and an optional delta (you provided neither)" 102 | } else if len(expected) == 2 { 103 | delta, err := getFloat(expected[1]) 104 | 105 | if err != nil { 106 | return 0.0, 0.0, 0.0, "The delta value " + err.Error() 107 | } 108 | 109 | deltaFloat = delta 110 | } else if len(expected) > 2 { 111 | return 0.0, 0.0, 0.0, "This assertion requires exactly one comparison value and an optional delta (you provided more values)" 112 | } 113 | 114 | actualFloat, err := getFloat(actual) 115 | if err != nil { 116 | return 0.0, 0.0, 0.0, "The actual value " + err.Error() 117 | } 118 | 119 | expectedFloat, err := getFloat(expected[0]) 120 | if err != nil { 121 | return 0.0, 0.0, 0.0, "The comparison value " + err.Error() 122 | } 123 | 124 | return actualFloat, expectedFloat, deltaFloat, "" 125 | } 126 | 127 | // returns the float value of any real number, or error if it is not a numerical type 128 | func getFloat(num interface{}) (float64, error) { 129 | numValue := reflect.ValueOf(num) 130 | numKind := numValue.Kind() 131 | 132 | if numKind == reflect.Int || 133 | numKind == reflect.Int8 || 134 | numKind == reflect.Int16 || 135 | numKind == reflect.Int32 || 136 | numKind == reflect.Int64 { 137 | return float64(numValue.Int()), nil 138 | } else if numKind == reflect.Uint || 139 | numKind == reflect.Uint8 || 140 | numKind == reflect.Uint16 || 141 | numKind == reflect.Uint32 || 142 | numKind == reflect.Uint64 { 143 | return float64(numValue.Uint()), nil 144 | } else if numKind == reflect.Float32 || 145 | numKind == reflect.Float64 { 146 | return numValue.Float(), nil 147 | } else { 148 | return 0.0, errors.New("must be a numerical type, but was: " + numKind.String()) 149 | } 150 | } 151 | 152 | // ShouldResemble receives exactly two parameters and does a deep equal check (see reflect.DeepEqual) 153 | func ShouldResemble(actual interface{}, expected ...interface{}) string { 154 | if message := need(1, expected); message != success { 155 | return message 156 | } 157 | 158 | if matchError := oglematchers.DeepEquals(expected[0]).Matches(actual); matchError != nil { 159 | return serializer.serializeDetailed(expected[0], actual, 160 | fmt.Sprintf(shouldHaveResembled, render.Render(expected[0]), render.Render(actual))) 161 | } 162 | 163 | return success 164 | } 165 | 166 | // ShouldNotResemble receives exactly two parameters and does an inverse deep equal check (see reflect.DeepEqual) 167 | func ShouldNotResemble(actual interface{}, expected ...interface{}) string { 168 | if message := need(1, expected); message != success { 169 | return message 170 | } else if ShouldResemble(actual, expected[0]) == success { 171 | return fmt.Sprintf(shouldNotHaveResembled, render.Render(actual), render.Render(expected[0])) 172 | } 173 | return success 174 | } 175 | 176 | // ShouldPointTo receives exactly two parameters and checks to see that they point to the same address. 177 | func ShouldPointTo(actual interface{}, expected ...interface{}) string { 178 | if message := need(1, expected); message != success { 179 | return message 180 | } 181 | return shouldPointTo(actual, expected[0]) 182 | 183 | } 184 | func shouldPointTo(actual, expected interface{}) string { 185 | actualValue := reflect.ValueOf(actual) 186 | expectedValue := reflect.ValueOf(expected) 187 | 188 | if ShouldNotBeNil(actual) != success { 189 | return fmt.Sprintf(shouldHaveBeenNonNilPointer, "first", "nil") 190 | } else if ShouldNotBeNil(expected) != success { 191 | return fmt.Sprintf(shouldHaveBeenNonNilPointer, "second", "nil") 192 | } else if actualValue.Kind() != reflect.Ptr { 193 | return fmt.Sprintf(shouldHaveBeenNonNilPointer, "first", "not") 194 | } else if expectedValue.Kind() != reflect.Ptr { 195 | return fmt.Sprintf(shouldHaveBeenNonNilPointer, "second", "not") 196 | } else if ShouldEqual(actualValue.Pointer(), expectedValue.Pointer()) != success { 197 | actualAddress := reflect.ValueOf(actual).Pointer() 198 | expectedAddress := reflect.ValueOf(expected).Pointer() 199 | return serializer.serialize(expectedAddress, actualAddress, fmt.Sprintf(shouldHavePointedTo, 200 | actual, actualAddress, 201 | expected, expectedAddress)) 202 | } 203 | return success 204 | } 205 | 206 | // ShouldNotPointTo receives exactly two parameters and checks to see that they point to different addresess. 207 | func ShouldNotPointTo(actual interface{}, expected ...interface{}) string { 208 | if message := need(1, expected); message != success { 209 | return message 210 | } 211 | compare := ShouldPointTo(actual, expected[0]) 212 | if strings.HasPrefix(compare, shouldBePointers) { 213 | return compare 214 | } else if compare == success { 215 | return fmt.Sprintf(shouldNotHavePointedTo, actual, expected[0], reflect.ValueOf(actual).Pointer()) 216 | } 217 | return success 218 | } 219 | 220 | // ShouldBeNil receives a single parameter and ensures that it is nil. 221 | func ShouldBeNil(actual interface{}, expected ...interface{}) string { 222 | if fail := need(0, expected); fail != success { 223 | return fail 224 | } else if actual == nil { 225 | return success 226 | } else if interfaceHasNilValue(actual) { 227 | return success 228 | } 229 | return fmt.Sprintf(shouldHaveBeenNil, actual) 230 | } 231 | func interfaceHasNilValue(actual interface{}) bool { 232 | value := reflect.ValueOf(actual) 233 | kind := value.Kind() 234 | nilable := kind == reflect.Slice || 235 | kind == reflect.Chan || 236 | kind == reflect.Func || 237 | kind == reflect.Ptr || 238 | kind == reflect.Map 239 | 240 | // Careful: reflect.Value.IsNil() will panic unless it's an interface, chan, map, func, slice, or ptr 241 | // Reference: http://golang.org/pkg/reflect/#Value.IsNil 242 | return nilable && value.IsNil() 243 | } 244 | 245 | // ShouldNotBeNil receives a single parameter and ensures that it is not nil. 246 | func ShouldNotBeNil(actual interface{}, expected ...interface{}) string { 247 | if fail := need(0, expected); fail != success { 248 | return fail 249 | } else if ShouldBeNil(actual) == success { 250 | return fmt.Sprintf(shouldNotHaveBeenNil, actual) 251 | } 252 | return success 253 | } 254 | 255 | // ShouldBeTrue receives a single parameter and ensures that it is true. 256 | func ShouldBeTrue(actual interface{}, expected ...interface{}) string { 257 | if fail := need(0, expected); fail != success { 258 | return fail 259 | } else if actual != true { 260 | return fmt.Sprintf(shouldHaveBeenTrue, actual) 261 | } 262 | return success 263 | } 264 | 265 | // ShouldBeFalse receives a single parameter and ensures that it is false. 266 | func ShouldBeFalse(actual interface{}, expected ...interface{}) string { 267 | if fail := need(0, expected); fail != success { 268 | return fail 269 | } else if actual != false { 270 | return fmt.Sprintf(shouldHaveBeenFalse, actual) 271 | } 272 | return success 273 | } 274 | 275 | // ShouldBeZeroValue receives a single parameter and ensures that it is 276 | // the Go equivalent of the default value, or "zero" value. 277 | func ShouldBeZeroValue(actual interface{}, expected ...interface{}) string { 278 | if fail := need(0, expected); fail != success { 279 | return fail 280 | } 281 | zeroVal := reflect.Zero(reflect.TypeOf(actual)).Interface() 282 | if !reflect.DeepEqual(zeroVal, actual) { 283 | return serializer.serialize(zeroVal, actual, fmt.Sprintf(shouldHaveBeenZeroValue, actual)) 284 | } 285 | return success 286 | } 287 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/filter.go: -------------------------------------------------------------------------------- 1 | package assertions 2 | 3 | import "fmt" 4 | 5 | const ( 6 | success = "" 7 | needExactValues = "This assertion requires exactly %d comparison values (you provided %d)." 8 | needNonEmptyCollection = "This assertion requires at least 1 comparison value (you provided 0)." 9 | needFewerValues = "This assertion allows %d or fewer comparison values (you provided %d)." 10 | ) 11 | 12 | func need(needed int, expected []interface{}) string { 13 | if len(expected) != needed { 14 | return fmt.Sprintf(needExactValues, needed, len(expected)) 15 | } 16 | return success 17 | } 18 | 19 | func atLeast(minimum int, expected []interface{}) string { 20 | if len(expected) < 1 { 21 | return needNonEmptyCollection 22 | } 23 | return success 24 | } 25 | 26 | func atMost(max int, expected []interface{}) string { 27 | if len(expected) > max { 28 | return fmt.Sprintf(needFewerValues, max, len(expected)) 29 | } 30 | return success 31 | } 32 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/internal/go-render/LICENSE: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015 The Chromium Authors. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of Google Inc. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/internal/go-render/render/render.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | package render 6 | 7 | import ( 8 | "bytes" 9 | "fmt" 10 | "reflect" 11 | "sort" 12 | "strconv" 13 | ) 14 | 15 | var builtinTypeMap = map[reflect.Kind]string{ 16 | reflect.Bool: "bool", 17 | reflect.Complex128: "complex128", 18 | reflect.Complex64: "complex64", 19 | reflect.Float32: "float32", 20 | reflect.Float64: "float64", 21 | reflect.Int16: "int16", 22 | reflect.Int32: "int32", 23 | reflect.Int64: "int64", 24 | reflect.Int8: "int8", 25 | reflect.Int: "int", 26 | reflect.String: "string", 27 | reflect.Uint16: "uint16", 28 | reflect.Uint32: "uint32", 29 | reflect.Uint64: "uint64", 30 | reflect.Uint8: "uint8", 31 | reflect.Uint: "uint", 32 | reflect.Uintptr: "uintptr", 33 | } 34 | 35 | var builtinTypeSet = map[string]struct{}{} 36 | 37 | func init() { 38 | for _, v := range builtinTypeMap { 39 | builtinTypeSet[v] = struct{}{} 40 | } 41 | } 42 | 43 | var typeOfString = reflect.TypeOf("") 44 | var typeOfInt = reflect.TypeOf(int(1)) 45 | var typeOfUint = reflect.TypeOf(uint(1)) 46 | var typeOfFloat = reflect.TypeOf(10.1) 47 | 48 | // Render converts a structure to a string representation. Unline the "%#v" 49 | // format string, this resolves pointer types' contents in structs, maps, and 50 | // slices/arrays and prints their field values. 51 | func Render(v interface{}) string { 52 | buf := bytes.Buffer{} 53 | s := (*traverseState)(nil) 54 | s.render(&buf, 0, reflect.ValueOf(v), false) 55 | return buf.String() 56 | } 57 | 58 | // renderPointer is called to render a pointer value. 59 | // 60 | // This is overridable so that the test suite can have deterministic pointer 61 | // values in its expectations. 62 | var renderPointer = func(buf *bytes.Buffer, p uintptr) { 63 | fmt.Fprintf(buf, "0x%016x", p) 64 | } 65 | 66 | // traverseState is used to note and avoid recursion as struct members are being 67 | // traversed. 68 | // 69 | // traverseState is allowed to be nil. Specifically, the root state is nil. 70 | type traverseState struct { 71 | parent *traverseState 72 | ptr uintptr 73 | } 74 | 75 | func (s *traverseState) forkFor(ptr uintptr) *traverseState { 76 | for cur := s; cur != nil; cur = cur.parent { 77 | if ptr == cur.ptr { 78 | return nil 79 | } 80 | } 81 | 82 | fs := &traverseState{ 83 | parent: s, 84 | ptr: ptr, 85 | } 86 | return fs 87 | } 88 | 89 | func (s *traverseState) render(buf *bytes.Buffer, ptrs int, v reflect.Value, implicit bool) { 90 | if v.Kind() == reflect.Invalid { 91 | buf.WriteString("nil") 92 | return 93 | } 94 | vt := v.Type() 95 | 96 | // If the type being rendered is a potentially recursive type (a type that 97 | // can contain itself as a member), we need to avoid recursion. 98 | // 99 | // If we've already seen this type before, mark that this is the case and 100 | // write a recursion placeholder instead of actually rendering it. 101 | // 102 | // If we haven't seen it before, fork our `seen` tracking so any higher-up 103 | // renderers will also render it at least once, then mark that we've seen it 104 | // to avoid recursing on lower layers. 105 | pe := uintptr(0) 106 | vk := vt.Kind() 107 | switch vk { 108 | case reflect.Ptr: 109 | // Since structs and arrays aren't pointers, they can't directly be 110 | // recursed, but they can contain pointers to themselves. Record their 111 | // pointer to avoid this. 112 | switch v.Elem().Kind() { 113 | case reflect.Struct, reflect.Array: 114 | pe = v.Pointer() 115 | } 116 | 117 | case reflect.Slice, reflect.Map: 118 | pe = v.Pointer() 119 | } 120 | if pe != 0 { 121 | s = s.forkFor(pe) 122 | if s == nil { 123 | buf.WriteString("") 128 | return 129 | } 130 | } 131 | 132 | isAnon := func(t reflect.Type) bool { 133 | if t.Name() != "" { 134 | if _, ok := builtinTypeSet[t.Name()]; !ok { 135 | return false 136 | } 137 | } 138 | return t.Kind() != reflect.Interface 139 | } 140 | 141 | switch vk { 142 | case reflect.Struct: 143 | if !implicit { 144 | writeType(buf, ptrs, vt) 145 | } 146 | structAnon := vt.Name() == "" 147 | buf.WriteRune('{') 148 | for i := 0; i < vt.NumField(); i++ { 149 | if i > 0 { 150 | buf.WriteString(", ") 151 | } 152 | anon := structAnon && isAnon(vt.Field(i).Type) 153 | 154 | if !anon { 155 | buf.WriteString(vt.Field(i).Name) 156 | buf.WriteRune(':') 157 | } 158 | 159 | s.render(buf, 0, v.Field(i), anon) 160 | } 161 | buf.WriteRune('}') 162 | 163 | case reflect.Slice: 164 | if v.IsNil() { 165 | if !implicit { 166 | writeType(buf, ptrs, vt) 167 | buf.WriteString("(nil)") 168 | } else { 169 | buf.WriteString("nil") 170 | } 171 | return 172 | } 173 | fallthrough 174 | 175 | case reflect.Array: 176 | if !implicit { 177 | writeType(buf, ptrs, vt) 178 | } 179 | anon := vt.Name() == "" && isAnon(vt.Elem()) 180 | buf.WriteString("{") 181 | for i := 0; i < v.Len(); i++ { 182 | if i > 0 { 183 | buf.WriteString(", ") 184 | } 185 | 186 | s.render(buf, 0, v.Index(i), anon) 187 | } 188 | buf.WriteRune('}') 189 | 190 | case reflect.Map: 191 | if !implicit { 192 | writeType(buf, ptrs, vt) 193 | } 194 | if v.IsNil() { 195 | buf.WriteString("(nil)") 196 | } else { 197 | buf.WriteString("{") 198 | 199 | mkeys := v.MapKeys() 200 | tryAndSortMapKeys(vt, mkeys) 201 | 202 | kt := vt.Key() 203 | keyAnon := typeOfString.ConvertibleTo(kt) || typeOfInt.ConvertibleTo(kt) || typeOfUint.ConvertibleTo(kt) || typeOfFloat.ConvertibleTo(kt) 204 | valAnon := vt.Name() == "" && isAnon(vt.Elem()) 205 | for i, mk := range mkeys { 206 | if i > 0 { 207 | buf.WriteString(", ") 208 | } 209 | 210 | s.render(buf, 0, mk, keyAnon) 211 | buf.WriteString(":") 212 | s.render(buf, 0, v.MapIndex(mk), valAnon) 213 | } 214 | buf.WriteRune('}') 215 | } 216 | 217 | case reflect.Ptr: 218 | ptrs++ 219 | fallthrough 220 | case reflect.Interface: 221 | if v.IsNil() { 222 | writeType(buf, ptrs, v.Type()) 223 | buf.WriteString("(nil)") 224 | } else { 225 | s.render(buf, ptrs, v.Elem(), false) 226 | } 227 | 228 | case reflect.Chan, reflect.Func, reflect.UnsafePointer: 229 | writeType(buf, ptrs, vt) 230 | buf.WriteRune('(') 231 | renderPointer(buf, v.Pointer()) 232 | buf.WriteRune(')') 233 | 234 | default: 235 | tstr := vt.String() 236 | implicit = implicit || (ptrs == 0 && builtinTypeMap[vk] == tstr) 237 | if !implicit { 238 | writeType(buf, ptrs, vt) 239 | buf.WriteRune('(') 240 | } 241 | 242 | switch vk { 243 | case reflect.String: 244 | fmt.Fprintf(buf, "%q", v.String()) 245 | case reflect.Bool: 246 | fmt.Fprintf(buf, "%v", v.Bool()) 247 | 248 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: 249 | fmt.Fprintf(buf, "%d", v.Int()) 250 | 251 | case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: 252 | fmt.Fprintf(buf, "%d", v.Uint()) 253 | 254 | case reflect.Float32, reflect.Float64: 255 | fmt.Fprintf(buf, "%g", v.Float()) 256 | 257 | case reflect.Complex64, reflect.Complex128: 258 | fmt.Fprintf(buf, "%g", v.Complex()) 259 | } 260 | 261 | if !implicit { 262 | buf.WriteRune(')') 263 | } 264 | } 265 | } 266 | 267 | func writeType(buf *bytes.Buffer, ptrs int, t reflect.Type) { 268 | parens := ptrs > 0 269 | switch t.Kind() { 270 | case reflect.Chan, reflect.Func, reflect.UnsafePointer: 271 | parens = true 272 | } 273 | 274 | if parens { 275 | buf.WriteRune('(') 276 | for i := 0; i < ptrs; i++ { 277 | buf.WriteRune('*') 278 | } 279 | } 280 | 281 | switch t.Kind() { 282 | case reflect.Ptr: 283 | if ptrs == 0 { 284 | // This pointer was referenced from within writeType (e.g., as part of 285 | // rendering a list), and so hasn't had its pointer asterisk accounted 286 | // for. 287 | buf.WriteRune('*') 288 | } 289 | writeType(buf, 0, t.Elem()) 290 | 291 | case reflect.Interface: 292 | if n := t.Name(); n != "" { 293 | buf.WriteString(t.String()) 294 | } else { 295 | buf.WriteString("interface{}") 296 | } 297 | 298 | case reflect.Array: 299 | buf.WriteRune('[') 300 | buf.WriteString(strconv.FormatInt(int64(t.Len()), 10)) 301 | buf.WriteRune(']') 302 | writeType(buf, 0, t.Elem()) 303 | 304 | case reflect.Slice: 305 | if t == reflect.SliceOf(t.Elem()) { 306 | buf.WriteString("[]") 307 | writeType(buf, 0, t.Elem()) 308 | } else { 309 | // Custom slice type, use type name. 310 | buf.WriteString(t.String()) 311 | } 312 | 313 | case reflect.Map: 314 | if t == reflect.MapOf(t.Key(), t.Elem()) { 315 | buf.WriteString("map[") 316 | writeType(buf, 0, t.Key()) 317 | buf.WriteRune(']') 318 | writeType(buf, 0, t.Elem()) 319 | } else { 320 | // Custom map type, use type name. 321 | buf.WriteString(t.String()) 322 | } 323 | 324 | default: 325 | buf.WriteString(t.String()) 326 | } 327 | 328 | if parens { 329 | buf.WriteRune(')') 330 | } 331 | } 332 | 333 | type cmpFn func(a, b reflect.Value) int 334 | 335 | type sortableValueSlice struct { 336 | cmp cmpFn 337 | elements []reflect.Value 338 | } 339 | 340 | func (s sortableValueSlice) Len() int { 341 | return len(s.elements) 342 | } 343 | 344 | func (s sortableValueSlice) Less(i, j int) bool { 345 | return s.cmp(s.elements[i], s.elements[j]) < 0 346 | } 347 | 348 | func (s sortableValueSlice) Swap(i, j int) { 349 | s.elements[i], s.elements[j] = s.elements[j], s.elements[i] 350 | } 351 | 352 | // cmpForType returns a cmpFn which sorts the data for some type t in the same 353 | // order that a go-native map key is compared for equality. 354 | func cmpForType(t reflect.Type) cmpFn { 355 | switch t.Kind() { 356 | case reflect.String: 357 | return func(av, bv reflect.Value) int { 358 | a, b := av.String(), bv.String() 359 | if a < b { 360 | return -1 361 | } else if a > b { 362 | return 1 363 | } 364 | return 0 365 | } 366 | 367 | case reflect.Bool: 368 | return func(av, bv reflect.Value) int { 369 | a, b := av.Bool(), bv.Bool() 370 | if !a && b { 371 | return -1 372 | } else if a && !b { 373 | return 1 374 | } 375 | return 0 376 | } 377 | 378 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: 379 | return func(av, bv reflect.Value) int { 380 | a, b := av.Int(), bv.Int() 381 | if a < b { 382 | return -1 383 | } else if a > b { 384 | return 1 385 | } 386 | return 0 387 | } 388 | 389 | case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, 390 | reflect.Uint64, reflect.Uintptr, reflect.UnsafePointer: 391 | return func(av, bv reflect.Value) int { 392 | a, b := av.Uint(), bv.Uint() 393 | if a < b { 394 | return -1 395 | } else if a > b { 396 | return 1 397 | } 398 | return 0 399 | } 400 | 401 | case reflect.Float32, reflect.Float64: 402 | return func(av, bv reflect.Value) int { 403 | a, b := av.Float(), bv.Float() 404 | if a < b { 405 | return -1 406 | } else if a > b { 407 | return 1 408 | } 409 | return 0 410 | } 411 | 412 | case reflect.Interface: 413 | return func(av, bv reflect.Value) int { 414 | a, b := av.InterfaceData(), bv.InterfaceData() 415 | if a[0] < b[0] { 416 | return -1 417 | } else if a[0] > b[0] { 418 | return 1 419 | } 420 | if a[1] < b[1] { 421 | return -1 422 | } else if a[1] > b[1] { 423 | return 1 424 | } 425 | return 0 426 | } 427 | 428 | case reflect.Complex64, reflect.Complex128: 429 | return func(av, bv reflect.Value) int { 430 | a, b := av.Complex(), bv.Complex() 431 | if real(a) < real(b) { 432 | return -1 433 | } else if real(a) > real(b) { 434 | return 1 435 | } 436 | if imag(a) < imag(b) { 437 | return -1 438 | } else if imag(a) > imag(b) { 439 | return 1 440 | } 441 | return 0 442 | } 443 | 444 | case reflect.Ptr, reflect.Chan: 445 | return func(av, bv reflect.Value) int { 446 | a, b := av.Pointer(), bv.Pointer() 447 | if a < b { 448 | return -1 449 | } else if a > b { 450 | return 1 451 | } 452 | return 0 453 | } 454 | 455 | case reflect.Struct: 456 | cmpLst := make([]cmpFn, t.NumField()) 457 | for i := range cmpLst { 458 | cmpLst[i] = cmpForType(t.Field(i).Type) 459 | } 460 | return func(a, b reflect.Value) int { 461 | for i, cmp := range cmpLst { 462 | if rslt := cmp(a.Field(i), b.Field(i)); rslt != 0 { 463 | return rslt 464 | } 465 | } 466 | return 0 467 | } 468 | } 469 | 470 | return nil 471 | } 472 | 473 | func tryAndSortMapKeys(mt reflect.Type, k []reflect.Value) { 474 | if cmp := cmpForType(mt.Key()); cmp != nil { 475 | sort.Sort(sortableValueSlice{cmp, k}) 476 | } 477 | } 478 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/internal/oglematchers/.gitignore: -------------------------------------------------------------------------------- 1 | *.6 2 | 6.out 3 | _obj/ 4 | _test/ 5 | _testmain.go 6 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/internal/oglematchers/.travis.yml: -------------------------------------------------------------------------------- 1 | # Cf. http://docs.travis-ci.com/user/getting-started/ 2 | # Cf. http://docs.travis-ci.com/user/languages/go/ 3 | 4 | language: go 5 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/internal/oglematchers/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/internal/oglematchers/README.md: -------------------------------------------------------------------------------- 1 | [![GoDoc](https://godoc.org/github.com/smartystreets/assertions/internal/oglematchers?status.svg)](https://godoc.org/github.com/smartystreets/assertions/internal/oglematchers) 2 | 3 | `oglematchers` is a package for the Go programming language containing a set of 4 | matchers, useful in a testing or mocking framework, inspired by and mostly 5 | compatible with [Google Test][googletest] for C++ and 6 | [Google JS Test][google-js-test]. The package is used by the 7 | [ogletest][ogletest] testing framework and [oglemock][oglemock] mocking 8 | framework, which may be more directly useful to you, but can be generically used 9 | elsewhere as well. 10 | 11 | A "matcher" is simply an object with a `Matches` method defining a set of golang 12 | values matched by the matcher, and a `Description` method describing that set. 13 | For example, here are some matchers: 14 | 15 | ```go 16 | // Numbers 17 | Equals(17.13) 18 | LessThan(19) 19 | 20 | // Strings 21 | Equals("taco") 22 | HasSubstr("burrito") 23 | MatchesRegex("t.*o") 24 | 25 | // Combining matchers 26 | AnyOf(LessThan(17), GreaterThan(19)) 27 | ``` 28 | 29 | There are lots more; see [here][reference] for a reference. You can also add 30 | your own simply by implementing the `oglematchers.Matcher` interface. 31 | 32 | 33 | Installation 34 | ------------ 35 | 36 | First, make sure you have installed Go 1.0.2 or newer. See 37 | [here][golang-install] for instructions. 38 | 39 | Use the following command to install `oglematchers` and keep it up to date: 40 | 41 | go get -u github.com/smartystreets/assertions/internal/oglematchers 42 | 43 | 44 | Documentation 45 | ------------- 46 | 47 | See [here][reference] for documentation. Alternatively, you can install the 48 | package and then use `godoc`: 49 | 50 | godoc github.com/smartystreets/assertions/internal/oglematchers 51 | 52 | 53 | [reference]: http://godoc.org/github.com/smartystreets/assertions/internal/oglematchers 54 | [golang-install]: http://golang.org/doc/install.html 55 | [googletest]: http://code.google.com/p/googletest/ 56 | [google-js-test]: http://code.google.com/p/google-js-test/ 57 | [ogletest]: http://github.com/smartystreets/assertions/internal/ogletest 58 | [oglemock]: http://github.com/smartystreets/assertions/internal/oglemock 59 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/internal/oglematchers/any_of.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Aaron Jacobs. All Rights Reserved. 2 | // Author: aaronjjacobs@gmail.com (Aaron Jacobs) 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package oglematchers 17 | 18 | import ( 19 | "errors" 20 | "fmt" 21 | "reflect" 22 | "strings" 23 | ) 24 | 25 | // AnyOf accepts a set of values S and returns a matcher that follows the 26 | // algorithm below when considering a candidate c: 27 | // 28 | // 1. If there exists a value m in S such that m implements the Matcher 29 | // interface and m matches c, return true. 30 | // 31 | // 2. Otherwise, if there exists a value v in S such that v does not implement 32 | // the Matcher interface and the matcher Equals(v) matches c, return true. 33 | // 34 | // 3. Otherwise, if there is a value m in S such that m implements the Matcher 35 | // interface and m returns a fatal error for c, return that fatal error. 36 | // 37 | // 4. Otherwise, return false. 38 | // 39 | // This is akin to a logical OR operation for matchers, with non-matchers x 40 | // being treated as Equals(x). 41 | func AnyOf(vals ...interface{}) Matcher { 42 | // Get ahold of a type variable for the Matcher interface. 43 | var dummy *Matcher 44 | matcherType := reflect.TypeOf(dummy).Elem() 45 | 46 | // Create a matcher for each value, or use the value itself if it's already a 47 | // matcher. 48 | wrapped := make([]Matcher, len(vals)) 49 | for i, v := range vals { 50 | t := reflect.TypeOf(v) 51 | if t != nil && t.Implements(matcherType) { 52 | wrapped[i] = v.(Matcher) 53 | } else { 54 | wrapped[i] = Equals(v) 55 | } 56 | } 57 | 58 | return &anyOfMatcher{wrapped} 59 | } 60 | 61 | type anyOfMatcher struct { 62 | wrapped []Matcher 63 | } 64 | 65 | func (m *anyOfMatcher) Description() string { 66 | wrappedDescs := make([]string, len(m.wrapped)) 67 | for i, matcher := range m.wrapped { 68 | wrappedDescs[i] = matcher.Description() 69 | } 70 | 71 | return fmt.Sprintf("or(%s)", strings.Join(wrappedDescs, ", ")) 72 | } 73 | 74 | func (m *anyOfMatcher) Matches(c interface{}) (err error) { 75 | err = errors.New("") 76 | 77 | // Try each matcher in turn. 78 | for _, matcher := range m.wrapped { 79 | wrappedErr := matcher.Matches(c) 80 | 81 | // Return immediately if there's a match. 82 | if wrappedErr == nil { 83 | err = nil 84 | return 85 | } 86 | 87 | // Note the fatal error, if any. 88 | if _, isFatal := wrappedErr.(*FatalError); isFatal { 89 | err = wrappedErr 90 | } 91 | } 92 | 93 | return 94 | } 95 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/internal/oglematchers/contains.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Aaron Jacobs. All Rights Reserved. 2 | // Author: aaronjjacobs@gmail.com (Aaron Jacobs) 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package oglematchers 17 | 18 | import ( 19 | "fmt" 20 | "reflect" 21 | ) 22 | 23 | // Return a matcher that matches arrays slices with at least one element that 24 | // matches the supplied argument. If the argument x is not itself a Matcher, 25 | // this is equivalent to Contains(Equals(x)). 26 | func Contains(x interface{}) Matcher { 27 | var result containsMatcher 28 | var ok bool 29 | 30 | if result.elementMatcher, ok = x.(Matcher); !ok { 31 | result.elementMatcher = DeepEquals(x) 32 | } 33 | 34 | return &result 35 | } 36 | 37 | type containsMatcher struct { 38 | elementMatcher Matcher 39 | } 40 | 41 | func (m *containsMatcher) Description() string { 42 | return fmt.Sprintf("contains: %s", m.elementMatcher.Description()) 43 | } 44 | 45 | func (m *containsMatcher) Matches(candidate interface{}) error { 46 | // The candidate must be a slice or an array. 47 | v := reflect.ValueOf(candidate) 48 | if v.Kind() != reflect.Slice && v.Kind() != reflect.Array { 49 | return NewFatalError("which is not a slice or array") 50 | } 51 | 52 | // Check each element. 53 | for i := 0; i < v.Len(); i++ { 54 | elem := v.Index(i) 55 | if matchErr := m.elementMatcher.Matches(elem.Interface()); matchErr == nil { 56 | return nil 57 | } 58 | } 59 | 60 | return fmt.Errorf("") 61 | } 62 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/internal/oglematchers/deep_equals.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Aaron Jacobs. All Rights Reserved. 2 | // Author: aaronjjacobs@gmail.com (Aaron Jacobs) 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package oglematchers 17 | 18 | import ( 19 | "bytes" 20 | "errors" 21 | "fmt" 22 | "reflect" 23 | ) 24 | 25 | var byteSliceType reflect.Type = reflect.TypeOf([]byte{}) 26 | 27 | // DeepEquals returns a matcher that matches based on 'deep equality', as 28 | // defined by the reflect package. This matcher requires that values have 29 | // identical types to x. 30 | func DeepEquals(x interface{}) Matcher { 31 | return &deepEqualsMatcher{x} 32 | } 33 | 34 | type deepEqualsMatcher struct { 35 | x interface{} 36 | } 37 | 38 | func (m *deepEqualsMatcher) Description() string { 39 | xDesc := fmt.Sprintf("%v", m.x) 40 | xValue := reflect.ValueOf(m.x) 41 | 42 | // Special case: fmt.Sprintf presents nil slices as "[]", but 43 | // reflect.DeepEqual makes a distinction between nil and empty slices. Make 44 | // this less confusing. 45 | if xValue.Kind() == reflect.Slice && xValue.IsNil() { 46 | xDesc = "" 47 | } 48 | 49 | return fmt.Sprintf("deep equals: %s", xDesc) 50 | } 51 | 52 | func (m *deepEqualsMatcher) Matches(c interface{}) error { 53 | // Make sure the types match. 54 | ct := reflect.TypeOf(c) 55 | xt := reflect.TypeOf(m.x) 56 | 57 | if ct != xt { 58 | return NewFatalError(fmt.Sprintf("which is of type %v", ct)) 59 | } 60 | 61 | // Special case: handle byte slices more efficiently. 62 | cValue := reflect.ValueOf(c) 63 | xValue := reflect.ValueOf(m.x) 64 | 65 | if ct == byteSliceType && !cValue.IsNil() && !xValue.IsNil() { 66 | xBytes := m.x.([]byte) 67 | cBytes := c.([]byte) 68 | 69 | if bytes.Equal(cBytes, xBytes) { 70 | return nil 71 | } 72 | 73 | return errors.New("") 74 | } 75 | 76 | // Defer to the reflect package. 77 | if reflect.DeepEqual(m.x, c) { 78 | return nil 79 | } 80 | 81 | // Special case: if the comparison failed because c is the nil slice, given 82 | // an indication of this (since its value is printed as "[]"). 83 | if cValue.Kind() == reflect.Slice && cValue.IsNil() { 84 | return errors.New("which is nil") 85 | } 86 | 87 | return errors.New("") 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/internal/oglematchers/greater_or_equal.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Aaron Jacobs. All Rights Reserved. 2 | // Author: aaronjjacobs@gmail.com (Aaron Jacobs) 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package oglematchers 17 | 18 | import ( 19 | "fmt" 20 | "reflect" 21 | ) 22 | 23 | // GreaterOrEqual returns a matcher that matches integer, floating point, or 24 | // strings values v such that v >= x. Comparison is not defined between numeric 25 | // and string types, but is defined between all integer and floating point 26 | // types. 27 | // 28 | // x must itself be an integer, floating point, or string type; otherwise, 29 | // GreaterOrEqual will panic. 30 | func GreaterOrEqual(x interface{}) Matcher { 31 | desc := fmt.Sprintf("greater than or equal to %v", x) 32 | 33 | // Special case: make it clear that strings are strings. 34 | if reflect.TypeOf(x).Kind() == reflect.String { 35 | desc = fmt.Sprintf("greater than or equal to \"%s\"", x) 36 | } 37 | 38 | return transformDescription(Not(LessThan(x)), desc) 39 | } 40 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/internal/oglematchers/greater_than.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Aaron Jacobs. All Rights Reserved. 2 | // Author: aaronjjacobs@gmail.com (Aaron Jacobs) 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package oglematchers 17 | 18 | import ( 19 | "fmt" 20 | "reflect" 21 | ) 22 | 23 | // GreaterThan returns a matcher that matches integer, floating point, or 24 | // strings values v such that v > x. Comparison is not defined between numeric 25 | // and string types, but is defined between all integer and floating point 26 | // types. 27 | // 28 | // x must itself be an integer, floating point, or string type; otherwise, 29 | // GreaterThan will panic. 30 | func GreaterThan(x interface{}) Matcher { 31 | desc := fmt.Sprintf("greater than %v", x) 32 | 33 | // Special case: make it clear that strings are strings. 34 | if reflect.TypeOf(x).Kind() == reflect.String { 35 | desc = fmt.Sprintf("greater than \"%s\"", x) 36 | } 37 | 38 | return transformDescription(Not(LessOrEqual(x)), desc) 39 | } 40 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/internal/oglematchers/less_or_equal.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Aaron Jacobs. All Rights Reserved. 2 | // Author: aaronjjacobs@gmail.com (Aaron Jacobs) 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package oglematchers 17 | 18 | import ( 19 | "fmt" 20 | "reflect" 21 | ) 22 | 23 | // LessOrEqual returns a matcher that matches integer, floating point, or 24 | // strings values v such that v <= x. Comparison is not defined between numeric 25 | // and string types, but is defined between all integer and floating point 26 | // types. 27 | // 28 | // x must itself be an integer, floating point, or string type; otherwise, 29 | // LessOrEqual will panic. 30 | func LessOrEqual(x interface{}) Matcher { 31 | desc := fmt.Sprintf("less than or equal to %v", x) 32 | 33 | // Special case: make it clear that strings are strings. 34 | if reflect.TypeOf(x).Kind() == reflect.String { 35 | desc = fmt.Sprintf("less than or equal to \"%s\"", x) 36 | } 37 | 38 | // Put LessThan last so that its error messages will be used in the event of 39 | // failure. 40 | return transformDescription(AnyOf(Equals(x), LessThan(x)), desc) 41 | } 42 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/internal/oglematchers/less_than.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Aaron Jacobs. All Rights Reserved. 2 | // Author: aaronjjacobs@gmail.com (Aaron Jacobs) 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package oglematchers 17 | 18 | import ( 19 | "errors" 20 | "fmt" 21 | "math" 22 | "reflect" 23 | ) 24 | 25 | // LessThan returns a matcher that matches integer, floating point, or strings 26 | // values v such that v < x. Comparison is not defined between numeric and 27 | // string types, but is defined between all integer and floating point types. 28 | // 29 | // x must itself be an integer, floating point, or string type; otherwise, 30 | // LessThan will panic. 31 | func LessThan(x interface{}) Matcher { 32 | v := reflect.ValueOf(x) 33 | kind := v.Kind() 34 | 35 | switch { 36 | case isInteger(v): 37 | case isFloat(v): 38 | case kind == reflect.String: 39 | 40 | default: 41 | panic(fmt.Sprintf("LessThan: unexpected kind %v", kind)) 42 | } 43 | 44 | return &lessThanMatcher{v} 45 | } 46 | 47 | type lessThanMatcher struct { 48 | limit reflect.Value 49 | } 50 | 51 | func (m *lessThanMatcher) Description() string { 52 | // Special case: make it clear that strings are strings. 53 | if m.limit.Kind() == reflect.String { 54 | return fmt.Sprintf("less than \"%s\"", m.limit.String()) 55 | } 56 | 57 | return fmt.Sprintf("less than %v", m.limit.Interface()) 58 | } 59 | 60 | func compareIntegers(v1, v2 reflect.Value) (err error) { 61 | err = errors.New("") 62 | 63 | switch { 64 | case isSignedInteger(v1) && isSignedInteger(v2): 65 | if v1.Int() < v2.Int() { 66 | err = nil 67 | } 68 | return 69 | 70 | case isSignedInteger(v1) && isUnsignedInteger(v2): 71 | if v1.Int() < 0 || uint64(v1.Int()) < v2.Uint() { 72 | err = nil 73 | } 74 | return 75 | 76 | case isUnsignedInteger(v1) && isSignedInteger(v2): 77 | if v1.Uint() <= math.MaxInt64 && int64(v1.Uint()) < v2.Int() { 78 | err = nil 79 | } 80 | return 81 | 82 | case isUnsignedInteger(v1) && isUnsignedInteger(v2): 83 | if v1.Uint() < v2.Uint() { 84 | err = nil 85 | } 86 | return 87 | } 88 | 89 | panic(fmt.Sprintf("compareIntegers: %v %v", v1, v2)) 90 | } 91 | 92 | func getFloat(v reflect.Value) float64 { 93 | switch { 94 | case isSignedInteger(v): 95 | return float64(v.Int()) 96 | 97 | case isUnsignedInteger(v): 98 | return float64(v.Uint()) 99 | 100 | case isFloat(v): 101 | return v.Float() 102 | } 103 | 104 | panic(fmt.Sprintf("getFloat: %v", v)) 105 | } 106 | 107 | func (m *lessThanMatcher) Matches(c interface{}) (err error) { 108 | v1 := reflect.ValueOf(c) 109 | v2 := m.limit 110 | 111 | err = errors.New("") 112 | 113 | // Handle strings as a special case. 114 | if v1.Kind() == reflect.String && v2.Kind() == reflect.String { 115 | if v1.String() < v2.String() { 116 | err = nil 117 | } 118 | return 119 | } 120 | 121 | // If we get here, we require that we are dealing with integers or floats. 122 | v1Legal := isInteger(v1) || isFloat(v1) 123 | v2Legal := isInteger(v2) || isFloat(v2) 124 | if !v1Legal || !v2Legal { 125 | err = NewFatalError("which is not comparable") 126 | return 127 | } 128 | 129 | // Handle the various comparison cases. 130 | switch { 131 | // Both integers 132 | case isInteger(v1) && isInteger(v2): 133 | return compareIntegers(v1, v2) 134 | 135 | // At least one float32 136 | case v1.Kind() == reflect.Float32 || v2.Kind() == reflect.Float32: 137 | if float32(getFloat(v1)) < float32(getFloat(v2)) { 138 | err = nil 139 | } 140 | return 141 | 142 | // At least one float64 143 | case v1.Kind() == reflect.Float64 || v2.Kind() == reflect.Float64: 144 | if getFloat(v1) < getFloat(v2) { 145 | err = nil 146 | } 147 | return 148 | } 149 | 150 | // We shouldn't get here. 151 | panic(fmt.Sprintf("lessThanMatcher.Matches: Shouldn't get here: %v %v", v1, v2)) 152 | } 153 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/internal/oglematchers/matcher.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Aaron Jacobs. All Rights Reserved. 2 | // Author: aaronjjacobs@gmail.com (Aaron Jacobs) 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | // Package oglematchers provides a set of matchers useful in a testing or 17 | // mocking framework. These matchers are inspired by and mostly compatible with 18 | // Google Test for C++ and Google JS Test. 19 | // 20 | // This package is used by github.com/smartystreets/assertions/internal/ogletest and 21 | // github.com/smartystreets/assertions/internal/oglemock, which may be more directly useful if you're not 22 | // writing your own testing package or defining your own matchers. 23 | package oglematchers 24 | 25 | // A Matcher is some predicate implicitly defining a set of values that it 26 | // matches. For example, GreaterThan(17) matches all numeric values greater 27 | // than 17, and HasSubstr("taco") matches all strings with the substring 28 | // "taco". 29 | // 30 | // Matchers are typically exposed to tests via constructor functions like 31 | // HasSubstr. In order to implement such a function you can either define your 32 | // own matcher type or use NewMatcher. 33 | type Matcher interface { 34 | // Check whether the supplied value belongs to the the set defined by the 35 | // matcher. Return a non-nil error if and only if it does not. 36 | // 37 | // The error describes why the value doesn't match. The error text is a 38 | // relative clause that is suitable for being placed after the value. For 39 | // example, a predicate that matches strings with a particular substring may, 40 | // when presented with a numerical value, return the following error text: 41 | // 42 | // "which is not a string" 43 | // 44 | // Then the failure message may look like: 45 | // 46 | // Expected: has substring "taco" 47 | // Actual: 17, which is not a string 48 | // 49 | // If the error is self-apparent based on the description of the matcher, the 50 | // error text may be empty (but the error still non-nil). For example: 51 | // 52 | // Expected: 17 53 | // Actual: 19 54 | // 55 | // If you are implementing a new matcher, see also the documentation on 56 | // FatalError. 57 | Matches(candidate interface{}) error 58 | 59 | // Description returns a string describing the property that values matching 60 | // this matcher have, as a verb phrase where the subject is the value. For 61 | // example, "is greather than 17" or "has substring "taco"". 62 | Description() string 63 | } 64 | 65 | // FatalError is an implementation of the error interface that may be returned 66 | // from matchers, indicating the error should be propagated. Returning a 67 | // *FatalError indicates that the matcher doesn't process values of the 68 | // supplied type, or otherwise doesn't know how to handle the value. 69 | // 70 | // For example, if GreaterThan(17) returned false for the value "taco" without 71 | // a fatal error, then Not(GreaterThan(17)) would return true. This is 72 | // technically correct, but is surprising and may mask failures where the wrong 73 | // sort of matcher is accidentally used. Instead, GreaterThan(17) can return a 74 | // fatal error, which will be propagated by Not(). 75 | type FatalError struct { 76 | errorText string 77 | } 78 | 79 | // NewFatalError creates a FatalError struct with the supplied error text. 80 | func NewFatalError(s string) *FatalError { 81 | return &FatalError{s} 82 | } 83 | 84 | func (e *FatalError) Error() string { 85 | return e.errorText 86 | } 87 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/internal/oglematchers/not.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Aaron Jacobs. All Rights Reserved. 2 | // Author: aaronjjacobs@gmail.com (Aaron Jacobs) 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package oglematchers 17 | 18 | import ( 19 | "errors" 20 | "fmt" 21 | ) 22 | 23 | // Not returns a matcher that inverts the set of values matched by the wrapped 24 | // matcher. It does not transform the result for values for which the wrapped 25 | // matcher returns a fatal error. 26 | func Not(m Matcher) Matcher { 27 | return ¬Matcher{m} 28 | } 29 | 30 | type notMatcher struct { 31 | wrapped Matcher 32 | } 33 | 34 | func (m *notMatcher) Matches(c interface{}) (err error) { 35 | err = m.wrapped.Matches(c) 36 | 37 | // Did the wrapped matcher say yes? 38 | if err == nil { 39 | return errors.New("") 40 | } 41 | 42 | // Did the wrapped matcher return a fatal error? 43 | if _, isFatal := err.(*FatalError); isFatal { 44 | return err 45 | } 46 | 47 | // The wrapped matcher returned a non-fatal error. 48 | return nil 49 | } 50 | 51 | func (m *notMatcher) Description() string { 52 | return fmt.Sprintf("not(%s)", m.wrapped.Description()) 53 | } 54 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/internal/oglematchers/transform_description.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Aaron Jacobs. All Rights Reserved. 2 | // Author: aaronjjacobs@gmail.com (Aaron Jacobs) 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package oglematchers 17 | 18 | // transformDescription returns a matcher that is equivalent to the supplied 19 | // one, except that it has the supplied description instead of the one attached 20 | // to the existing matcher. 21 | func transformDescription(m Matcher, newDesc string) Matcher { 22 | return &transformDescriptionMatcher{newDesc, m} 23 | } 24 | 25 | type transformDescriptionMatcher struct { 26 | desc string 27 | wrappedMatcher Matcher 28 | } 29 | 30 | func (m *transformDescriptionMatcher) Description() string { 31 | return m.desc 32 | } 33 | 34 | func (m *transformDescriptionMatcher) Matches(c interface{}) error { 35 | return m.wrappedMatcher.Matches(c) 36 | } 37 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/messages.go: -------------------------------------------------------------------------------- 1 | package assertions 2 | 3 | const ( // equality 4 | shouldHaveBeenEqual = "Expected: '%v'\nActual: '%v'\n(Should be equal)" 5 | shouldNotHaveBeenEqual = "Expected '%v'\nto NOT equal '%v'\n(but it did)!" 6 | shouldHaveBeenEqualTypeMismatch = "Expected: '%v' (%T)\nActual: '%v' (%T)\n(Should be equal, type mismatch)" 7 | shouldHaveBeenAlmostEqual = "Expected '%v' to almost equal '%v' (but it didn't)!" 8 | shouldHaveNotBeenAlmostEqual = "Expected '%v' to NOT almost equal '%v' (but it did)!" 9 | shouldHaveResembled = "Expected: '%s'\nActual: '%s'\n(Should resemble)!" 10 | shouldNotHaveResembled = "Expected '%#v'\nto NOT resemble '%#v'\n(but it did)!" 11 | shouldBePointers = "Both arguments should be pointers " 12 | shouldHaveBeenNonNilPointer = shouldBePointers + "(the %s was %s)!" 13 | shouldHavePointedTo = "Expected '%+v' (address: '%v') and '%+v' (address: '%v') to be the same address (but their weren't)!" 14 | shouldNotHavePointedTo = "Expected '%+v' and '%+v' to be different references (but they matched: '%v')!" 15 | shouldHaveBeenNil = "Expected: nil\nActual: '%v'" 16 | shouldNotHaveBeenNil = "Expected '%+v' to NOT be nil (but it was)!" 17 | shouldHaveBeenTrue = "Expected: true\nActual: %v" 18 | shouldHaveBeenFalse = "Expected: false\nActual: %v" 19 | shouldHaveBeenZeroValue = "'%+v' should have been the zero value" //"Expected: (zero value)\nActual: %v" 20 | ) 21 | 22 | const ( // quantity comparisons 23 | shouldHaveBeenGreater = "Expected '%v' to be greater than '%v' (but it wasn't)!" 24 | shouldHaveBeenGreaterOrEqual = "Expected '%v' to be greater than or equal to '%v' (but it wasn't)!" 25 | shouldHaveBeenLess = "Expected '%v' to be less than '%v' (but it wasn't)!" 26 | shouldHaveBeenLessOrEqual = "Expected '%v' to be less than or equal to '%v' (but it wasn't)!" 27 | shouldHaveBeenBetween = "Expected '%v' to be between '%v' and '%v' (but it wasn't)!" 28 | shouldNotHaveBeenBetween = "Expected '%v' NOT to be between '%v' and '%v' (but it was)!" 29 | shouldHaveDifferentUpperAndLower = "The lower and upper bounds must be different values (they were both '%v')." 30 | shouldHaveBeenBetweenOrEqual = "Expected '%v' to be between '%v' and '%v' or equal to one of them (but it wasn't)!" 31 | shouldNotHaveBeenBetweenOrEqual = "Expected '%v' NOT to be between '%v' and '%v' or equal to one of them (but it was)!" 32 | ) 33 | 34 | const ( // collections 35 | shouldHaveContained = "Expected the container (%v) to contain: '%v' (but it didn't)!" 36 | shouldNotHaveContained = "Expected the container (%v) NOT to contain: '%v' (but it did)!" 37 | shouldHaveContainedKey = "Expected the %v to contain the key: %v (but it didn't)!" 38 | shouldNotHaveContainedKey = "Expected the %v NOT to contain the key: %v (but it did)!" 39 | shouldHaveBeenIn = "Expected '%v' to be in the container (%v), but it wasn't!" 40 | shouldNotHaveBeenIn = "Expected '%v' NOT to be in the container (%v), but it was!" 41 | shouldHaveBeenAValidCollection = "You must provide a valid container (was %v)!" 42 | shouldHaveBeenAValidMap = "You must provide a valid map type (was %v)!" 43 | shouldHaveBeenEmpty = "Expected %+v to be empty (but it wasn't)!" 44 | shouldNotHaveBeenEmpty = "Expected %+v to NOT be empty (but it was)!" 45 | shouldHaveBeenAValidInteger = "You must provide a valid integer (was %v)!" 46 | shouldHaveBeenAValidLength = "You must provide a valid positive integer (was %v)!" 47 | shouldHaveHadLength = "Expected %+v (length: %v) to have length equal to '%v', but it wasn't!" 48 | ) 49 | 50 | const ( // strings 51 | shouldHaveStartedWith = "Expected '%v'\nto start with '%v'\n(but it didn't)!" 52 | shouldNotHaveStartedWith = "Expected '%v'\nNOT to start with '%v'\n(but it did)!" 53 | shouldHaveEndedWith = "Expected '%v'\nto end with '%v'\n(but it didn't)!" 54 | shouldNotHaveEndedWith = "Expected '%v'\nNOT to end with '%v'\n(but it did)!" 55 | shouldAllBeStrings = "All arguments to this assertion must be strings (you provided: %v)." 56 | shouldBothBeStrings = "Both arguments to this assertion must be strings (you provided %v and %v)." 57 | shouldBeString = "The argument to this assertion must be a string (you provided %v)." 58 | shouldHaveContainedSubstring = "Expected '%s' to contain substring '%s' (but it didn't)!" 59 | shouldNotHaveContainedSubstring = "Expected '%s' NOT to contain substring '%s' (but it did)!" 60 | shouldHaveBeenBlank = "Expected '%s' to be blank (but it wasn't)!" 61 | shouldNotHaveBeenBlank = "Expected value to NOT be blank (but it was)!" 62 | ) 63 | 64 | const ( // panics 65 | shouldUseVoidNiladicFunction = "You must provide a void, niladic function as the first argument!" 66 | shouldHavePanickedWith = "Expected func() to panic with '%v' (but it panicked with '%v')!" 67 | shouldHavePanicked = "Expected func() to panic (but it didn't)!" 68 | shouldNotHavePanicked = "Expected func() NOT to panic (error: '%+v')!" 69 | shouldNotHavePanickedWith = "Expected func() NOT to panic with '%v' (but it did)!" 70 | ) 71 | 72 | const ( // type checking 73 | shouldHaveBeenA = "Expected '%v' to be: '%v' (but was: '%v')!" 74 | shouldNotHaveBeenA = "Expected '%v' to NOT be: '%v' (but it was)!" 75 | 76 | shouldHaveImplemented = "Expected: '%v interface support'\nActual: '%v' does not implement the interface!" 77 | shouldNotHaveImplemented = "Expected '%v'\nto NOT implement '%v'\n(but it did)!" 78 | shouldCompareWithInterfacePointer = "The expected value must be a pointer to an interface type (eg. *fmt.Stringer)" 79 | shouldNotBeNilActual = "The actual value was 'nil' and should be a value or a pointer to a value!" 80 | 81 | shouldBeError = "Expected an error value (but was '%v' instead)!" 82 | shouldBeErrorInvalidComparisonValue = "The final argument to this assertion must be a string or an error value (you provided: '%v')." 83 | ) 84 | 85 | const ( // time comparisons 86 | shouldUseTimes = "You must provide time instances as arguments to this assertion." 87 | shouldUseTimeSlice = "You must provide a slice of time instances as the first argument to this assertion." 88 | shouldUseDurationAndTime = "You must provide a duration and a time as arguments to this assertion." 89 | shouldHaveHappenedBefore = "Expected '%v' to happen before '%v' (it happened '%v' after)!" 90 | shouldHaveHappenedAfter = "Expected '%v' to happen after '%v' (it happened '%v' before)!" 91 | shouldHaveHappenedBetween = "Expected '%v' to happen between '%v' and '%v' (it happened '%v' outside threshold)!" 92 | shouldNotHaveHappenedOnOrBetween = "Expected '%v' to NOT happen on or between '%v' and '%v' (but it did)!" 93 | 94 | // format params: incorrect-index, previous-index, previous-time, incorrect-index, incorrect-time 95 | shouldHaveBeenChronological = "The 'Time' at index [%d] should have happened after the previous one (but it didn't!):\n [%d]: %s\n [%d]: %s (see, it happened before!)" 96 | ) 97 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/panic.go: -------------------------------------------------------------------------------- 1 | package assertions 2 | 3 | import "fmt" 4 | 5 | // ShouldPanic receives a void, niladic function and expects to recover a panic. 6 | func ShouldPanic(actual interface{}, expected ...interface{}) (message string) { 7 | if fail := need(0, expected); fail != success { 8 | return fail 9 | } 10 | 11 | action, _ := actual.(func()) 12 | 13 | if action == nil { 14 | message = shouldUseVoidNiladicFunction 15 | return 16 | } 17 | 18 | defer func() { 19 | recovered := recover() 20 | if recovered == nil { 21 | message = shouldHavePanicked 22 | } else { 23 | message = success 24 | } 25 | }() 26 | action() 27 | 28 | return 29 | } 30 | 31 | // ShouldNotPanic receives a void, niladic function and expects to execute the function without any panic. 32 | func ShouldNotPanic(actual interface{}, expected ...interface{}) (message string) { 33 | if fail := need(0, expected); fail != success { 34 | return fail 35 | } 36 | 37 | action, _ := actual.(func()) 38 | 39 | if action == nil { 40 | message = shouldUseVoidNiladicFunction 41 | return 42 | } 43 | 44 | defer func() { 45 | recovered := recover() 46 | if recovered != nil { 47 | message = fmt.Sprintf(shouldNotHavePanicked, recovered) 48 | } else { 49 | message = success 50 | } 51 | }() 52 | action() 53 | 54 | return 55 | } 56 | 57 | // ShouldPanicWith receives a void, niladic function and expects to recover a panic with the second argument as the content. 58 | func ShouldPanicWith(actual interface{}, expected ...interface{}) (message string) { 59 | if fail := need(1, expected); fail != success { 60 | return fail 61 | } 62 | 63 | action, _ := actual.(func()) 64 | 65 | if action == nil { 66 | message = shouldUseVoidNiladicFunction 67 | return 68 | } 69 | 70 | defer func() { 71 | recovered := recover() 72 | if recovered == nil { 73 | message = shouldHavePanicked 74 | } else { 75 | if equal := ShouldEqual(recovered, expected[0]); equal != success { 76 | message = serializer.serialize(expected[0], recovered, fmt.Sprintf(shouldHavePanickedWith, expected[0], recovered)) 77 | } else { 78 | message = success 79 | } 80 | } 81 | }() 82 | action() 83 | 84 | return 85 | } 86 | 87 | // ShouldNotPanicWith receives a void, niladic function and expects to recover a panic whose content differs from the second argument. 88 | func ShouldNotPanicWith(actual interface{}, expected ...interface{}) (message string) { 89 | if fail := need(1, expected); fail != success { 90 | return fail 91 | } 92 | 93 | action, _ := actual.(func()) 94 | 95 | if action == nil { 96 | message = shouldUseVoidNiladicFunction 97 | return 98 | } 99 | 100 | defer func() { 101 | recovered := recover() 102 | if recovered == nil { 103 | message = success 104 | } else { 105 | if equal := ShouldEqual(recovered, expected[0]); equal == success { 106 | message = fmt.Sprintf(shouldNotHavePanickedWith, expected[0]) 107 | } else { 108 | message = success 109 | } 110 | } 111 | }() 112 | action() 113 | 114 | return 115 | } 116 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/quantity.go: -------------------------------------------------------------------------------- 1 | package assertions 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/smartystreets/assertions/internal/oglematchers" 7 | ) 8 | 9 | // ShouldBeGreaterThan receives exactly two parameters and ensures that the first is greater than the second. 10 | func ShouldBeGreaterThan(actual interface{}, expected ...interface{}) string { 11 | if fail := need(1, expected); fail != success { 12 | return fail 13 | } 14 | 15 | if matchError := oglematchers.GreaterThan(expected[0]).Matches(actual); matchError != nil { 16 | return fmt.Sprintf(shouldHaveBeenGreater, actual, expected[0]) 17 | } 18 | return success 19 | } 20 | 21 | // ShouldBeGreaterThanOrEqualTo receives exactly two parameters and ensures that the first is greater than or equal to the second. 22 | func ShouldBeGreaterThanOrEqualTo(actual interface{}, expected ...interface{}) string { 23 | if fail := need(1, expected); fail != success { 24 | return fail 25 | } else if matchError := oglematchers.GreaterOrEqual(expected[0]).Matches(actual); matchError != nil { 26 | return fmt.Sprintf(shouldHaveBeenGreaterOrEqual, actual, expected[0]) 27 | } 28 | return success 29 | } 30 | 31 | // ShouldBeLessThan receives exactly two parameters and ensures that the first is less than the second. 32 | func ShouldBeLessThan(actual interface{}, expected ...interface{}) string { 33 | if fail := need(1, expected); fail != success { 34 | return fail 35 | } else if matchError := oglematchers.LessThan(expected[0]).Matches(actual); matchError != nil { 36 | return fmt.Sprintf(shouldHaveBeenLess, actual, expected[0]) 37 | } 38 | return success 39 | } 40 | 41 | // ShouldBeLessThan receives exactly two parameters and ensures that the first is less than or equal to the second. 42 | func ShouldBeLessThanOrEqualTo(actual interface{}, expected ...interface{}) string { 43 | if fail := need(1, expected); fail != success { 44 | return fail 45 | } else if matchError := oglematchers.LessOrEqual(expected[0]).Matches(actual); matchError != nil { 46 | return fmt.Sprintf(shouldHaveBeenLessOrEqual, actual, expected[0]) 47 | } 48 | return success 49 | } 50 | 51 | // ShouldBeBetween receives exactly three parameters: an actual value, a lower bound, and an upper bound. 52 | // It ensures that the actual value is between both bounds (but not equal to either of them). 53 | func ShouldBeBetween(actual interface{}, expected ...interface{}) string { 54 | if fail := need(2, expected); fail != success { 55 | return fail 56 | } 57 | lower, upper, fail := deriveBounds(expected) 58 | 59 | if fail != success { 60 | return fail 61 | } else if !isBetween(actual, lower, upper) { 62 | return fmt.Sprintf(shouldHaveBeenBetween, actual, lower, upper) 63 | } 64 | return success 65 | } 66 | 67 | // ShouldNotBeBetween receives exactly three parameters: an actual value, a lower bound, and an upper bound. 68 | // It ensures that the actual value is NOT between both bounds. 69 | func ShouldNotBeBetween(actual interface{}, expected ...interface{}) string { 70 | if fail := need(2, expected); fail != success { 71 | return fail 72 | } 73 | lower, upper, fail := deriveBounds(expected) 74 | 75 | if fail != success { 76 | return fail 77 | } else if isBetween(actual, lower, upper) { 78 | return fmt.Sprintf(shouldNotHaveBeenBetween, actual, lower, upper) 79 | } 80 | return success 81 | } 82 | func deriveBounds(values []interface{}) (lower interface{}, upper interface{}, fail string) { 83 | lower = values[0] 84 | upper = values[1] 85 | 86 | if ShouldNotEqual(lower, upper) != success { 87 | return nil, nil, fmt.Sprintf(shouldHaveDifferentUpperAndLower, lower) 88 | } else if ShouldBeLessThan(lower, upper) != success { 89 | lower, upper = upper, lower 90 | } 91 | return lower, upper, success 92 | } 93 | func isBetween(value, lower, upper interface{}) bool { 94 | if ShouldBeGreaterThan(value, lower) != success { 95 | return false 96 | } else if ShouldBeLessThan(value, upper) != success { 97 | return false 98 | } 99 | return true 100 | } 101 | 102 | // ShouldBeBetweenOrEqual receives exactly three parameters: an actual value, a lower bound, and an upper bound. 103 | // It ensures that the actual value is between both bounds or equal to one of them. 104 | func ShouldBeBetweenOrEqual(actual interface{}, expected ...interface{}) string { 105 | if fail := need(2, expected); fail != success { 106 | return fail 107 | } 108 | lower, upper, fail := deriveBounds(expected) 109 | 110 | if fail != success { 111 | return fail 112 | } else if !isBetweenOrEqual(actual, lower, upper) { 113 | return fmt.Sprintf(shouldHaveBeenBetweenOrEqual, actual, lower, upper) 114 | } 115 | return success 116 | } 117 | 118 | // ShouldNotBeBetweenOrEqual receives exactly three parameters: an actual value, a lower bound, and an upper bound. 119 | // It ensures that the actual value is nopt between the bounds nor equal to either of them. 120 | func ShouldNotBeBetweenOrEqual(actual interface{}, expected ...interface{}) string { 121 | if fail := need(2, expected); fail != success { 122 | return fail 123 | } 124 | lower, upper, fail := deriveBounds(expected) 125 | 126 | if fail != success { 127 | return fail 128 | } else if isBetweenOrEqual(actual, lower, upper) { 129 | return fmt.Sprintf(shouldNotHaveBeenBetweenOrEqual, actual, lower, upper) 130 | } 131 | return success 132 | } 133 | 134 | func isBetweenOrEqual(value, lower, upper interface{}) bool { 135 | if ShouldBeGreaterThanOrEqualTo(value, lower) != success { 136 | return false 137 | } else if ShouldBeLessThanOrEqualTo(value, upper) != success { 138 | return false 139 | } 140 | return true 141 | } 142 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/serializer.go: -------------------------------------------------------------------------------- 1 | package assertions 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | 7 | "github.com/smartystreets/assertions/internal/go-render/render" 8 | ) 9 | 10 | type Serializer interface { 11 | serialize(expected, actual interface{}, message string) string 12 | serializeDetailed(expected, actual interface{}, message string) string 13 | } 14 | 15 | type failureSerializer struct{} 16 | 17 | func (self *failureSerializer) serializeDetailed(expected, actual interface{}, message string) string { 18 | view := FailureView{ 19 | Message: message, 20 | Expected: render.Render(expected), 21 | Actual: render.Render(actual), 22 | } 23 | serialized, _ := json.Marshal(view) 24 | return string(serialized) 25 | } 26 | 27 | func (self *failureSerializer) serialize(expected, actual interface{}, message string) string { 28 | view := FailureView{ 29 | Message: message, 30 | Expected: fmt.Sprintf("%+v", expected), 31 | Actual: fmt.Sprintf("%+v", actual), 32 | } 33 | serialized, _ := json.Marshal(view) 34 | return string(serialized) 35 | } 36 | 37 | func newSerializer() *failureSerializer { 38 | return &failureSerializer{} 39 | } 40 | 41 | /////////////////////////////////////////////////////////////////////////////// 42 | 43 | // This struct is also declared in github.com/smartystreets/goconvey/convey/reporting. 44 | // The json struct tags should be equal in both declarations. 45 | type FailureView struct { 46 | Message string `json:"Message"` 47 | Expected string `json:"Expected"` 48 | Actual string `json:"Actual"` 49 | } 50 | 51 | /////////////////////////////////////////////////////// 52 | 53 | // noopSerializer just gives back the original message. This is useful when we are using 54 | // the assertions from a context other than the GoConvey Web UI, that requires the JSON 55 | // structure provided by the failureSerializer. 56 | type noopSerializer struct{} 57 | 58 | func (self *noopSerializer) serialize(expected, actual interface{}, message string) string { 59 | return message 60 | } 61 | func (self *noopSerializer) serializeDetailed(expected, actual interface{}, message string) string { 62 | return message 63 | } 64 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/strings.go: -------------------------------------------------------------------------------- 1 | package assertions 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | "strings" 7 | ) 8 | 9 | // ShouldStartWith receives exactly 2 string parameters and ensures that the first starts with the second. 10 | func ShouldStartWith(actual interface{}, expected ...interface{}) string { 11 | if fail := need(1, expected); fail != success { 12 | return fail 13 | } 14 | 15 | value, valueIsString := actual.(string) 16 | prefix, prefixIsString := expected[0].(string) 17 | 18 | if !valueIsString || !prefixIsString { 19 | return fmt.Sprintf(shouldBothBeStrings, reflect.TypeOf(actual), reflect.TypeOf(expected[0])) 20 | } 21 | 22 | return shouldStartWith(value, prefix) 23 | } 24 | func shouldStartWith(value, prefix string) string { 25 | if !strings.HasPrefix(value, prefix) { 26 | shortval := value 27 | if len(shortval) > len(prefix) { 28 | shortval = shortval[:len(prefix)] + "..." 29 | } 30 | return serializer.serialize(prefix, shortval, fmt.Sprintf(shouldHaveStartedWith, value, prefix)) 31 | } 32 | return success 33 | } 34 | 35 | // ShouldNotStartWith receives exactly 2 string parameters and ensures that the first does not start with the second. 36 | func ShouldNotStartWith(actual interface{}, expected ...interface{}) string { 37 | if fail := need(1, expected); fail != success { 38 | return fail 39 | } 40 | 41 | value, valueIsString := actual.(string) 42 | prefix, prefixIsString := expected[0].(string) 43 | 44 | if !valueIsString || !prefixIsString { 45 | return fmt.Sprintf(shouldBothBeStrings, reflect.TypeOf(actual), reflect.TypeOf(expected[0])) 46 | } 47 | 48 | return shouldNotStartWith(value, prefix) 49 | } 50 | func shouldNotStartWith(value, prefix string) string { 51 | if strings.HasPrefix(value, prefix) { 52 | if value == "" { 53 | value = "" 54 | } 55 | if prefix == "" { 56 | prefix = "" 57 | } 58 | return fmt.Sprintf(shouldNotHaveStartedWith, value, prefix) 59 | } 60 | return success 61 | } 62 | 63 | // ShouldEndWith receives exactly 2 string parameters and ensures that the first ends with the second. 64 | func ShouldEndWith(actual interface{}, expected ...interface{}) string { 65 | if fail := need(1, expected); fail != success { 66 | return fail 67 | } 68 | 69 | value, valueIsString := actual.(string) 70 | suffix, suffixIsString := expected[0].(string) 71 | 72 | if !valueIsString || !suffixIsString { 73 | return fmt.Sprintf(shouldBothBeStrings, reflect.TypeOf(actual), reflect.TypeOf(expected[0])) 74 | } 75 | 76 | return shouldEndWith(value, suffix) 77 | } 78 | func shouldEndWith(value, suffix string) string { 79 | if !strings.HasSuffix(value, suffix) { 80 | shortval := value 81 | if len(shortval) > len(suffix) { 82 | shortval = "..." + shortval[len(shortval)-len(suffix):] 83 | } 84 | return serializer.serialize(suffix, shortval, fmt.Sprintf(shouldHaveEndedWith, value, suffix)) 85 | } 86 | return success 87 | } 88 | 89 | // ShouldEndWith receives exactly 2 string parameters and ensures that the first does not end with the second. 90 | func ShouldNotEndWith(actual interface{}, expected ...interface{}) string { 91 | if fail := need(1, expected); fail != success { 92 | return fail 93 | } 94 | 95 | value, valueIsString := actual.(string) 96 | suffix, suffixIsString := expected[0].(string) 97 | 98 | if !valueIsString || !suffixIsString { 99 | return fmt.Sprintf(shouldBothBeStrings, reflect.TypeOf(actual), reflect.TypeOf(expected[0])) 100 | } 101 | 102 | return shouldNotEndWith(value, suffix) 103 | } 104 | func shouldNotEndWith(value, suffix string) string { 105 | if strings.HasSuffix(value, suffix) { 106 | if value == "" { 107 | value = "" 108 | } 109 | if suffix == "" { 110 | suffix = "" 111 | } 112 | return fmt.Sprintf(shouldNotHaveEndedWith, value, suffix) 113 | } 114 | return success 115 | } 116 | 117 | // ShouldContainSubstring receives exactly 2 string parameters and ensures that the first contains the second as a substring. 118 | func ShouldContainSubstring(actual interface{}, expected ...interface{}) string { 119 | if fail := need(1, expected); fail != success { 120 | return fail 121 | } 122 | 123 | long, longOk := actual.(string) 124 | short, shortOk := expected[0].(string) 125 | 126 | if !longOk || !shortOk { 127 | return fmt.Sprintf(shouldBothBeStrings, reflect.TypeOf(actual), reflect.TypeOf(expected[0])) 128 | } 129 | 130 | if !strings.Contains(long, short) { 131 | return serializer.serialize(expected[0], actual, fmt.Sprintf(shouldHaveContainedSubstring, long, short)) 132 | } 133 | return success 134 | } 135 | 136 | // ShouldNotContainSubstring receives exactly 2 string parameters and ensures that the first does NOT contain the second as a substring. 137 | func ShouldNotContainSubstring(actual interface{}, expected ...interface{}) string { 138 | if fail := need(1, expected); fail != success { 139 | return fail 140 | } 141 | 142 | long, longOk := actual.(string) 143 | short, shortOk := expected[0].(string) 144 | 145 | if !longOk || !shortOk { 146 | return fmt.Sprintf(shouldBothBeStrings, reflect.TypeOf(actual), reflect.TypeOf(expected[0])) 147 | } 148 | 149 | if strings.Contains(long, short) { 150 | return fmt.Sprintf(shouldNotHaveContainedSubstring, long, short) 151 | } 152 | return success 153 | } 154 | 155 | // ShouldBeBlank receives exactly 1 string parameter and ensures that it is equal to "". 156 | func ShouldBeBlank(actual interface{}, expected ...interface{}) string { 157 | if fail := need(0, expected); fail != success { 158 | return fail 159 | } 160 | value, ok := actual.(string) 161 | if !ok { 162 | return fmt.Sprintf(shouldBeString, reflect.TypeOf(actual)) 163 | } 164 | if value != "" { 165 | return serializer.serialize("", value, fmt.Sprintf(shouldHaveBeenBlank, value)) 166 | } 167 | return success 168 | } 169 | 170 | // ShouldNotBeBlank receives exactly 1 string parameter and ensures that it is equal to "". 171 | func ShouldNotBeBlank(actual interface{}, expected ...interface{}) string { 172 | if fail := need(0, expected); fail != success { 173 | return fail 174 | } 175 | value, ok := actual.(string) 176 | if !ok { 177 | return fmt.Sprintf(shouldBeString, reflect.TypeOf(actual)) 178 | } 179 | if value == "" { 180 | return shouldNotHaveBeenBlank 181 | } 182 | return success 183 | } 184 | 185 | // ShouldEqualWithout receives exactly 3 string parameters and ensures that the first is equal to the second 186 | // after removing all instances of the third from the first using strings.Replace(first, third, "", -1). 187 | func ShouldEqualWithout(actual interface{}, expected ...interface{}) string { 188 | if fail := need(2, expected); fail != success { 189 | return fail 190 | } 191 | actualString, ok1 := actual.(string) 192 | expectedString, ok2 := expected[0].(string) 193 | replace, ok3 := expected[1].(string) 194 | 195 | if !ok1 || !ok2 || !ok3 { 196 | return fmt.Sprintf(shouldAllBeStrings, []reflect.Type{ 197 | reflect.TypeOf(actual), 198 | reflect.TypeOf(expected[0]), 199 | reflect.TypeOf(expected[1]), 200 | }) 201 | } 202 | 203 | replaced := strings.Replace(actualString, replace, "", -1) 204 | if replaced == expectedString { 205 | return "" 206 | } 207 | 208 | return fmt.Sprintf("Expected '%s' to equal '%s' but without any '%s' (but it didn't).", actualString, expectedString, replace) 209 | } 210 | 211 | // ShouldEqualTrimSpace receives exactly 2 string parameters and ensures that the first is equal to the second 212 | // after removing all leading and trailing whitespace using strings.TrimSpace(first). 213 | func ShouldEqualTrimSpace(actual interface{}, expected ...interface{}) string { 214 | if fail := need(1, expected); fail != success { 215 | return fail 216 | } 217 | 218 | actualString, valueIsString := actual.(string) 219 | _, value2IsString := expected[0].(string) 220 | 221 | if !valueIsString || !value2IsString { 222 | return fmt.Sprintf(shouldBothBeStrings, reflect.TypeOf(actual), reflect.TypeOf(expected[0])) 223 | } 224 | 225 | actualString = strings.TrimSpace(actualString) 226 | return ShouldEqual(actualString, expected[0]) 227 | } 228 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/time.go: -------------------------------------------------------------------------------- 1 | package assertions 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | ) 7 | 8 | // ShouldHappenBefore receives exactly 2 time.Time arguments and asserts that the first happens before the second. 9 | func ShouldHappenBefore(actual interface{}, expected ...interface{}) string { 10 | if fail := need(1, expected); fail != success { 11 | return fail 12 | } 13 | actualTime, firstOk := actual.(time.Time) 14 | expectedTime, secondOk := expected[0].(time.Time) 15 | 16 | if !firstOk || !secondOk { 17 | return shouldUseTimes 18 | } 19 | 20 | if !actualTime.Before(expectedTime) { 21 | return fmt.Sprintf(shouldHaveHappenedBefore, actualTime, expectedTime, actualTime.Sub(expectedTime)) 22 | } 23 | 24 | return success 25 | } 26 | 27 | // ShouldHappenOnOrBefore receives exactly 2 time.Time arguments and asserts that the first happens on or before the second. 28 | func ShouldHappenOnOrBefore(actual interface{}, expected ...interface{}) string { 29 | if fail := need(1, expected); fail != success { 30 | return fail 31 | } 32 | actualTime, firstOk := actual.(time.Time) 33 | expectedTime, secondOk := expected[0].(time.Time) 34 | 35 | if !firstOk || !secondOk { 36 | return shouldUseTimes 37 | } 38 | 39 | if actualTime.Equal(expectedTime) { 40 | return success 41 | } 42 | return ShouldHappenBefore(actualTime, expectedTime) 43 | } 44 | 45 | // ShouldHappenAfter receives exactly 2 time.Time arguments and asserts that the first happens after the second. 46 | func ShouldHappenAfter(actual interface{}, expected ...interface{}) string { 47 | if fail := need(1, expected); fail != success { 48 | return fail 49 | } 50 | actualTime, firstOk := actual.(time.Time) 51 | expectedTime, secondOk := expected[0].(time.Time) 52 | 53 | if !firstOk || !secondOk { 54 | return shouldUseTimes 55 | } 56 | if !actualTime.After(expectedTime) { 57 | return fmt.Sprintf(shouldHaveHappenedAfter, actualTime, expectedTime, expectedTime.Sub(actualTime)) 58 | } 59 | return success 60 | } 61 | 62 | // ShouldHappenOnOrAfter receives exactly 2 time.Time arguments and asserts that the first happens on or after the second. 63 | func ShouldHappenOnOrAfter(actual interface{}, expected ...interface{}) string { 64 | if fail := need(1, expected); fail != success { 65 | return fail 66 | } 67 | actualTime, firstOk := actual.(time.Time) 68 | expectedTime, secondOk := expected[0].(time.Time) 69 | 70 | if !firstOk || !secondOk { 71 | return shouldUseTimes 72 | } 73 | if actualTime.Equal(expectedTime) { 74 | return success 75 | } 76 | return ShouldHappenAfter(actualTime, expectedTime) 77 | } 78 | 79 | // ShouldHappenBetween receives exactly 3 time.Time arguments and asserts that the first happens between (not on) the second and third. 80 | func ShouldHappenBetween(actual interface{}, expected ...interface{}) string { 81 | if fail := need(2, expected); fail != success { 82 | return fail 83 | } 84 | actualTime, firstOk := actual.(time.Time) 85 | min, secondOk := expected[0].(time.Time) 86 | max, thirdOk := expected[1].(time.Time) 87 | 88 | if !firstOk || !secondOk || !thirdOk { 89 | return shouldUseTimes 90 | } 91 | 92 | if !actualTime.After(min) { 93 | return fmt.Sprintf(shouldHaveHappenedBetween, actualTime, min, max, min.Sub(actualTime)) 94 | } 95 | if !actualTime.Before(max) { 96 | return fmt.Sprintf(shouldHaveHappenedBetween, actualTime, min, max, actualTime.Sub(max)) 97 | } 98 | return success 99 | } 100 | 101 | // ShouldHappenOnOrBetween receives exactly 3 time.Time arguments and asserts that the first happens between or on the second and third. 102 | func ShouldHappenOnOrBetween(actual interface{}, expected ...interface{}) string { 103 | if fail := need(2, expected); fail != success { 104 | return fail 105 | } 106 | actualTime, firstOk := actual.(time.Time) 107 | min, secondOk := expected[0].(time.Time) 108 | max, thirdOk := expected[1].(time.Time) 109 | 110 | if !firstOk || !secondOk || !thirdOk { 111 | return shouldUseTimes 112 | } 113 | if actualTime.Equal(min) || actualTime.Equal(max) { 114 | return success 115 | } 116 | return ShouldHappenBetween(actualTime, min, max) 117 | } 118 | 119 | // ShouldNotHappenOnOrBetween receives exactly 3 time.Time arguments and asserts that the first 120 | // does NOT happen between or on the second or third. 121 | func ShouldNotHappenOnOrBetween(actual interface{}, expected ...interface{}) string { 122 | if fail := need(2, expected); fail != success { 123 | return fail 124 | } 125 | actualTime, firstOk := actual.(time.Time) 126 | min, secondOk := expected[0].(time.Time) 127 | max, thirdOk := expected[1].(time.Time) 128 | 129 | if !firstOk || !secondOk || !thirdOk { 130 | return shouldUseTimes 131 | } 132 | if actualTime.Equal(min) || actualTime.Equal(max) { 133 | return fmt.Sprintf(shouldNotHaveHappenedOnOrBetween, actualTime, min, max) 134 | } 135 | if actualTime.After(min) && actualTime.Before(max) { 136 | return fmt.Sprintf(shouldNotHaveHappenedOnOrBetween, actualTime, min, max) 137 | } 138 | return success 139 | } 140 | 141 | // ShouldHappenWithin receives a time.Time, a time.Duration, and a time.Time (3 arguments) 142 | // and asserts that the first time.Time happens within or on the duration specified relative to 143 | // the other time.Time. 144 | func ShouldHappenWithin(actual interface{}, expected ...interface{}) string { 145 | if fail := need(2, expected); fail != success { 146 | return fail 147 | } 148 | actualTime, firstOk := actual.(time.Time) 149 | tolerance, secondOk := expected[0].(time.Duration) 150 | threshold, thirdOk := expected[1].(time.Time) 151 | 152 | if !firstOk || !secondOk || !thirdOk { 153 | return shouldUseDurationAndTime 154 | } 155 | 156 | min := threshold.Add(-tolerance) 157 | max := threshold.Add(tolerance) 158 | return ShouldHappenOnOrBetween(actualTime, min, max) 159 | } 160 | 161 | // ShouldNotHappenWithin receives a time.Time, a time.Duration, and a time.Time (3 arguments) 162 | // and asserts that the first time.Time does NOT happen within or on the duration specified relative to 163 | // the other time.Time. 164 | func ShouldNotHappenWithin(actual interface{}, expected ...interface{}) string { 165 | if fail := need(2, expected); fail != success { 166 | return fail 167 | } 168 | actualTime, firstOk := actual.(time.Time) 169 | tolerance, secondOk := expected[0].(time.Duration) 170 | threshold, thirdOk := expected[1].(time.Time) 171 | 172 | if !firstOk || !secondOk || !thirdOk { 173 | return shouldUseDurationAndTime 174 | } 175 | 176 | min := threshold.Add(-tolerance) 177 | max := threshold.Add(tolerance) 178 | return ShouldNotHappenOnOrBetween(actualTime, min, max) 179 | } 180 | 181 | // ShouldBeChronological receives a []time.Time slice and asserts that the are 182 | // in chronological order starting with the first time.Time as the earliest. 183 | func ShouldBeChronological(actual interface{}, expected ...interface{}) string { 184 | if fail := need(0, expected); fail != success { 185 | return fail 186 | } 187 | 188 | times, ok := actual.([]time.Time) 189 | if !ok { 190 | return shouldUseTimeSlice 191 | } 192 | 193 | var previous time.Time 194 | for i, current := range times { 195 | if i > 0 && current.Before(previous) { 196 | return fmt.Sprintf(shouldHaveBeenChronological, 197 | i, i-1, previous.String(), i, current.String()) 198 | } 199 | previous = current 200 | } 201 | return "" 202 | } 203 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/assertions/type.go: -------------------------------------------------------------------------------- 1 | package assertions 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | ) 7 | 8 | // ShouldHaveSameTypeAs receives exactly two parameters and compares their underlying types for equality. 9 | func ShouldHaveSameTypeAs(actual interface{}, expected ...interface{}) string { 10 | if fail := need(1, expected); fail != success { 11 | return fail 12 | } 13 | 14 | first := reflect.TypeOf(actual) 15 | second := reflect.TypeOf(expected[0]) 16 | 17 | if first != second { 18 | return serializer.serialize(second, first, fmt.Sprintf(shouldHaveBeenA, actual, second, first)) 19 | } 20 | 21 | return success 22 | } 23 | 24 | // ShouldNotHaveSameTypeAs receives exactly two parameters and compares their underlying types for inequality. 25 | func ShouldNotHaveSameTypeAs(actual interface{}, expected ...interface{}) string { 26 | if fail := need(1, expected); fail != success { 27 | return fail 28 | } 29 | 30 | first := reflect.TypeOf(actual) 31 | second := reflect.TypeOf(expected[0]) 32 | 33 | if (actual == nil && expected[0] == nil) || first == second { 34 | return fmt.Sprintf(shouldNotHaveBeenA, actual, second) 35 | } 36 | return success 37 | } 38 | 39 | // ShouldImplement receives exactly two parameters and ensures 40 | // that the first implements the interface type of the second. 41 | func ShouldImplement(actual interface{}, expectedList ...interface{}) string { 42 | if fail := need(1, expectedList); fail != success { 43 | return fail 44 | } 45 | 46 | expected := expectedList[0] 47 | if fail := ShouldBeNil(expected); fail != success { 48 | return shouldCompareWithInterfacePointer 49 | } 50 | 51 | if fail := ShouldNotBeNil(actual); fail != success { 52 | return shouldNotBeNilActual 53 | } 54 | 55 | var actualType reflect.Type 56 | if reflect.TypeOf(actual).Kind() != reflect.Ptr { 57 | actualType = reflect.PtrTo(reflect.TypeOf(actual)) 58 | } else { 59 | actualType = reflect.TypeOf(actual) 60 | } 61 | 62 | expectedType := reflect.TypeOf(expected) 63 | if fail := ShouldNotBeNil(expectedType); fail != success { 64 | return shouldCompareWithInterfacePointer 65 | } 66 | 67 | expectedInterface := expectedType.Elem() 68 | 69 | if !actualType.Implements(expectedInterface) { 70 | return fmt.Sprintf(shouldHaveImplemented, expectedInterface, actualType) 71 | } 72 | return success 73 | } 74 | 75 | // ShouldNotImplement receives exactly two parameters and ensures 76 | // that the first does NOT implement the interface type of the second. 77 | func ShouldNotImplement(actual interface{}, expectedList ...interface{}) string { 78 | if fail := need(1, expectedList); fail != success { 79 | return fail 80 | } 81 | 82 | expected := expectedList[0] 83 | if fail := ShouldBeNil(expected); fail != success { 84 | return shouldCompareWithInterfacePointer 85 | } 86 | 87 | if fail := ShouldNotBeNil(actual); fail != success { 88 | return shouldNotBeNilActual 89 | } 90 | 91 | var actualType reflect.Type 92 | if reflect.TypeOf(actual).Kind() != reflect.Ptr { 93 | actualType = reflect.PtrTo(reflect.TypeOf(actual)) 94 | } else { 95 | actualType = reflect.TypeOf(actual) 96 | } 97 | 98 | expectedType := reflect.TypeOf(expected) 99 | if fail := ShouldNotBeNil(expectedType); fail != success { 100 | return shouldCompareWithInterfacePointer 101 | } 102 | 103 | expectedInterface := expectedType.Elem() 104 | 105 | if actualType.Implements(expectedInterface) { 106 | return fmt.Sprintf(shouldNotHaveImplemented, actualType, expectedInterface) 107 | } 108 | return success 109 | } 110 | 111 | // ShouldBeError asserts that the first argument implements the error interface. 112 | // It also compares the first argument against the second argument if provided 113 | // (which must be an error message string or another error value). 114 | func ShouldBeError(actual interface{}, expected ...interface{}) string { 115 | if fail := atMost(1, expected); fail != success { 116 | return fail 117 | } 118 | 119 | if !isError(actual) { 120 | return fmt.Sprintf(shouldBeError, reflect.TypeOf(actual)) 121 | } 122 | 123 | if len(expected) == 0 { 124 | return success 125 | } 126 | 127 | if expected := expected[0]; !isString(expected) && !isError(expected) { 128 | return fmt.Sprintf(shouldBeErrorInvalidComparisonValue, reflect.TypeOf(expected)) 129 | } 130 | return ShouldEqual(fmt.Sprint(actual), fmt.Sprint(expected[0])) 131 | } 132 | 133 | func isString(value interface{}) bool { _, ok := value.(string); return ok } 134 | func isError(value interface{}) bool { _, ok := value.(error); return ok } 135 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/goconvey/LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 SmartyStreets, LLC 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | 21 | NOTE: Various optional and subordinate components carry their own licensing 22 | requirements and restrictions. Use of those components is subject to the terms 23 | and conditions outlined the respective license of each component. 24 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/goconvey/convey/assertions.go: -------------------------------------------------------------------------------- 1 | package convey 2 | 3 | import "github.com/smartystreets/assertions" 4 | 5 | var ( 6 | ShouldEqual = assertions.ShouldEqual 7 | ShouldNotEqual = assertions.ShouldNotEqual 8 | ShouldAlmostEqual = assertions.ShouldAlmostEqual 9 | ShouldNotAlmostEqual = assertions.ShouldNotAlmostEqual 10 | ShouldResemble = assertions.ShouldResemble 11 | ShouldNotResemble = assertions.ShouldNotResemble 12 | ShouldPointTo = assertions.ShouldPointTo 13 | ShouldNotPointTo = assertions.ShouldNotPointTo 14 | ShouldBeNil = assertions.ShouldBeNil 15 | ShouldNotBeNil = assertions.ShouldNotBeNil 16 | ShouldBeTrue = assertions.ShouldBeTrue 17 | ShouldBeFalse = assertions.ShouldBeFalse 18 | ShouldBeZeroValue = assertions.ShouldBeZeroValue 19 | 20 | ShouldBeGreaterThan = assertions.ShouldBeGreaterThan 21 | ShouldBeGreaterThanOrEqualTo = assertions.ShouldBeGreaterThanOrEqualTo 22 | ShouldBeLessThan = assertions.ShouldBeLessThan 23 | ShouldBeLessThanOrEqualTo = assertions.ShouldBeLessThanOrEqualTo 24 | ShouldBeBetween = assertions.ShouldBeBetween 25 | ShouldNotBeBetween = assertions.ShouldNotBeBetween 26 | ShouldBeBetweenOrEqual = assertions.ShouldBeBetweenOrEqual 27 | ShouldNotBeBetweenOrEqual = assertions.ShouldNotBeBetweenOrEqual 28 | 29 | ShouldContain = assertions.ShouldContain 30 | ShouldNotContain = assertions.ShouldNotContain 31 | ShouldContainKey = assertions.ShouldContainKey 32 | ShouldNotContainKey = assertions.ShouldNotContainKey 33 | ShouldBeIn = assertions.ShouldBeIn 34 | ShouldNotBeIn = assertions.ShouldNotBeIn 35 | ShouldBeEmpty = assertions.ShouldBeEmpty 36 | ShouldNotBeEmpty = assertions.ShouldNotBeEmpty 37 | ShouldHaveLength = assertions.ShouldHaveLength 38 | 39 | ShouldStartWith = assertions.ShouldStartWith 40 | ShouldNotStartWith = assertions.ShouldNotStartWith 41 | ShouldEndWith = assertions.ShouldEndWith 42 | ShouldNotEndWith = assertions.ShouldNotEndWith 43 | ShouldBeBlank = assertions.ShouldBeBlank 44 | ShouldNotBeBlank = assertions.ShouldNotBeBlank 45 | ShouldContainSubstring = assertions.ShouldContainSubstring 46 | ShouldNotContainSubstring = assertions.ShouldNotContainSubstring 47 | 48 | ShouldPanic = assertions.ShouldPanic 49 | ShouldNotPanic = assertions.ShouldNotPanic 50 | ShouldPanicWith = assertions.ShouldPanicWith 51 | ShouldNotPanicWith = assertions.ShouldNotPanicWith 52 | 53 | ShouldHaveSameTypeAs = assertions.ShouldHaveSameTypeAs 54 | ShouldNotHaveSameTypeAs = assertions.ShouldNotHaveSameTypeAs 55 | ShouldImplement = assertions.ShouldImplement 56 | ShouldNotImplement = assertions.ShouldNotImplement 57 | 58 | ShouldHappenBefore = assertions.ShouldHappenBefore 59 | ShouldHappenOnOrBefore = assertions.ShouldHappenOnOrBefore 60 | ShouldHappenAfter = assertions.ShouldHappenAfter 61 | ShouldHappenOnOrAfter = assertions.ShouldHappenOnOrAfter 62 | ShouldHappenBetween = assertions.ShouldHappenBetween 63 | ShouldHappenOnOrBetween = assertions.ShouldHappenOnOrBetween 64 | ShouldNotHappenOnOrBetween = assertions.ShouldNotHappenOnOrBetween 65 | ShouldHappenWithin = assertions.ShouldHappenWithin 66 | ShouldNotHappenWithin = assertions.ShouldNotHappenWithin 67 | ShouldBeChronological = assertions.ShouldBeChronological 68 | 69 | ShouldBeError = assertions.ShouldBeError 70 | ) 71 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/goconvey/convey/context.go: -------------------------------------------------------------------------------- 1 | package convey 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/jtolds/gls" 7 | "github.com/smartystreets/goconvey/convey/reporting" 8 | ) 9 | 10 | type conveyErr struct { 11 | fmt string 12 | params []interface{} 13 | } 14 | 15 | func (e *conveyErr) Error() string { 16 | return fmt.Sprintf(e.fmt, e.params...) 17 | } 18 | 19 | func conveyPanic(fmt string, params ...interface{}) { 20 | panic(&conveyErr{fmt, params}) 21 | } 22 | 23 | const ( 24 | missingGoTest = `Top-level calls to Convey(...) need a reference to the *testing.T. 25 | Hint: Convey("description here", t, func() { /* notice that the second argument was the *testing.T (t)! */ }) ` 26 | extraGoTest = `Only the top-level call to Convey(...) needs a reference to the *testing.T.` 27 | noStackContext = "Convey operation made without context on goroutine stack.\n" + 28 | "Hint: Perhaps you meant to use `Convey(..., func(c C){...})` ?" 29 | differentConveySituations = "Different set of Convey statements on subsequent pass!\nDid not expect %#v." 30 | multipleIdenticalConvey = "Multiple convey suites with identical names: %#v" 31 | ) 32 | 33 | const ( 34 | failureHalt = "___FAILURE_HALT___" 35 | 36 | nodeKey = "node" 37 | ) 38 | 39 | ///////////////////////////////// Stack Context ///////////////////////////////// 40 | 41 | func getCurrentContext() *context { 42 | ctx, ok := ctxMgr.GetValue(nodeKey) 43 | if ok { 44 | return ctx.(*context) 45 | } 46 | return nil 47 | } 48 | 49 | func mustGetCurrentContext() *context { 50 | ctx := getCurrentContext() 51 | if ctx == nil { 52 | conveyPanic(noStackContext) 53 | } 54 | return ctx 55 | } 56 | 57 | //////////////////////////////////// Context //////////////////////////////////// 58 | 59 | // context magically handles all coordination of Convey's and So assertions. 60 | // 61 | // It is tracked on the stack as goroutine-local-storage with the gls package, 62 | // or explicitly if the user decides to call convey like: 63 | // 64 | // Convey(..., func(c C) { 65 | // c.So(...) 66 | // }) 67 | // 68 | // This implements the `C` interface. 69 | type context struct { 70 | reporter reporting.Reporter 71 | 72 | children map[string]*context 73 | 74 | resets []func() 75 | 76 | executedOnce bool 77 | expectChildRun *bool 78 | complete bool 79 | 80 | focus bool 81 | failureMode FailureMode 82 | } 83 | 84 | // rootConvey is the main entry point to a test suite. This is called when 85 | // there's no context in the stack already, and items must contain a `t` object, 86 | // or this panics. 87 | func rootConvey(items ...interface{}) { 88 | entry := discover(items) 89 | 90 | if entry.Test == nil { 91 | conveyPanic(missingGoTest) 92 | } 93 | 94 | expectChildRun := true 95 | ctx := &context{ 96 | reporter: buildReporter(), 97 | 98 | children: make(map[string]*context), 99 | 100 | expectChildRun: &expectChildRun, 101 | 102 | focus: entry.Focus, 103 | failureMode: defaultFailureMode.combine(entry.FailMode), 104 | } 105 | ctxMgr.SetValues(gls.Values{nodeKey: ctx}, func() { 106 | ctx.reporter.BeginStory(reporting.NewStoryReport(entry.Test)) 107 | defer ctx.reporter.EndStory() 108 | 109 | for ctx.shouldVisit() { 110 | ctx.conveyInner(entry.Situation, entry.Func) 111 | expectChildRun = true 112 | } 113 | }) 114 | } 115 | 116 | //////////////////////////////////// Methods //////////////////////////////////// 117 | 118 | func (ctx *context) SkipConvey(items ...interface{}) { 119 | ctx.Convey(items, skipConvey) 120 | } 121 | 122 | func (ctx *context) FocusConvey(items ...interface{}) { 123 | ctx.Convey(items, focusConvey) 124 | } 125 | 126 | func (ctx *context) Convey(items ...interface{}) { 127 | entry := discover(items) 128 | 129 | // we're a branch, or leaf (on the wind) 130 | if entry.Test != nil { 131 | conveyPanic(extraGoTest) 132 | } 133 | if ctx.focus && !entry.Focus { 134 | return 135 | } 136 | 137 | var inner_ctx *context 138 | if ctx.executedOnce { 139 | var ok bool 140 | inner_ctx, ok = ctx.children[entry.Situation] 141 | if !ok { 142 | conveyPanic(differentConveySituations, entry.Situation) 143 | } 144 | } else { 145 | if _, ok := ctx.children[entry.Situation]; ok { 146 | conveyPanic(multipleIdenticalConvey, entry.Situation) 147 | } 148 | inner_ctx = &context{ 149 | reporter: ctx.reporter, 150 | 151 | children: make(map[string]*context), 152 | 153 | expectChildRun: ctx.expectChildRun, 154 | 155 | focus: entry.Focus, 156 | failureMode: ctx.failureMode.combine(entry.FailMode), 157 | } 158 | ctx.children[entry.Situation] = inner_ctx 159 | } 160 | 161 | if inner_ctx.shouldVisit() { 162 | ctxMgr.SetValues(gls.Values{nodeKey: inner_ctx}, func() { 163 | inner_ctx.conveyInner(entry.Situation, entry.Func) 164 | }) 165 | } 166 | } 167 | 168 | func (ctx *context) SkipSo(stuff ...interface{}) { 169 | ctx.assertionReport(reporting.NewSkipReport()) 170 | } 171 | 172 | func (ctx *context) So(actual interface{}, assert assertion, expected ...interface{}) { 173 | if result := assert(actual, expected...); result == assertionSuccess { 174 | ctx.assertionReport(reporting.NewSuccessReport()) 175 | } else { 176 | ctx.assertionReport(reporting.NewFailureReport(result)) 177 | } 178 | } 179 | 180 | func (ctx *context) Reset(action func()) { 181 | /* TODO: Failure mode configuration */ 182 | ctx.resets = append(ctx.resets, action) 183 | } 184 | 185 | func (ctx *context) Print(items ...interface{}) (int, error) { 186 | fmt.Fprint(ctx.reporter, items...) 187 | return fmt.Print(items...) 188 | } 189 | 190 | func (ctx *context) Println(items ...interface{}) (int, error) { 191 | fmt.Fprintln(ctx.reporter, items...) 192 | return fmt.Println(items...) 193 | } 194 | 195 | func (ctx *context) Printf(format string, items ...interface{}) (int, error) { 196 | fmt.Fprintf(ctx.reporter, format, items...) 197 | return fmt.Printf(format, items...) 198 | } 199 | 200 | //////////////////////////////////// Private //////////////////////////////////// 201 | 202 | // shouldVisit returns true iff we should traverse down into a Convey. Note 203 | // that just because we don't traverse a Convey this time, doesn't mean that 204 | // we may not traverse it on a subsequent pass. 205 | func (c *context) shouldVisit() bool { 206 | return !c.complete && *c.expectChildRun 207 | } 208 | 209 | // conveyInner is the function which actually executes the user's anonymous test 210 | // function body. At this point, Convey or RootConvey has decided that this 211 | // function should actually run. 212 | func (ctx *context) conveyInner(situation string, f func(C)) { 213 | // Record/Reset state for next time. 214 | defer func() { 215 | ctx.executedOnce = true 216 | 217 | // This is only needed at the leaves, but there's no harm in also setting it 218 | // when returning from branch Convey's 219 | *ctx.expectChildRun = false 220 | }() 221 | 222 | // Set up+tear down our scope for the reporter 223 | ctx.reporter.Enter(reporting.NewScopeReport(situation)) 224 | defer ctx.reporter.Exit() 225 | 226 | // Recover from any panics in f, and assign the `complete` status for this 227 | // node of the tree. 228 | defer func() { 229 | ctx.complete = true 230 | if problem := recover(); problem != nil { 231 | if problem, ok := problem.(*conveyErr); ok { 232 | panic(problem) 233 | } 234 | if problem != failureHalt { 235 | ctx.reporter.Report(reporting.NewErrorReport(problem)) 236 | } 237 | } else { 238 | for _, child := range ctx.children { 239 | if !child.complete { 240 | ctx.complete = false 241 | return 242 | } 243 | } 244 | } 245 | }() 246 | 247 | // Resets are registered as the `f` function executes, so nil them here. 248 | // All resets are run in registration order (FIFO). 249 | ctx.resets = []func(){} 250 | defer func() { 251 | for _, r := range ctx.resets { 252 | // panics handled by the previous defer 253 | r() 254 | } 255 | }() 256 | 257 | if f == nil { 258 | // if f is nil, this was either a Convey(..., nil), or a SkipConvey 259 | ctx.reporter.Report(reporting.NewSkipReport()) 260 | } else { 261 | f(ctx) 262 | } 263 | } 264 | 265 | // assertionReport is a helper for So and SkipSo which makes the report and 266 | // then possibly panics, depending on the current context's failureMode. 267 | func (ctx *context) assertionReport(r *reporting.AssertionResult) { 268 | ctx.reporter.Report(r) 269 | if r.Failure != "" && ctx.failureMode == FailureHalts { 270 | panic(failureHalt) 271 | } 272 | } 273 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/goconvey/convey/convey.goconvey: -------------------------------------------------------------------------------- 1 | #ignore 2 | -timeout=1s 3 | #-covermode=count 4 | #-coverpkg=github.com/smartystreets/goconvey/convey,github.com/smartystreets/goconvey/convey/gotest,github.com/smartystreets/goconvey/convey/reporting -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/goconvey/convey/discovery.go: -------------------------------------------------------------------------------- 1 | package convey 2 | 3 | type actionSpecifier uint8 4 | 5 | const ( 6 | noSpecifier actionSpecifier = iota 7 | skipConvey 8 | focusConvey 9 | ) 10 | 11 | type suite struct { 12 | Situation string 13 | Test t 14 | Focus bool 15 | Func func(C) // nil means skipped 16 | FailMode FailureMode 17 | } 18 | 19 | func newSuite(situation string, failureMode FailureMode, f func(C), test t, specifier actionSpecifier) *suite { 20 | ret := &suite{ 21 | Situation: situation, 22 | Test: test, 23 | Func: f, 24 | FailMode: failureMode, 25 | } 26 | switch specifier { 27 | case skipConvey: 28 | ret.Func = nil 29 | case focusConvey: 30 | ret.Focus = true 31 | } 32 | return ret 33 | } 34 | 35 | func discover(items []interface{}) *suite { 36 | name, items := parseName(items) 37 | test, items := parseGoTest(items) 38 | failure, items := parseFailureMode(items) 39 | action, items := parseAction(items) 40 | specifier, items := parseSpecifier(items) 41 | 42 | if len(items) != 0 { 43 | conveyPanic(parseError) 44 | } 45 | 46 | return newSuite(name, failure, action, test, specifier) 47 | } 48 | func item(items []interface{}) interface{} { 49 | if len(items) == 0 { 50 | conveyPanic(parseError) 51 | } 52 | return items[0] 53 | } 54 | func parseName(items []interface{}) (string, []interface{}) { 55 | if name, parsed := item(items).(string); parsed { 56 | return name, items[1:] 57 | } 58 | conveyPanic(parseError) 59 | panic("never get here") 60 | } 61 | func parseGoTest(items []interface{}) (t, []interface{}) { 62 | if test, parsed := item(items).(t); parsed { 63 | return test, items[1:] 64 | } 65 | return nil, items 66 | } 67 | func parseFailureMode(items []interface{}) (FailureMode, []interface{}) { 68 | if mode, parsed := item(items).(FailureMode); parsed { 69 | return mode, items[1:] 70 | } 71 | return FailureInherits, items 72 | } 73 | func parseAction(items []interface{}) (func(C), []interface{}) { 74 | switch x := item(items).(type) { 75 | case nil: 76 | return nil, items[1:] 77 | case func(C): 78 | return x, items[1:] 79 | case func(): 80 | return func(C) { x() }, items[1:] 81 | } 82 | conveyPanic(parseError) 83 | panic("never get here") 84 | } 85 | func parseSpecifier(items []interface{}) (actionSpecifier, []interface{}) { 86 | if len(items) == 0 { 87 | return noSpecifier, items 88 | } 89 | if spec, ok := items[0].(actionSpecifier); ok { 90 | return spec, items[1:] 91 | } 92 | conveyPanic(parseError) 93 | panic("never get here") 94 | } 95 | 96 | // This interface allows us to pass the *testing.T struct 97 | // throughout the internals of this package without ever 98 | // having to import the "testing" package. 99 | type t interface { 100 | Fail() 101 | } 102 | 103 | const parseError = "You must provide a name (string), then a *testing.T (if in outermost scope), an optional FailureMode, and then an action (func())." 104 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/goconvey/convey/doc.go: -------------------------------------------------------------------------------- 1 | // Package convey contains all of the public-facing entry points to this project. 2 | // This means that it should never be required of the user to import any other 3 | // packages from this project as they serve internal purposes. 4 | package convey 5 | 6 | import "github.com/smartystreets/goconvey/convey/reporting" 7 | 8 | ////////////////////////////////// suite ////////////////////////////////// 9 | 10 | // C is the Convey context which you can optionally obtain in your action 11 | // by calling Convey like: 12 | // 13 | // Convey(..., func(c C) { 14 | // ... 15 | // }) 16 | // 17 | // See the documentation on Convey for more details. 18 | // 19 | // All methods in this context behave identically to the global functions of the 20 | // same name in this package. 21 | type C interface { 22 | Convey(items ...interface{}) 23 | SkipConvey(items ...interface{}) 24 | FocusConvey(items ...interface{}) 25 | 26 | So(actual interface{}, assert assertion, expected ...interface{}) 27 | SkipSo(stuff ...interface{}) 28 | 29 | Reset(action func()) 30 | 31 | Println(items ...interface{}) (int, error) 32 | Print(items ...interface{}) (int, error) 33 | Printf(format string, items ...interface{}) (int, error) 34 | } 35 | 36 | // Convey is the method intended for use when declaring the scopes of 37 | // a specification. Each scope has a description and a func() which may contain 38 | // other calls to Convey(), Reset() or Should-style assertions. Convey calls can 39 | // be nested as far as you see fit. 40 | // 41 | // IMPORTANT NOTE: The top-level Convey() within a Test method 42 | // must conform to the following signature: 43 | // 44 | // Convey(description string, t *testing.T, action func()) 45 | // 46 | // All other calls should look like this (no need to pass in *testing.T): 47 | // 48 | // Convey(description string, action func()) 49 | // 50 | // Don't worry, goconvey will panic if you get it wrong so you can fix it. 51 | // 52 | // Additionally, you may explicitly obtain access to the Convey context by doing: 53 | // 54 | // Convey(description string, action func(c C)) 55 | // 56 | // You may need to do this if you want to pass the context through to a 57 | // goroutine, or to close over the context in a handler to a library which 58 | // calls your handler in a goroutine (httptest comes to mind). 59 | // 60 | // All Convey()-blocks also accept an optional parameter of FailureMode which sets 61 | // how goconvey should treat failures for So()-assertions in the block and 62 | // nested blocks. See the constants in this file for the available options. 63 | // 64 | // By default it will inherit from its parent block and the top-level blocks 65 | // default to the FailureHalts setting. 66 | // 67 | // This parameter is inserted before the block itself: 68 | // 69 | // Convey(description string, t *testing.T, mode FailureMode, action func()) 70 | // Convey(description string, mode FailureMode, action func()) 71 | // 72 | // See the examples package for, well, examples. 73 | func Convey(items ...interface{}) { 74 | if ctx := getCurrentContext(); ctx == nil { 75 | rootConvey(items...) 76 | } else { 77 | ctx.Convey(items...) 78 | } 79 | } 80 | 81 | // SkipConvey is analagous to Convey except that the scope is not executed 82 | // (which means that child scopes defined within this scope are not run either). 83 | // The reporter will be notified that this step was skipped. 84 | func SkipConvey(items ...interface{}) { 85 | Convey(append(items, skipConvey)...) 86 | } 87 | 88 | // FocusConvey is has the inverse effect of SkipConvey. If the top-level 89 | // Convey is changed to `FocusConvey`, only nested scopes that are defined 90 | // with FocusConvey will be run. The rest will be ignored completely. This 91 | // is handy when debugging a large suite that runs a misbehaving function 92 | // repeatedly as you can disable all but one of that function 93 | // without swaths of `SkipConvey` calls, just a targeted chain of calls 94 | // to FocusConvey. 95 | func FocusConvey(items ...interface{}) { 96 | Convey(append(items, focusConvey)...) 97 | } 98 | 99 | // Reset registers a cleanup function to be run after each Convey() 100 | // in the same scope. See the examples package for a simple use case. 101 | func Reset(action func()) { 102 | mustGetCurrentContext().Reset(action) 103 | } 104 | 105 | /////////////////////////////////// Assertions /////////////////////////////////// 106 | 107 | // assertion is an alias for a function with a signature that the convey.So() 108 | // method can handle. Any future or custom assertions should conform to this 109 | // method signature. The return value should be an empty string if the assertion 110 | // passes and a well-formed failure message if not. 111 | type assertion func(actual interface{}, expected ...interface{}) string 112 | 113 | const assertionSuccess = "" 114 | 115 | // So is the means by which assertions are made against the system under test. 116 | // The majority of exported names in the assertions package begin with the word 117 | // 'Should' and describe how the first argument (actual) should compare with any 118 | // of the final (expected) arguments. How many final arguments are accepted 119 | // depends on the particular assertion that is passed in as the assert argument. 120 | // See the examples package for use cases and the assertions package for 121 | // documentation on specific assertion methods. A failing assertion will 122 | // cause t.Fail() to be invoked--you should never call this method (or other 123 | // failure-inducing methods) in your test code. Leave that to GoConvey. 124 | func So(actual interface{}, assert assertion, expected ...interface{}) { 125 | mustGetCurrentContext().So(actual, assert, expected...) 126 | } 127 | 128 | // SkipSo is analagous to So except that the assertion that would have been passed 129 | // to So is not executed and the reporter is notified that the assertion was skipped. 130 | func SkipSo(stuff ...interface{}) { 131 | mustGetCurrentContext().SkipSo() 132 | } 133 | 134 | // FailureMode is a type which determines how the So() blocks should fail 135 | // if their assertion fails. See constants further down for acceptable values 136 | type FailureMode string 137 | 138 | const ( 139 | 140 | // FailureContinues is a failure mode which prevents failing 141 | // So()-assertions from halting Convey-block execution, instead 142 | // allowing the test to continue past failing So()-assertions. 143 | FailureContinues FailureMode = "continue" 144 | 145 | // FailureHalts is the default setting for a top-level Convey()-block 146 | // and will cause all failing So()-assertions to halt further execution 147 | // in that test-arm and continue on to the next arm. 148 | FailureHalts FailureMode = "halt" 149 | 150 | // FailureInherits is the default setting for failure-mode, it will 151 | // default to the failure-mode of the parent block. You should never 152 | // need to specify this mode in your tests.. 153 | FailureInherits FailureMode = "inherits" 154 | ) 155 | 156 | func (f FailureMode) combine(other FailureMode) FailureMode { 157 | if other == FailureInherits { 158 | return f 159 | } 160 | return other 161 | } 162 | 163 | var defaultFailureMode FailureMode = FailureHalts 164 | 165 | // SetDefaultFailureMode allows you to specify the default failure mode 166 | // for all Convey blocks. It is meant to be used in an init function to 167 | // allow the default mode to be changdd across all tests for an entire packgae 168 | // but it can be used anywhere. 169 | func SetDefaultFailureMode(mode FailureMode) { 170 | if mode == FailureContinues || mode == FailureHalts { 171 | defaultFailureMode = mode 172 | } else { 173 | panic("You may only use the constants named 'FailureContinues' and 'FailureHalts' as default failure modes.") 174 | } 175 | } 176 | 177 | //////////////////////////////////// Print functions //////////////////////////////////// 178 | 179 | // Print is analogous to fmt.Print (and it even calls fmt.Print). It ensures that 180 | // output is aligned with the corresponding scopes in the web UI. 181 | func Print(items ...interface{}) (written int, err error) { 182 | return mustGetCurrentContext().Print(items...) 183 | } 184 | 185 | // Print is analogous to fmt.Println (and it even calls fmt.Println). It ensures that 186 | // output is aligned with the corresponding scopes in the web UI. 187 | func Println(items ...interface{}) (written int, err error) { 188 | return mustGetCurrentContext().Println(items...) 189 | } 190 | 191 | // Print is analogous to fmt.Printf (and it even calls fmt.Printf). It ensures that 192 | // output is aligned with the corresponding scopes in the web UI. 193 | func Printf(format string, items ...interface{}) (written int, err error) { 194 | return mustGetCurrentContext().Printf(format, items...) 195 | } 196 | 197 | /////////////////////////////////////////////////////////////////////////////// 198 | 199 | // SuppressConsoleStatistics prevents automatic printing of console statistics. 200 | // Calling PrintConsoleStatistics explicitly will force printing of statistics. 201 | func SuppressConsoleStatistics() { 202 | reporting.SuppressConsoleStatistics() 203 | } 204 | 205 | // ConsoleStatistics may be called at any time to print assertion statistics. 206 | // Generally, the best place to do this would be in a TestMain function, 207 | // after all tests have been run. Something like this: 208 | // 209 | // func TestMain(m *testing.M) { 210 | // convey.SuppressConsoleStatistics() 211 | // result := m.Run() 212 | // convey.PrintConsoleStatistics() 213 | // os.Exit(result) 214 | // } 215 | // 216 | func PrintConsoleStatistics() { 217 | reporting.PrintConsoleStatistics() 218 | } 219 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/goconvey/convey/gotest/utils.go: -------------------------------------------------------------------------------- 1 | // Package gotest contains internal functionality. Although this package 2 | // contains one or more exported names it is not intended for public 3 | // consumption. See the examples package for how to use this project. 4 | package gotest 5 | 6 | import ( 7 | "runtime" 8 | "strings" 9 | ) 10 | 11 | func ResolveExternalCaller() (file string, line int, name string) { 12 | var caller_id uintptr 13 | callers := runtime.Callers(0, callStack) 14 | 15 | for x := 0; x < callers; x++ { 16 | caller_id, file, line, _ = runtime.Caller(x) 17 | if strings.HasSuffix(file, "_test.go") || strings.HasSuffix(file, "_tests.go") { 18 | name = runtime.FuncForPC(caller_id).Name() 19 | return 20 | } 21 | } 22 | file, line, name = "", -1, "" 23 | return // panic? 24 | } 25 | 26 | const maxStackDepth = 100 // This had better be enough... 27 | 28 | var callStack []uintptr = make([]uintptr, maxStackDepth, maxStackDepth) 29 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/goconvey/convey/init.go: -------------------------------------------------------------------------------- 1 | package convey 2 | 3 | import ( 4 | "flag" 5 | "os" 6 | 7 | "github.com/jtolds/gls" 8 | "github.com/smartystreets/assertions" 9 | "github.com/smartystreets/goconvey/convey/reporting" 10 | ) 11 | 12 | func init() { 13 | assertions.GoConveyMode(true) 14 | 15 | declareFlags() 16 | 17 | ctxMgr = gls.NewContextManager() 18 | } 19 | 20 | func declareFlags() { 21 | flag.BoolVar(&json, "convey-json", false, "When true, emits results in JSON blocks. Default: 'false'") 22 | flag.BoolVar(&silent, "convey-silent", false, "When true, all output from GoConvey is suppressed.") 23 | flag.BoolVar(&story, "convey-story", false, "When true, emits story output, otherwise emits dot output. When not provided, this flag mirros the value of the '-test.v' flag") 24 | 25 | if noStoryFlagProvided() { 26 | story = verboseEnabled 27 | } 28 | 29 | // FYI: flag.Parse() is called from the testing package. 30 | } 31 | 32 | func noStoryFlagProvided() bool { 33 | return !story && !storyDisabled 34 | } 35 | 36 | func buildReporter() reporting.Reporter { 37 | selectReporter := os.Getenv("GOCONVEY_REPORTER") 38 | 39 | switch { 40 | case testReporter != nil: 41 | return testReporter 42 | case json || selectReporter == "json": 43 | return reporting.BuildJsonReporter() 44 | case silent || selectReporter == "silent": 45 | return reporting.BuildSilentReporter() 46 | case selectReporter == "dot": 47 | // Story is turned on when verbose is set, so we need to check for dot reporter first. 48 | return reporting.BuildDotReporter() 49 | case story || selectReporter == "story": 50 | return reporting.BuildStoryReporter() 51 | default: 52 | return reporting.BuildDotReporter() 53 | } 54 | } 55 | 56 | var ( 57 | ctxMgr *gls.ContextManager 58 | 59 | // only set by internal tests 60 | testReporter reporting.Reporter 61 | ) 62 | 63 | var ( 64 | json bool 65 | silent bool 66 | story bool 67 | 68 | verboseEnabled = flagFound("-test.v=true") 69 | storyDisabled = flagFound("-story=false") 70 | ) 71 | 72 | // flagFound parses the command line args manually for flags defined in other 73 | // packages. Like the '-v' flag from the "testing" package, for instance. 74 | func flagFound(flagValue string) bool { 75 | for _, arg := range os.Args { 76 | if arg == flagValue { 77 | return true 78 | } 79 | } 80 | return false 81 | } 82 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/goconvey/convey/nilReporter.go: -------------------------------------------------------------------------------- 1 | package convey 2 | 3 | import ( 4 | "github.com/smartystreets/goconvey/convey/reporting" 5 | ) 6 | 7 | type nilReporter struct{} 8 | 9 | func (self *nilReporter) BeginStory(story *reporting.StoryReport) {} 10 | func (self *nilReporter) Enter(scope *reporting.ScopeReport) {} 11 | func (self *nilReporter) Report(report *reporting.AssertionResult) {} 12 | func (self *nilReporter) Exit() {} 13 | func (self *nilReporter) EndStory() {} 14 | func (self *nilReporter) Write(p []byte) (int, error) { return len(p), nil } 15 | func newNilReporter() *nilReporter { return &nilReporter{} } 16 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/goconvey/convey/reporting/console.go: -------------------------------------------------------------------------------- 1 | package reporting 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | ) 7 | 8 | type console struct{} 9 | 10 | func (self *console) Write(p []byte) (n int, err error) { 11 | return fmt.Print(string(p)) 12 | } 13 | 14 | func NewConsole() io.Writer { 15 | return new(console) 16 | } 17 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/goconvey/convey/reporting/doc.go: -------------------------------------------------------------------------------- 1 | // Package reporting contains internal functionality related 2 | // to console reporting and output. Although this package has 3 | // exported names is not intended for public consumption. See the 4 | // examples package for how to use this project. 5 | package reporting 6 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/goconvey/convey/reporting/dot.go: -------------------------------------------------------------------------------- 1 | package reporting 2 | 3 | import "fmt" 4 | 5 | type dot struct{ out *Printer } 6 | 7 | func (self *dot) BeginStory(story *StoryReport) {} 8 | 9 | func (self *dot) Enter(scope *ScopeReport) {} 10 | 11 | func (self *dot) Report(report *AssertionResult) { 12 | if report.Error != nil { 13 | fmt.Print(redColor) 14 | self.out.Insert(dotError) 15 | } else if report.Failure != "" { 16 | fmt.Print(yellowColor) 17 | self.out.Insert(dotFailure) 18 | } else if report.Skipped { 19 | fmt.Print(yellowColor) 20 | self.out.Insert(dotSkip) 21 | } else { 22 | fmt.Print(greenColor) 23 | self.out.Insert(dotSuccess) 24 | } 25 | fmt.Print(resetColor) 26 | } 27 | 28 | func (self *dot) Exit() {} 29 | 30 | func (self *dot) EndStory() {} 31 | 32 | func (self *dot) Write(content []byte) (written int, err error) { 33 | return len(content), nil // no-op 34 | } 35 | 36 | func NewDotReporter(out *Printer) *dot { 37 | self := new(dot) 38 | self.out = out 39 | return self 40 | } 41 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/goconvey/convey/reporting/gotest.go: -------------------------------------------------------------------------------- 1 | package reporting 2 | 3 | type gotestReporter struct{ test T } 4 | 5 | func (self *gotestReporter) BeginStory(story *StoryReport) { 6 | self.test = story.Test 7 | } 8 | 9 | func (self *gotestReporter) Enter(scope *ScopeReport) {} 10 | 11 | func (self *gotestReporter) Report(r *AssertionResult) { 12 | if !passed(r) { 13 | self.test.Fail() 14 | } 15 | } 16 | 17 | func (self *gotestReporter) Exit() {} 18 | 19 | func (self *gotestReporter) EndStory() { 20 | self.test = nil 21 | } 22 | 23 | func (self *gotestReporter) Write(content []byte) (written int, err error) { 24 | return len(content), nil // no-op 25 | } 26 | 27 | func NewGoTestReporter() *gotestReporter { 28 | return new(gotestReporter) 29 | } 30 | 31 | func passed(r *AssertionResult) bool { 32 | return r.Error == nil && r.Failure == "" 33 | } 34 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/goconvey/convey/reporting/init.go: -------------------------------------------------------------------------------- 1 | package reporting 2 | 3 | import ( 4 | "os" 5 | "runtime" 6 | "strings" 7 | ) 8 | 9 | func init() { 10 | if !isColorableTerminal() { 11 | monochrome() 12 | } 13 | 14 | if runtime.GOOS == "windows" { 15 | success, failure, error_ = dotSuccess, dotFailure, dotError 16 | } 17 | } 18 | 19 | func BuildJsonReporter() Reporter { 20 | out := NewPrinter(NewConsole()) 21 | return NewReporters( 22 | NewGoTestReporter(), 23 | NewJsonReporter(out)) 24 | } 25 | func BuildDotReporter() Reporter { 26 | out := NewPrinter(NewConsole()) 27 | return NewReporters( 28 | NewGoTestReporter(), 29 | NewDotReporter(out), 30 | NewProblemReporter(out), 31 | consoleStatistics) 32 | } 33 | func BuildStoryReporter() Reporter { 34 | out := NewPrinter(NewConsole()) 35 | return NewReporters( 36 | NewGoTestReporter(), 37 | NewStoryReporter(out), 38 | NewProblemReporter(out), 39 | consoleStatistics) 40 | } 41 | func BuildSilentReporter() Reporter { 42 | out := NewPrinter(NewConsole()) 43 | return NewReporters( 44 | NewGoTestReporter(), 45 | NewSilentProblemReporter(out)) 46 | } 47 | 48 | var ( 49 | newline = "\n" 50 | success = "✔" 51 | failure = "✘" 52 | error_ = "🔥" 53 | skip = "⚠" 54 | dotSuccess = "." 55 | dotFailure = "x" 56 | dotError = "E" 57 | dotSkip = "S" 58 | errorTemplate = "* %s \nLine %d: - %v \n%s\n" 59 | failureTemplate = "* %s \nLine %d:\n%s\n" 60 | ) 61 | 62 | var ( 63 | greenColor = "\033[32m" 64 | yellowColor = "\033[33m" 65 | redColor = "\033[31m" 66 | resetColor = "\033[0m" 67 | ) 68 | 69 | var consoleStatistics = NewStatisticsReporter(NewPrinter(NewConsole())) 70 | 71 | func SuppressConsoleStatistics() { consoleStatistics.Suppress() } 72 | func PrintConsoleStatistics() { consoleStatistics.PrintSummary() } 73 | 74 | // QuiteMode disables all console output symbols. This is only meant to be used 75 | // for tests that are internal to goconvey where the output is distracting or 76 | // otherwise not needed in the test output. 77 | func QuietMode() { 78 | success, failure, error_, skip, dotSuccess, dotFailure, dotError, dotSkip = "", "", "", "", "", "", "", "" 79 | } 80 | 81 | func monochrome() { 82 | greenColor, yellowColor, redColor, resetColor = "", "", "", "" 83 | } 84 | 85 | func isColorableTerminal() bool { 86 | return strings.Contains(os.Getenv("TERM"), "color") 87 | } 88 | 89 | // This interface allows us to pass the *testing.T struct 90 | // throughout the internals of this tool without ever 91 | // having to import the "testing" package. 92 | type T interface { 93 | Fail() 94 | } 95 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/goconvey/convey/reporting/json.go: -------------------------------------------------------------------------------- 1 | // TODO: under unit test 2 | 3 | package reporting 4 | 5 | import ( 6 | "bytes" 7 | "encoding/json" 8 | "fmt" 9 | "strings" 10 | ) 11 | 12 | type JsonReporter struct { 13 | out *Printer 14 | currentKey []string 15 | current *ScopeResult 16 | index map[string]*ScopeResult 17 | scopes []*ScopeResult 18 | } 19 | 20 | func (self *JsonReporter) depth() int { return len(self.currentKey) } 21 | 22 | func (self *JsonReporter) BeginStory(story *StoryReport) {} 23 | 24 | func (self *JsonReporter) Enter(scope *ScopeReport) { 25 | self.currentKey = append(self.currentKey, scope.Title) 26 | ID := strings.Join(self.currentKey, "|") 27 | if _, found := self.index[ID]; !found { 28 | next := newScopeResult(scope.Title, self.depth(), scope.File, scope.Line) 29 | self.scopes = append(self.scopes, next) 30 | self.index[ID] = next 31 | } 32 | self.current = self.index[ID] 33 | } 34 | 35 | func (self *JsonReporter) Report(report *AssertionResult) { 36 | self.current.Assertions = append(self.current.Assertions, report) 37 | } 38 | 39 | func (self *JsonReporter) Exit() { 40 | self.currentKey = self.currentKey[:len(self.currentKey)-1] 41 | } 42 | 43 | func (self *JsonReporter) EndStory() { 44 | self.report() 45 | self.reset() 46 | } 47 | func (self *JsonReporter) report() { 48 | scopes := []string{} 49 | for _, scope := range self.scopes { 50 | serialized, err := json.Marshal(scope) 51 | if err != nil { 52 | self.out.Println(jsonMarshalFailure) 53 | panic(err) 54 | } 55 | var buffer bytes.Buffer 56 | json.Indent(&buffer, serialized, "", " ") 57 | scopes = append(scopes, buffer.String()) 58 | } 59 | self.out.Print(fmt.Sprintf("%s\n%s,\n%s\n", OpenJson, strings.Join(scopes, ","), CloseJson)) 60 | } 61 | func (self *JsonReporter) reset() { 62 | self.scopes = []*ScopeResult{} 63 | self.index = map[string]*ScopeResult{} 64 | self.currentKey = nil 65 | } 66 | 67 | func (self *JsonReporter) Write(content []byte) (written int, err error) { 68 | self.current.Output += string(content) 69 | return len(content), nil 70 | } 71 | 72 | func NewJsonReporter(out *Printer) *JsonReporter { 73 | self := new(JsonReporter) 74 | self.out = out 75 | self.reset() 76 | return self 77 | } 78 | 79 | const OpenJson = ">->->OPEN-JSON->->->" // "⌦" 80 | const CloseJson = "<-<-<-CLOSE-JSON<-<-<" // "⌫" 81 | const jsonMarshalFailure = ` 82 | 83 | GOCONVEY_JSON_MARSHALL_FAILURE: There was an error when attempting to convert test results to JSON. 84 | Please file a bug report and reference the code that caused this failure if possible. 85 | 86 | Here's the panic: 87 | 88 | ` 89 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/goconvey/convey/reporting/printer.go: -------------------------------------------------------------------------------- 1 | package reporting 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | "strings" 7 | ) 8 | 9 | type Printer struct { 10 | out io.Writer 11 | prefix string 12 | } 13 | 14 | func (self *Printer) Println(message string, values ...interface{}) { 15 | formatted := self.format(message, values...) + newline 16 | self.out.Write([]byte(formatted)) 17 | } 18 | 19 | func (self *Printer) Print(message string, values ...interface{}) { 20 | formatted := self.format(message, values...) 21 | self.out.Write([]byte(formatted)) 22 | } 23 | 24 | func (self *Printer) Insert(text string) { 25 | self.out.Write([]byte(text)) 26 | } 27 | 28 | func (self *Printer) format(message string, values ...interface{}) string { 29 | var formatted string 30 | if len(values) == 0 { 31 | formatted = self.prefix + message 32 | } else { 33 | formatted = self.prefix + fmt.Sprintf(message, values...) 34 | } 35 | indented := strings.Replace(formatted, newline, newline+self.prefix, -1) 36 | return strings.TrimRight(indented, space) 37 | } 38 | 39 | func (self *Printer) Indent() { 40 | self.prefix += pad 41 | } 42 | 43 | func (self *Printer) Dedent() { 44 | if len(self.prefix) >= padLength { 45 | self.prefix = self.prefix[:len(self.prefix)-padLength] 46 | } 47 | } 48 | 49 | func NewPrinter(out io.Writer) *Printer { 50 | self := new(Printer) 51 | self.out = out 52 | return self 53 | } 54 | 55 | const space = " " 56 | const pad = space + space 57 | const padLength = len(pad) 58 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/goconvey/convey/reporting/problems.go: -------------------------------------------------------------------------------- 1 | package reporting 2 | 3 | import "fmt" 4 | 5 | type problem struct { 6 | silent bool 7 | out *Printer 8 | errors []*AssertionResult 9 | failures []*AssertionResult 10 | } 11 | 12 | func (self *problem) BeginStory(story *StoryReport) {} 13 | 14 | func (self *problem) Enter(scope *ScopeReport) {} 15 | 16 | func (self *problem) Report(report *AssertionResult) { 17 | if report.Error != nil { 18 | self.errors = append(self.errors, report) 19 | } else if report.Failure != "" { 20 | self.failures = append(self.failures, report) 21 | } 22 | } 23 | 24 | func (self *problem) Exit() {} 25 | 26 | func (self *problem) EndStory() { 27 | self.show(self.showErrors, redColor) 28 | self.show(self.showFailures, yellowColor) 29 | self.prepareForNextStory() 30 | } 31 | func (self *problem) show(display func(), color string) { 32 | if !self.silent { 33 | fmt.Print(color) 34 | } 35 | display() 36 | if !self.silent { 37 | fmt.Print(resetColor) 38 | } 39 | self.out.Dedent() 40 | } 41 | func (self *problem) showErrors() { 42 | for i, e := range self.errors { 43 | if i == 0 { 44 | self.out.Println("\nErrors:\n") 45 | self.out.Indent() 46 | } 47 | self.out.Println(errorTemplate, e.File, e.Line, e.Error, e.StackTrace) 48 | } 49 | } 50 | func (self *problem) showFailures() { 51 | for i, f := range self.failures { 52 | if i == 0 { 53 | self.out.Println("\nFailures:\n") 54 | self.out.Indent() 55 | } 56 | self.out.Println(failureTemplate, f.File, f.Line, f.Failure) 57 | } 58 | } 59 | 60 | func (self *problem) Write(content []byte) (written int, err error) { 61 | return len(content), nil // no-op 62 | } 63 | 64 | func NewProblemReporter(out *Printer) *problem { 65 | self := new(problem) 66 | self.out = out 67 | self.prepareForNextStory() 68 | return self 69 | } 70 | 71 | func NewSilentProblemReporter(out *Printer) *problem { 72 | self := NewProblemReporter(out) 73 | self.silent = true 74 | return self 75 | } 76 | 77 | func (self *problem) prepareForNextStory() { 78 | self.errors = []*AssertionResult{} 79 | self.failures = []*AssertionResult{} 80 | } 81 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/goconvey/convey/reporting/reporter.go: -------------------------------------------------------------------------------- 1 | package reporting 2 | 3 | import "io" 4 | 5 | type Reporter interface { 6 | BeginStory(story *StoryReport) 7 | Enter(scope *ScopeReport) 8 | Report(r *AssertionResult) 9 | Exit() 10 | EndStory() 11 | io.Writer 12 | } 13 | 14 | type reporters struct{ collection []Reporter } 15 | 16 | func (self *reporters) BeginStory(s *StoryReport) { self.foreach(func(r Reporter) { r.BeginStory(s) }) } 17 | func (self *reporters) Enter(s *ScopeReport) { self.foreach(func(r Reporter) { r.Enter(s) }) } 18 | func (self *reporters) Report(a *AssertionResult) { self.foreach(func(r Reporter) { r.Report(a) }) } 19 | func (self *reporters) Exit() { self.foreach(func(r Reporter) { r.Exit() }) } 20 | func (self *reporters) EndStory() { self.foreach(func(r Reporter) { r.EndStory() }) } 21 | 22 | func (self *reporters) Write(contents []byte) (written int, err error) { 23 | self.foreach(func(r Reporter) { 24 | written, err = r.Write(contents) 25 | }) 26 | return written, err 27 | } 28 | 29 | func (self *reporters) foreach(action func(Reporter)) { 30 | for _, r := range self.collection { 31 | action(r) 32 | } 33 | } 34 | 35 | func NewReporters(collection ...Reporter) *reporters { 36 | self := new(reporters) 37 | self.collection = collection 38 | return self 39 | } 40 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/goconvey/convey/reporting/reporting.goconvey: -------------------------------------------------------------------------------- 1 | #ignore 2 | -timeout=1s 3 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/goconvey/convey/reporting/reports.go: -------------------------------------------------------------------------------- 1 | package reporting 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "runtime" 7 | "strings" 8 | 9 | "github.com/smartystreets/goconvey/convey/gotest" 10 | ) 11 | 12 | ////////////////// ScopeReport //////////////////// 13 | 14 | type ScopeReport struct { 15 | Title string 16 | File string 17 | Line int 18 | } 19 | 20 | func NewScopeReport(title string) *ScopeReport { 21 | file, line, _ := gotest.ResolveExternalCaller() 22 | self := new(ScopeReport) 23 | self.Title = title 24 | self.File = file 25 | self.Line = line 26 | return self 27 | } 28 | 29 | ////////////////// ScopeResult //////////////////// 30 | 31 | type ScopeResult struct { 32 | Title string 33 | File string 34 | Line int 35 | Depth int 36 | Assertions []*AssertionResult 37 | Output string 38 | } 39 | 40 | func newScopeResult(title string, depth int, file string, line int) *ScopeResult { 41 | self := new(ScopeResult) 42 | self.Title = title 43 | self.Depth = depth 44 | self.File = file 45 | self.Line = line 46 | self.Assertions = []*AssertionResult{} 47 | return self 48 | } 49 | 50 | /////////////////// StoryReport ///////////////////// 51 | 52 | type StoryReport struct { 53 | Test T 54 | Name string 55 | File string 56 | Line int 57 | } 58 | 59 | func NewStoryReport(test T) *StoryReport { 60 | file, line, name := gotest.ResolveExternalCaller() 61 | name = removePackagePath(name) 62 | self := new(StoryReport) 63 | self.Test = test 64 | self.Name = name 65 | self.File = file 66 | self.Line = line 67 | return self 68 | } 69 | 70 | // name comes in looking like "github.com/smartystreets/goconvey/examples.TestName". 71 | // We only want the stuff after the last '.', which is the name of the test function. 72 | func removePackagePath(name string) string { 73 | parts := strings.Split(name, ".") 74 | return parts[len(parts)-1] 75 | } 76 | 77 | /////////////////// FailureView //////////////////////// 78 | 79 | // This struct is also declared in github.com/smartystreets/assertions. 80 | // The json struct tags should be equal in both declarations. 81 | type FailureView struct { 82 | Message string `json:"Message"` 83 | Expected string `json:"Expected"` 84 | Actual string `json:"Actual"` 85 | } 86 | 87 | ////////////////////AssertionResult ////////////////////// 88 | 89 | type AssertionResult struct { 90 | File string 91 | Line int 92 | Expected string 93 | Actual string 94 | Failure string 95 | Error interface{} 96 | StackTrace string 97 | Skipped bool 98 | } 99 | 100 | func NewFailureReport(failure string) *AssertionResult { 101 | report := new(AssertionResult) 102 | report.File, report.Line = caller() 103 | report.StackTrace = stackTrace() 104 | parseFailure(failure, report) 105 | return report 106 | } 107 | func parseFailure(failure string, report *AssertionResult) { 108 | view := new(FailureView) 109 | err := json.Unmarshal([]byte(failure), view) 110 | if err == nil { 111 | report.Failure = view.Message 112 | report.Expected = view.Expected 113 | report.Actual = view.Actual 114 | } else { 115 | report.Failure = failure 116 | } 117 | } 118 | func NewErrorReport(err interface{}) *AssertionResult { 119 | report := new(AssertionResult) 120 | report.File, report.Line = caller() 121 | report.StackTrace = fullStackTrace() 122 | report.Error = fmt.Sprintf("%v", err) 123 | return report 124 | } 125 | func NewSuccessReport() *AssertionResult { 126 | return new(AssertionResult) 127 | } 128 | func NewSkipReport() *AssertionResult { 129 | report := new(AssertionResult) 130 | report.File, report.Line = caller() 131 | report.StackTrace = fullStackTrace() 132 | report.Skipped = true 133 | return report 134 | } 135 | 136 | func caller() (file string, line int) { 137 | file, line, _ = gotest.ResolveExternalCaller() 138 | return 139 | } 140 | 141 | func stackTrace() string { 142 | buffer := make([]byte, 1024*64) 143 | n := runtime.Stack(buffer, false) 144 | return removeInternalEntries(string(buffer[:n])) 145 | } 146 | func fullStackTrace() string { 147 | buffer := make([]byte, 1024*64) 148 | n := runtime.Stack(buffer, true) 149 | return removeInternalEntries(string(buffer[:n])) 150 | } 151 | func removeInternalEntries(stack string) string { 152 | lines := strings.Split(stack, newline) 153 | filtered := []string{} 154 | for _, line := range lines { 155 | if !isExternal(line) { 156 | filtered = append(filtered, line) 157 | } 158 | } 159 | return strings.Join(filtered, newline) 160 | } 161 | func isExternal(line string) bool { 162 | for _, p := range internalPackages { 163 | if strings.Contains(line, p) { 164 | return true 165 | } 166 | } 167 | return false 168 | } 169 | 170 | // NOTE: any new packages that host goconvey packages will need to be added here! 171 | // An alternative is to scan the goconvey directory and then exclude stuff like 172 | // the examples package but that's nasty too. 173 | var internalPackages = []string{ 174 | "goconvey/assertions", 175 | "goconvey/convey", 176 | "goconvey/execution", 177 | "goconvey/gotest", 178 | "goconvey/reporting", 179 | } 180 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/goconvey/convey/reporting/statistics.go: -------------------------------------------------------------------------------- 1 | package reporting 2 | 3 | import ( 4 | "fmt" 5 | "sync" 6 | ) 7 | 8 | func (self *statistics) BeginStory(story *StoryReport) {} 9 | 10 | func (self *statistics) Enter(scope *ScopeReport) {} 11 | 12 | func (self *statistics) Report(report *AssertionResult) { 13 | self.Lock() 14 | defer self.Unlock() 15 | 16 | if !self.failing && report.Failure != "" { 17 | self.failing = true 18 | } 19 | if !self.erroring && report.Error != nil { 20 | self.erroring = true 21 | } 22 | if report.Skipped { 23 | self.skipped += 1 24 | } else { 25 | self.total++ 26 | } 27 | } 28 | 29 | func (self *statistics) Exit() {} 30 | 31 | func (self *statistics) EndStory() { 32 | self.Lock() 33 | defer self.Unlock() 34 | 35 | if !self.suppressed { 36 | self.printSummaryLocked() 37 | } 38 | } 39 | 40 | func (self *statistics) Suppress() { 41 | self.Lock() 42 | defer self.Unlock() 43 | self.suppressed = true 44 | } 45 | 46 | func (self *statistics) PrintSummary() { 47 | self.Lock() 48 | defer self.Unlock() 49 | self.printSummaryLocked() 50 | } 51 | 52 | func (self *statistics) printSummaryLocked() { 53 | self.reportAssertionsLocked() 54 | self.reportSkippedSectionsLocked() 55 | self.completeReportLocked() 56 | } 57 | func (self *statistics) reportAssertionsLocked() { 58 | self.decideColorLocked() 59 | self.out.Print("\n%d total %s", self.total, plural("assertion", self.total)) 60 | } 61 | func (self *statistics) decideColorLocked() { 62 | if self.failing && !self.erroring { 63 | fmt.Print(yellowColor) 64 | } else if self.erroring { 65 | fmt.Print(redColor) 66 | } else { 67 | fmt.Print(greenColor) 68 | } 69 | } 70 | func (self *statistics) reportSkippedSectionsLocked() { 71 | if self.skipped > 0 { 72 | fmt.Print(yellowColor) 73 | self.out.Print(" (one or more sections skipped)") 74 | } 75 | } 76 | func (self *statistics) completeReportLocked() { 77 | fmt.Print(resetColor) 78 | self.out.Print("\n") 79 | self.out.Print("\n") 80 | } 81 | 82 | func (self *statistics) Write(content []byte) (written int, err error) { 83 | return len(content), nil // no-op 84 | } 85 | 86 | func NewStatisticsReporter(out *Printer) *statistics { 87 | self := statistics{} 88 | self.out = out 89 | return &self 90 | } 91 | 92 | type statistics struct { 93 | sync.Mutex 94 | 95 | out *Printer 96 | total int 97 | failing bool 98 | erroring bool 99 | skipped int 100 | suppressed bool 101 | } 102 | 103 | func plural(word string, count int) string { 104 | if count == 1 { 105 | return word 106 | } 107 | return word + "s" 108 | } 109 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/goconvey/convey/reporting/story.go: -------------------------------------------------------------------------------- 1 | // TODO: in order for this reporter to be completely honest 2 | // we need to retrofit to be more like the json reporter such that: 3 | // 1. it maintains ScopeResult collections, which count assertions 4 | // 2. it reports only after EndStory(), so that all tick marks 5 | // are placed near the appropriate title. 6 | // 3. Under unit test 7 | 8 | package reporting 9 | 10 | import ( 11 | "fmt" 12 | "strings" 13 | ) 14 | 15 | type story struct { 16 | out *Printer 17 | titlesById map[string]string 18 | currentKey []string 19 | } 20 | 21 | func (self *story) BeginStory(story *StoryReport) {} 22 | 23 | func (self *story) Enter(scope *ScopeReport) { 24 | self.out.Indent() 25 | 26 | self.currentKey = append(self.currentKey, scope.Title) 27 | ID := strings.Join(self.currentKey, "|") 28 | 29 | if _, found := self.titlesById[ID]; !found { 30 | self.out.Println("") 31 | self.out.Print(scope.Title) 32 | self.out.Insert(" ") 33 | self.titlesById[ID] = scope.Title 34 | } 35 | } 36 | 37 | func (self *story) Report(report *AssertionResult) { 38 | if report.Error != nil { 39 | fmt.Print(redColor) 40 | self.out.Insert(error_) 41 | } else if report.Failure != "" { 42 | fmt.Print(yellowColor) 43 | self.out.Insert(failure) 44 | } else if report.Skipped { 45 | fmt.Print(yellowColor) 46 | self.out.Insert(skip) 47 | } else { 48 | fmt.Print(greenColor) 49 | self.out.Insert(success) 50 | } 51 | fmt.Print(resetColor) 52 | } 53 | 54 | func (self *story) Exit() { 55 | self.out.Dedent() 56 | self.currentKey = self.currentKey[:len(self.currentKey)-1] 57 | } 58 | 59 | func (self *story) EndStory() { 60 | self.titlesById = make(map[string]string) 61 | self.out.Println("\n") 62 | } 63 | 64 | func (self *story) Write(content []byte) (written int, err error) { 65 | return len(content), nil // no-op 66 | } 67 | 68 | func NewStoryReporter(out *Printer) *story { 69 | self := new(story) 70 | self.out = out 71 | self.titlesById = make(map[string]string) 72 | return self 73 | } 74 | -------------------------------------------------------------------------------- /vendor/github.com/smartystreets/goconvey/web/client/resources/fonts/Open_Sans/LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | --------------------------------------------------------------------------------