diff -Nru golang-gomega-1.9.0/CHANGELOG.md golang-gomega-1.10.3/CHANGELOG.md --- golang-gomega-1.9.0/CHANGELOG.md 2020-02-01 10:40:48.000000000 +0000 +++ golang-gomega-1.10.3/CHANGELOG.md 2020-10-12 17:54:53.000000000 +0000 @@ -1,3 +1,26 @@ +## 1.10.3 + +### Fixes +- updates golang/x/net to fix vulnerability detected by snyk (#394) [c479356] + +## 1.10.2 + +### Fixes +- Add ExpectWithOffset, EventuallyWithOffset and ConsistentlyWithOffset to WithT (#391) [990941a] + +## 1.10.1 + +### Fixes +- Update dependencies (#389) [9f5eecd] + +## 1.10.0 + +### Features +- Add HaveHTTPStatusMatcher (#378) [f335c94] +- Changed matcher for content-type in VerifyJSONRepresenting (#377) [6024f5b] +- Make ghttp usable with x-unit style tests (#376) [c0be499] +- Implement PanicWith matcher (#381) [f8032b4] + ## 1.9.0 ### Features diff -Nru golang-gomega-1.9.0/debian/changelog golang-gomega-1.10.3/debian/changelog --- golang-gomega-1.9.0/debian/changelog 2020-02-07 11:40:31.000000000 +0000 +++ golang-gomega-1.10.3/debian/changelog 2020-11-22 10:39:13.000000000 +0000 @@ -1,3 +1,21 @@ +golang-gomega (1.10.3-1) unstable; urgency=medium + + * Team upload. + + [ Debian Janitor ] + * Trim trailing whitespace. + * Set upstream metadata fields: Bug-Database, Bug-Submit, Repository, + Repository-Browse. + + [ Roger Shimizu ] + * New upstream release v1.10.3 + * debian/watch: + - Update watch file format version to 4 + * debian/control: + - Add Testsuite: autopkgtest-pkg-go + + -- Roger Shimizu Sun, 22 Nov 2020 19:39:13 +0900 + golang-gomega (1.9.0-1) unstable; urgency=medium * Team upload. diff -Nru golang-gomega-1.9.0/debian/control golang-gomega-1.10.3/debian/control --- golang-gomega-1.9.0/debian/control 2020-02-07 11:40:31.000000000 +0000 +++ golang-gomega-1.10.3/debian/control 2020-11-22 10:39:13.000000000 +0000 @@ -1,5 +1,6 @@ Source: golang-gomega Section: devel +Testsuite: autopkgtest-pkg-go Priority: optional Maintainer: Debian Go Packaging Team Uploaders: Martín Ferrari , diff -Nru golang-gomega-1.9.0/debian/rules golang-gomega-1.10.3/debian/rules --- golang-gomega-1.9.0/debian/rules 2020-02-07 11:40:31.000000000 +0000 +++ golang-gomega-1.10.3/debian/rules 2020-11-22 10:39:13.000000000 +0000 @@ -6,4 +6,3 @@ # There is a circular dependency between gomega and ginkgo during testing, so # skip tests. override_dh_auto_test: - diff -Nru golang-gomega-1.9.0/debian/upstream/metadata golang-gomega-1.10.3/debian/upstream/metadata --- golang-gomega-1.9.0/debian/upstream/metadata 1970-01-01 00:00:00.000000000 +0000 +++ golang-gomega-1.10.3/debian/upstream/metadata 2020-11-22 10:39:13.000000000 +0000 @@ -0,0 +1,5 @@ +--- +Bug-Database: https://github.com/onsi/gomega/issues +Bug-Submit: https://github.com/onsi/gomega/issues/new +Repository: https://github.com/onsi/gomega.git +Repository-Browse: https://github.com/onsi/gomega diff -Nru golang-gomega-1.9.0/debian/watch golang-gomega-1.10.3/debian/watch --- golang-gomega-1.9.0/debian/watch 2020-02-07 11:40:31.000000000 +0000 +++ golang-gomega-1.10.3/debian/watch 2020-11-22 10:39:13.000000000 +0000 @@ -1,4 +1,3 @@ -version=3 - -opts="filenamemangle=s/(?:.*\/)?v?(\d[\d\.]*)\.tar\.gz/gomega-$1.tar.gz/" \ +version=4 +opts="filenamemangle=s/(?:.*\/)?v?(\d[\d\.]*)\.tar\.gz/golang-gomega_$1.orig.tar.gz/" \ https://github.com/onsi/gomega/tags (?:.*/)?v?(\d[\d\.]*)\.tar\.gz diff -Nru golang-gomega-1.9.0/ghttp/handlers.go golang-gomega-1.10.3/ghttp/handlers.go --- golang-gomega-1.9.0/ghttp/handlers.go 2020-02-01 10:40:48.000000000 +0000 +++ golang-gomega-1.10.3/ghttp/handlers.go 2020-10-12 17:54:53.000000000 +0000 @@ -13,10 +13,21 @@ "strings" "github.com/golang/protobuf/proto" + "github.com/onsi/gomega" . "github.com/onsi/gomega" "github.com/onsi/gomega/types" ) +type GHTTPWithGomega struct { + gomega Gomega +} + +func NewGHTTPWithGomega(gomega Gomega) *GHTTPWithGomega { + return &GHTTPWithGomega{ + gomega: gomega, + } +} + //CombineHandler takes variadic list of handlers and produces one handler //that calls each handler in order. func CombineHandlers(handlers ...http.HandlerFunc) http.HandlerFunc { @@ -32,51 +43,51 @@ // //For path, you may pass in a string, in which case strict equality will be applied //Alternatively you can pass in a matcher (ContainSubstring("/foo") and MatchRegexp("/foo/[a-f0-9]+") for example) -func VerifyRequest(method string, path interface{}, rawQuery ...string) http.HandlerFunc { +func (g GHTTPWithGomega) VerifyRequest(method string, path interface{}, rawQuery ...string) http.HandlerFunc { return func(w http.ResponseWriter, req *http.Request) { - Expect(req.Method).Should(Equal(method), "Method mismatch") + g.gomega.Expect(req.Method).Should(Equal(method), "Method mismatch") switch p := path.(type) { case types.GomegaMatcher: - Expect(req.URL.Path).Should(p, "Path mismatch") + g.gomega.Expect(req.URL.Path).Should(p, "Path mismatch") default: - Expect(req.URL.Path).Should(Equal(path), "Path mismatch") + g.gomega.Expect(req.URL.Path).Should(Equal(path), "Path mismatch") } if len(rawQuery) > 0 { values, err := url.ParseQuery(rawQuery[0]) - Expect(err).ShouldNot(HaveOccurred(), "Expected RawQuery is malformed") + g.gomega.Expect(err).ShouldNot(HaveOccurred(), "Expected RawQuery is malformed") - Expect(req.URL.Query()).Should(Equal(values), "RawQuery mismatch") + g.gomega.Expect(req.URL.Query()).Should(Equal(values), "RawQuery mismatch") } } } //VerifyContentType returns a handler that verifies that a request has a Content-Type header set to the //specified value -func VerifyContentType(contentType string) http.HandlerFunc { +func (g GHTTPWithGomega) VerifyContentType(contentType string) http.HandlerFunc { return func(w http.ResponseWriter, req *http.Request) { - Expect(req.Header.Get("Content-Type")).Should(Equal(contentType)) + g.gomega.Expect(req.Header.Get("Content-Type")).Should(Equal(contentType)) } } //VerifyMimeType returns a handler that verifies that a request has a specified mime type set //in Content-Type header -func VerifyMimeType(mimeType string) http.HandlerFunc { +func (g GHTTPWithGomega) VerifyMimeType(mimeType string) http.HandlerFunc { return func(w http.ResponseWriter, req *http.Request) { - Expect(strings.Split(req.Header.Get("Content-Type"), ";")[0]).Should(Equal(mimeType)) + g.gomega.Expect(strings.Split(req.Header.Get("Content-Type"), ";")[0]).Should(Equal(mimeType)) } } //VerifyBasicAuth returns a handler that verifies the request contains a BasicAuth Authorization header //matching the passed in username and password -func VerifyBasicAuth(username string, password string) http.HandlerFunc { +func (g GHTTPWithGomega) VerifyBasicAuth(username string, password string) http.HandlerFunc { return func(w http.ResponseWriter, req *http.Request) { auth := req.Header.Get("Authorization") - Expect(auth).ShouldNot(Equal(""), "Authorization header must be specified") + g.gomega.Expect(auth).ShouldNot(Equal(""), "Authorization header must be specified") decoded, err := base64.StdEncoding.DecodeString(auth[6:]) - Expect(err).ShouldNot(HaveOccurred()) + g.gomega.Expect(err).ShouldNot(HaveOccurred()) - Expect(string(decoded)).Should(Equal(fmt.Sprintf("%s:%s", username, password)), "Authorization mismatch") + g.gomega.Expect(string(decoded)).Should(Equal(fmt.Sprintf("%s:%s", username, password)), "Authorization mismatch") } } @@ -85,11 +96,11 @@ // //The request must contain *all* the passed in headers, but it is allowed to have additional headers //beyond the passed in set. -func VerifyHeader(header http.Header) http.HandlerFunc { +func (g GHTTPWithGomega) VerifyHeader(header http.Header) http.HandlerFunc { return func(w http.ResponseWriter, req *http.Request) { for key, values := range header { key = http.CanonicalHeaderKey(key) - Expect(req.Header[key]).Should(Equal(values), "Header mismatch for key: %s", key) + g.gomega.Expect(req.Header[key]).Should(Equal(values), "Header mismatch for key: %s", key) } } } @@ -97,19 +108,19 @@ //VerifyHeaderKV returns a handler that verifies the request contains a header matching the passed in key and values //(recall that a `http.Header` is a mapping from string (key) to []string (values)) //It is a convenience wrapper around `VerifyHeader` that allows you to avoid having to create an `http.Header` object. -func VerifyHeaderKV(key string, values ...string) http.HandlerFunc { +func (g GHTTPWithGomega) VerifyHeaderKV(key string, values ...string) http.HandlerFunc { return VerifyHeader(http.Header{key: values}) } //VerifyBody returns a handler that verifies that the body of the request matches the passed in byte array. //It does this using Equal(). -func VerifyBody(expectedBody []byte) http.HandlerFunc { +func (g GHTTPWithGomega) VerifyBody(expectedBody []byte) http.HandlerFunc { return CombineHandlers( func(w http.ResponseWriter, req *http.Request) { body, err := ioutil.ReadAll(req.Body) req.Body.Close() - Expect(err).ShouldNot(HaveOccurred()) - Expect(body).Should(Equal(expectedBody), "Body Mismatch") + g.gomega.Expect(err).ShouldNot(HaveOccurred()) + g.gomega.Expect(body).Should(Equal(expectedBody), "Body Mismatch") }, ) } @@ -118,14 +129,14 @@ //matching the passed in JSON string. It does this using Gomega's MatchJSON method // //VerifyJSON also verifies that the request's content type is application/json -func VerifyJSON(expectedJSON string) http.HandlerFunc { +func (g GHTTPWithGomega) VerifyJSON(expectedJSON string) http.HandlerFunc { return CombineHandlers( VerifyMimeType("application/json"), func(w http.ResponseWriter, req *http.Request) { body, err := ioutil.ReadAll(req.Body) req.Body.Close() - Expect(err).ShouldNot(HaveOccurred()) - Expect(body).Should(MatchJSON(expectedJSON), "JSON Mismatch") + g.gomega.Expect(err).ShouldNot(HaveOccurred()) + g.gomega.Expect(body).Should(MatchJSON(expectedJSON), "JSON Mismatch") }, ) } @@ -133,11 +144,11 @@ //VerifyJSONRepresenting is similar to VerifyJSON. Instead of taking a JSON string, however, it //takes an arbitrary JSON-encodable object and verifies that the requests's body is a JSON representation //that matches the object -func VerifyJSONRepresenting(object interface{}) http.HandlerFunc { +func (g GHTTPWithGomega) VerifyJSONRepresenting(object interface{}) http.HandlerFunc { data, err := json.Marshal(object) - Expect(err).ShouldNot(HaveOccurred()) + g.gomega.Expect(err).ShouldNot(HaveOccurred()) return CombineHandlers( - VerifyContentType("application/json"), + VerifyMimeType("application/json"), VerifyJSON(string(data)), ) } @@ -146,12 +157,12 @@ // //The request must contain *all* of the specified values, but it is allowed to have additional //form values beyond the passed in set. -func VerifyForm(values url.Values) http.HandlerFunc { +func (g GHTTPWithGomega) VerifyForm(values url.Values) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { err := r.ParseForm() - Expect(err).ShouldNot(HaveOccurred()) + g.gomega.Expect(err).ShouldNot(HaveOccurred()) for key, vals := range values { - Expect(r.Form[key]).Should(Equal(vals), "Form mismatch for key: %s", key) + g.gomega.Expect(r.Form[key]).Should(Equal(vals), "Form mismatch for key: %s", key) } } } @@ -159,7 +170,7 @@ //VerifyFormKV returns a handler that verifies a request contains a form key with the specified values. // //It is a convenience wrapper around `VerifyForm` that lets you avoid having to create a `url.Values` object. -func VerifyFormKV(key string, values ...string) http.HandlerFunc { +func (g GHTTPWithGomega) VerifyFormKV(key string, values ...string) http.HandlerFunc { return VerifyForm(url.Values{key: values}) } @@ -167,24 +178,24 @@ //representation of the passed message. // //VerifyProtoRepresenting also verifies that the request's content type is application/x-protobuf -func VerifyProtoRepresenting(expected proto.Message) http.HandlerFunc { +func (g GHTTPWithGomega) VerifyProtoRepresenting(expected proto.Message) http.HandlerFunc { return CombineHandlers( VerifyContentType("application/x-protobuf"), func(w http.ResponseWriter, req *http.Request) { body, err := ioutil.ReadAll(req.Body) - Expect(err).ShouldNot(HaveOccurred()) + g.gomega.Expect(err).ShouldNot(HaveOccurred()) req.Body.Close() expectedType := reflect.TypeOf(expected) actualValuePtr := reflect.New(expectedType.Elem()) actual, ok := actualValuePtr.Interface().(proto.Message) - Expect(ok).Should(BeTrue(), "Message value is not a proto.Message") + g.gomega.Expect(ok).Should(BeTrue(), "Message value is not a proto.Message") err = proto.Unmarshal(body, actual) - Expect(err).ShouldNot(HaveOccurred(), "Failed to unmarshal protobuf") + g.gomega.Expect(err).ShouldNot(HaveOccurred(), "Failed to unmarshal protobuf") - Expect(actual).Should(Equal(expected), "ProtoBuf Mismatch") + g.gomega.Expect(actual).Should(Equal(expected), "ProtoBuf Mismatch") }, ) } @@ -202,7 +213,7 @@ Also, RespondWith can be given an optional http.Header. The headers defined therein will be added to the response headers. */ -func RespondWith(statusCode int, body interface{}, optionalHeader ...http.Header) http.HandlerFunc { +func (g GHTTPWithGomega) RespondWith(statusCode int, body interface{}, optionalHeader ...http.Header) http.HandlerFunc { return func(w http.ResponseWriter, req *http.Request) { if len(optionalHeader) == 1 { copyHeader(optionalHeader[0], w.Header()) @@ -214,7 +225,7 @@ case []byte: w.Write(x) default: - Expect(body).Should(BeNil(), "Invalid type for body. Should be string or []byte.") + g.gomega.Expect(body).Should(BeNil(), "Invalid type for body. Should be string or []byte.") } } } @@ -228,7 +239,7 @@ Also, RespondWithPtr can be given an optional http.Header. The headers defined therein will be added to the response headers. Since the http.Header can be mutated after the fact you don't need to pass in a pointer. */ -func RespondWithPtr(statusCode *int, body interface{}, optionalHeader ...http.Header) http.HandlerFunc { +func (g GHTTPWithGomega) RespondWithPtr(statusCode *int, body interface{}, optionalHeader ...http.Header) http.HandlerFunc { return func(w http.ResponseWriter, req *http.Request) { if len(optionalHeader) == 1 { copyHeader(optionalHeader[0], w.Header()) @@ -241,7 +252,7 @@ case *[]byte: w.Write(*x) default: - Expect(body).Should(BeNil(), "Invalid type for body. Should be string or []byte.") + g.gomega.Expect(body).Should(BeNil(), "Invalid type for body. Should be string or []byte.") } } } @@ -253,9 +264,9 @@ Also, RespondWithJSONEncoded can be given an optional http.Header. The headers defined therein will be added to the response headers. */ -func RespondWithJSONEncoded(statusCode int, object interface{}, optionalHeader ...http.Header) http.HandlerFunc { +func (g GHTTPWithGomega) RespondWithJSONEncoded(statusCode int, object interface{}, optionalHeader ...http.Header) http.HandlerFunc { data, err := json.Marshal(object) - Expect(err).ShouldNot(HaveOccurred()) + g.gomega.Expect(err).ShouldNot(HaveOccurred()) var headers http.Header if len(optionalHeader) == 1 { @@ -279,10 +290,10 @@ Also, RespondWithJSONEncodedPtr can be given an optional http.Header. The headers defined therein will be added to the response headers. Since the http.Header can be mutated after the fact you don't need to pass in a pointer. */ -func RespondWithJSONEncodedPtr(statusCode *int, object interface{}, optionalHeader ...http.Header) http.HandlerFunc { +func (g GHTTPWithGomega) RespondWithJSONEncodedPtr(statusCode *int, object interface{}, optionalHeader ...http.Header) http.HandlerFunc { return func(w http.ResponseWriter, req *http.Request) { data, err := json.Marshal(object) - Expect(err).ShouldNot(HaveOccurred()) + g.gomega.Expect(err).ShouldNot(HaveOccurred()) var headers http.Header if len(optionalHeader) == 1 { headers = optionalHeader[0] @@ -302,10 +313,10 @@ //containing the protobuf serialization of the provided message. // //Also, RespondWithProto can be given an optional http.Header. The headers defined therein will be added to the response headers. -func RespondWithProto(statusCode int, message proto.Message, optionalHeader ...http.Header) http.HandlerFunc { +func (g GHTTPWithGomega) RespondWithProto(statusCode int, message proto.Message, optionalHeader ...http.Header) http.HandlerFunc { return func(w http.ResponseWriter, req *http.Request) { data, err := proto.Marshal(message) - Expect(err).ShouldNot(HaveOccurred()) + g.gomega.Expect(err).ShouldNot(HaveOccurred()) var headers http.Header if len(optionalHeader) == 1 { @@ -322,3 +333,71 @@ w.Write(data) } } + +func VerifyRequest(method string, path interface{}, rawQuery ...string) http.HandlerFunc { + return NewGHTTPWithGomega(gomega.Default).VerifyRequest(method, path, rawQuery...) +} + +func VerifyContentType(contentType string) http.HandlerFunc { + return NewGHTTPWithGomega(gomega.Default).VerifyContentType(contentType) +} + +func VerifyMimeType(mimeType string) http.HandlerFunc { + return NewGHTTPWithGomega(gomega.Default).VerifyMimeType(mimeType) +} + +func VerifyBasicAuth(username string, password string) http.HandlerFunc { + return NewGHTTPWithGomega(gomega.Default).VerifyBasicAuth(username, password) +} + +func VerifyHeader(header http.Header) http.HandlerFunc { + return NewGHTTPWithGomega(gomega.Default).VerifyHeader(header) +} + +func VerifyHeaderKV(key string, values ...string) http.HandlerFunc { + return NewGHTTPWithGomega(gomega.Default).VerifyHeaderKV(key, values...) +} + +func VerifyBody(expectedBody []byte) http.HandlerFunc { + return NewGHTTPWithGomega(gomega.Default).VerifyBody(expectedBody) +} + +func VerifyJSON(expectedJSON string) http.HandlerFunc { + return NewGHTTPWithGomega(gomega.Default).VerifyJSON(expectedJSON) +} + +func VerifyJSONRepresenting(object interface{}) http.HandlerFunc { + return NewGHTTPWithGomega(gomega.Default).VerifyJSONRepresenting(object) +} + +func VerifyForm(values url.Values) http.HandlerFunc { + return NewGHTTPWithGomega(gomega.Default).VerifyForm(values) +} + +func VerifyFormKV(key string, values ...string) http.HandlerFunc { + return NewGHTTPWithGomega(gomega.Default).VerifyFormKV(key, values...) +} + +func VerifyProtoRepresenting(expected proto.Message) http.HandlerFunc { + return NewGHTTPWithGomega(gomega.Default).VerifyProtoRepresenting(expected) +} + +func RespondWith(statusCode int, body interface{}, optionalHeader ...http.Header) http.HandlerFunc { + return NewGHTTPWithGomega(gomega.Default).RespondWith(statusCode, body, optionalHeader...) +} + +func RespondWithPtr(statusCode *int, body interface{}, optionalHeader ...http.Header) http.HandlerFunc { + return NewGHTTPWithGomega(gomega.Default).RespondWithPtr(statusCode, body, optionalHeader...) +} + +func RespondWithJSONEncoded(statusCode int, object interface{}, optionalHeader ...http.Header) http.HandlerFunc { + return NewGHTTPWithGomega(gomega.Default).RespondWithJSONEncoded(statusCode, object, optionalHeader...) +} + +func RespondWithJSONEncodedPtr(statusCode *int, object interface{}, optionalHeader ...http.Header) http.HandlerFunc { + return NewGHTTPWithGomega(gomega.Default).RespondWithJSONEncodedPtr(statusCode, object, optionalHeader...) +} + +func RespondWithProto(statusCode int, message proto.Message, optionalHeader ...http.Header) http.HandlerFunc { + return NewGHTTPWithGomega(gomega.Default).RespondWithProto(statusCode, message, optionalHeader...) +} diff -Nru golang-gomega-1.9.0/ghttp/test_server_test.go golang-gomega-1.10.3/ghttp/test_server_test.go --- golang-gomega-1.9.0/ghttp/test_server_test.go 2020-02-01 10:40:48.000000000 +0000 +++ golang-gomega-1.10.3/ghttp/test_server_test.go 2020-10-12 17:54:53.000000000 +0000 @@ -588,7 +588,7 @@ It("should verify the json body and the content type", func() { failures := InterceptGomegaFailures(func() { - http.Post(s.URL()+"/foo", "application/json", bytes.NewReader([]byte(`[1,3]`))) + http.Post(s.URL()+"/foo", "application/json; charset=utf-8", bytes.NewReader([]byte(`[1,3]`))) }) Expect(failures).Should(HaveLen(1)) }) diff -Nru golang-gomega-1.9.0/gomega_dsl.go golang-gomega-1.10.3/gomega_dsl.go --- golang-gomega-1.9.0/gomega_dsl.go 2020-02-01 10:40:48.000000000 +0000 +++ golang-gomega-1.10.3/gomega_dsl.go 2020-10-12 17:54:53.000000000 +0000 @@ -24,7 +24,7 @@ "github.com/onsi/gomega/types" ) -const GOMEGA_VERSION = "1.9.0" +const GOMEGA_VERSION = "1.10.3" const nilFailHandlerPanic = `You are trying to make an assertion, but Gomega's fail handler is nil. If you're using Ginkgo then you probably forgot to put your assertion in an It(). @@ -252,7 +252,7 @@ return ConsistentlyWithOffset(0, actual, intervals...) } -// ConsistentlyWithOffset operates like Consistnetly but takes an additional +// ConsistentlyWithOffset operates like Consistently but takes an additional // initial argument to indicate an offset in the call stack. This is useful when building helper // functions that contain matchers. To learn more, read about `ExpectWithOffset`. func ConsistentlyWithOffset(offset int, actual interface{}, intervals ...interface{}) AsyncAssertion { @@ -376,13 +376,13 @@ return NewWithT(t) } -// Expect is used to make assertions. See documentation for Expect. -func (g *WithT) Expect(actual interface{}, extra ...interface{}) Assertion { - return assertion.New(actual, testingtsupport.BuildTestingTGomegaFailWrapper(g.t), 0, extra...) +// ExpectWithOffset is used to make assertions. See documentation for ExpectWithOffset. +func (g *WithT) ExpectWithOffset(offset int, actual interface{}, extra ...interface{}) Assertion { + return assertion.New(actual, testingtsupport.BuildTestingTGomegaFailWrapper(g.t), offset, extra...) } -// Eventually is used to make asynchronous assertions. See documentation for Eventually. -func (g *WithT) Eventually(actual interface{}, intervals ...interface{}) AsyncAssertion { +// EventuallyWithOffset is used to make asynchronous assertions. See documentation for EventuallyWithOffset. +func (g *WithT) EventuallyWithOffset(offset int, actual interface{}, intervals ...interface{}) AsyncAssertion { timeoutInterval := defaultEventuallyTimeout pollingInterval := defaultEventuallyPollingInterval if len(intervals) > 0 { @@ -391,11 +391,11 @@ if len(intervals) > 1 { pollingInterval = toDuration(intervals[1]) } - return asyncassertion.New(asyncassertion.AsyncAssertionTypeEventually, actual, testingtsupport.BuildTestingTGomegaFailWrapper(g.t), timeoutInterval, pollingInterval, 0) + return asyncassertion.New(asyncassertion.AsyncAssertionTypeEventually, actual, testingtsupport.BuildTestingTGomegaFailWrapper(g.t), timeoutInterval, pollingInterval, offset) } -// Consistently is used to make asynchronous assertions. See documentation for Consistently. -func (g *WithT) Consistently(actual interface{}, intervals ...interface{}) AsyncAssertion { +// ConsistentlyWithOffset is used to make asynchronous assertions. See documentation for ConsistentlyWithOffset. +func (g *WithT) ConsistentlyWithOffset(offset int, actual interface{}, intervals ...interface{}) AsyncAssertion { timeoutInterval := defaultConsistentlyDuration pollingInterval := defaultConsistentlyPollingInterval if len(intervals) > 0 { @@ -404,7 +404,22 @@ if len(intervals) > 1 { pollingInterval = toDuration(intervals[1]) } - return asyncassertion.New(asyncassertion.AsyncAssertionTypeConsistently, actual, testingtsupport.BuildTestingTGomegaFailWrapper(g.t), timeoutInterval, pollingInterval, 0) + return asyncassertion.New(asyncassertion.AsyncAssertionTypeConsistently, actual, testingtsupport.BuildTestingTGomegaFailWrapper(g.t), timeoutInterval, pollingInterval, offset) +} + +// Expect is used to make assertions. See documentation for Expect. +func (g *WithT) Expect(actual interface{}, extra ...interface{}) Assertion { + return g.ExpectWithOffset(0, actual, extra...) +} + +// Eventually is used to make asynchronous assertions. See documentation for Eventually. +func (g *WithT) Eventually(actual interface{}, intervals ...interface{}) AsyncAssertion { + return g.EventuallyWithOffset(0, actual, intervals...) +} + +// Consistently is used to make asynchronous assertions. See documentation for Consistently. +func (g *WithT) Consistently(actual interface{}, intervals ...interface{}) AsyncAssertion { + return g.ConsistentlyWithOffset(0, actual, intervals...) } func toDuration(input interface{}) time.Duration { @@ -432,3 +447,32 @@ panic(fmt.Sprintf("%v is not a valid interval. Must be time.Duration, parsable duration string or a number.", input)) } + +// Gomega describes the essential Gomega DSL. This interface allows libraries +// to abstract between the standard package-level function implementations +// and alternatives like *WithT. +type Gomega interface { + Expect(actual interface{}, extra ...interface{}) Assertion + Eventually(actual interface{}, intervals ...interface{}) AsyncAssertion + Consistently(actual interface{}, intervals ...interface{}) AsyncAssertion +} + +type globalFailHandlerGomega struct{} + +// DefaultGomega supplies the standard package-level implementation +var Default Gomega = globalFailHandlerGomega{} + +// Expect is used to make assertions. See documentation for Expect. +func (globalFailHandlerGomega) Expect(actual interface{}, extra ...interface{}) Assertion { + return Expect(actual, extra...) +} + +// Eventually is used to make asynchronous assertions. See documentation for Eventually. +func (globalFailHandlerGomega) Eventually(actual interface{}, extra ...interface{}) AsyncAssertion { + return Eventually(actual, extra...) +} + +// Consistently is used to make asynchronous assertions. See documentation for Consistently. +func (globalFailHandlerGomega) Consistently(actual interface{}, extra ...interface{}) AsyncAssertion { + return Consistently(actual, extra...) +} diff -Nru golang-gomega-1.9.0/go.mod golang-gomega-1.10.3/go.mod --- golang-gomega-1.9.0/go.mod 2020-02-01 10:40:48.000000000 +0000 +++ golang-gomega-1.10.3/go.mod 2020-10-12 17:54:53.000000000 +0000 @@ -1,17 +1,11 @@ module github.com/onsi/gomega +go 1.14 + require ( - github.com/fsnotify/fsnotify v1.4.7 // indirect - github.com/golang/protobuf v1.2.0 - github.com/hpcloud/tail v1.0.0 // indirect - github.com/onsi/ginkgo v1.6.0 - golang.org/x/net v0.0.0-20180906233101-161cd47e91fd - golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f // indirect - golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e // indirect - golang.org/x/text v0.3.0 // indirect - golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 - gopkg.in/fsnotify.v1 v1.4.7 // indirect - gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect - gopkg.in/yaml.v2 v2.2.4 + github.com/golang/protobuf v1.4.2 + github.com/onsi/ginkgo v1.12.1 + golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0 + golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 + gopkg.in/yaml.v2 v2.3.0 ) - diff -Nru golang-gomega-1.9.0/go.sum golang-gomega-1.10.3/go.sum --- golang-gomega-1.9.0/go.sum 2020-02-01 10:40:48.000000000 +0000 +++ golang-gomega-1.10.3/go.sum 2020-10-12 17:54:53.000000000 +0000 @@ -2,20 +2,61 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78= +github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/onsi/ginkgo v1.6.0 h1:Ix8l273rp3QzYgXSR+c8d1fTG7UPgYkOSELPhiY/YGw= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.12.1 h1:mFwc4LvZ0xpSvDZ3E+k8Yte0hLOMxXUlP+yXtJqkYfQ= +github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7 h1:AeiKBIuRw3UomYXSbLy0Mc2dDLfdtbT/IVn4keq83P0= +golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0 h1:wBouT66WTYFXdxfVdz9sVWARVd/2vfGcmI45D2gj45M= +golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e h1:N7DeIrjYszNmSW409R3frPPwglRwMkXSBzwVbkOjLLA= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= @@ -24,3 +65,5 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff -Nru golang-gomega-1.9.0/matchers/have_http_status_matcher.go golang-gomega-1.10.3/matchers/have_http_status_matcher.go --- golang-gomega-1.9.0/matchers/have_http_status_matcher.go 1970-01-01 00:00:00.000000000 +0000 +++ golang-gomega-1.10.3/matchers/have_http_status_matcher.go 2020-10-12 17:54:53.000000000 +0000 @@ -0,0 +1,42 @@ +package matchers + +import ( + "fmt" + "net/http" + "net/http/httptest" + + "github.com/onsi/gomega/format" +) + +type HaveHTTPStatusMatcher struct { + Expected interface{} +} + +func (matcher *HaveHTTPStatusMatcher) Match(actual interface{}) (success bool, err error) { + var resp *http.Response + switch a := actual.(type) { + case *http.Response: + resp = a + case *httptest.ResponseRecorder: + resp = a.Result() + default: + return false, fmt.Errorf("HaveHTTPStatus matcher expects *http.Response or *httptest.ResponseRecorder. Got:\n%s", format.Object(actual, 1)) + } + + switch e := matcher.Expected.(type) { + case int: + return resp.StatusCode == e, nil + case string: + return resp.Status == e, nil + } + + return false, fmt.Errorf("HaveHTTPStatus matcher must be passed an int or a string. Got:\n%s", format.Object(matcher.Expected, 1)) +} + +func (matcher *HaveHTTPStatusMatcher) FailureMessage(actual interface{}) (message string) { + return format.Message(actual, "to have HTTP status", matcher.Expected) +} + +func (matcher *HaveHTTPStatusMatcher) NegatedFailureMessage(actual interface{}) (message string) { + return format.Message(actual, "not to have HTTP status", matcher.Expected) +} diff -Nru golang-gomega-1.9.0/matchers/have_http_status_matcher_test.go golang-gomega-1.10.3/matchers/have_http_status_matcher_test.go --- golang-gomega-1.9.0/matchers/have_http_status_matcher_test.go 1970-01-01 00:00:00.000000000 +0000 +++ golang-gomega-1.10.3/matchers/have_http_status_matcher_test.go 2020-10-12 17:54:53.000000000 +0000 @@ -0,0 +1,91 @@ +package matchers_test + +import ( + "net/http" + "net/http/httptest" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +var _ = Describe("HaveHTTPStatus", func() { + When("ACTUAL is *http.Response", func() { + When("EXPECTED is integer", func() { + It("matches the StatusCode", func() { + resp := &http.Response{StatusCode: http.StatusOK} + Expect(resp).To(HaveHTTPStatus(http.StatusOK)) + Expect(resp).NotTo(HaveHTTPStatus(http.StatusNotFound)) + }) + }) + When("EXPECTED is string", func() { + It("matches the Status", func() { + resp := &http.Response{Status: "200 OK"} + Expect(resp).To(HaveHTTPStatus("200 OK")) + Expect(resp).NotTo(HaveHTTPStatus("404 Not Found")) + }) + }) + When("EXPECTED is anything else", func() { + It("does not match", func() { + failures := InterceptGomegaFailures(func() { + resp := &http.Response{StatusCode: http.StatusOK} + Expect(resp).NotTo(HaveHTTPStatus(true)) + }) + Expect(failures).To(ConsistOf("HaveHTTPStatus matcher must be passed an int or a string. Got:\n : true")) + }) + }) + }) + + When("ACTUAL is *httptest.ResponseRecorder", func() { + When("EXPECTED is integer", func() { + It("matches the StatusCode", func() { + resp := &httptest.ResponseRecorder{Code: http.StatusOK} + Expect(resp).To(HaveHTTPStatus(http.StatusOK)) + Expect(resp).NotTo(HaveHTTPStatus(http.StatusNotFound)) + }) + }) + When("EXPECTED is string", func() { + It("matches the Status", func() { + resp := &httptest.ResponseRecorder{Code: http.StatusOK} + Expect(resp).To(HaveHTTPStatus("200 OK")) + Expect(resp).NotTo(HaveHTTPStatus("404 Not Found")) + }) + }) + When("EXPECTED is anything else", func() { + It("does not match", func() { + failures := InterceptGomegaFailures(func() { + resp := &httptest.ResponseRecorder{Code: http.StatusOK} + Expect(resp).NotTo(HaveHTTPStatus(nil)) + }) + Expect(failures).To(ConsistOf("HaveHTTPStatus matcher must be passed an int or a string. Got:\n : nil")) + }) + }) + }) + + When("ACTUAL is neither *http.Response nor *httptest.ResponseRecorder", func() { + It("errors", func() { + failures := InterceptGomegaFailures(func() { + Expect("foo").To(HaveHTTPStatus(http.StatusOK)) + }) + Expect(failures).To(ConsistOf("HaveHTTPStatus matcher expects *http.Response or *httptest.ResponseRecorder. Got:\n : foo")) + }) + }) + + Describe("FailureMessage", func() { + It("returns message", func() { + failures := InterceptGomegaFailures(func() { + resp := &http.Response{StatusCode: http.StatusBadGateway} + Expect(resp).To(HaveHTTPStatus(http.StatusOK)) + }) + Expect(failures).To(ConsistOf(MatchRegexp("Expected(.|\n)*StatusCode: 502(.|\n)*to have HTTP status\n : 200"))) + }) + }) + Describe("NegatedFailureMessage", func() { + It("returns message", func() { + failures := InterceptGomegaFailures(func() { + resp := &http.Response{StatusCode: http.StatusOK} + Expect(resp).NotTo(HaveHTTPStatus(http.StatusOK)) + }) + Expect(failures).To(ConsistOf(MatchRegexp("Expected(.|\n)*StatusCode: 200(.|\n)*not to have HTTP status\n : 200"))) + }) + }) +}) diff -Nru golang-gomega-1.9.0/matchers/panic_matcher.go golang-gomega-1.10.3/matchers/panic_matcher.go --- golang-gomega-1.9.0/matchers/panic_matcher.go 2020-02-01 10:40:48.000000000 +0000 +++ golang-gomega-1.10.3/matchers/panic_matcher.go 2020-10-12 17:54:53.000000000 +0000 @@ -8,7 +8,8 @@ ) type PanicMatcher struct { - object interface{} + Expected interface{} + object interface{} } func (matcher *PanicMatcher) Match(actual interface{}) (success bool, err error) { @@ -28,7 +29,21 @@ defer func() { if e := recover(); e != nil { matcher.object = e - success = true + + if matcher.Expected == nil { + success = true + return + } + + valueMatcher, valueIsMatcher := matcher.Expected.(omegaMatcher) + if !valueIsMatcher { + valueMatcher = &EqualMatcher{Expected: matcher.Expected} + } + + success, err = valueMatcher.Match(e) + if err != nil { + err = fmt.Errorf("PanicMatcher's value matcher failed with:\n%s%s", format.Indent, err.Error()) + } } }() @@ -38,9 +53,62 @@ } func (matcher *PanicMatcher) FailureMessage(actual interface{}) (message string) { - return format.Message(actual, "to panic") + if matcher.Expected == nil { + // We wanted any panic to occur, but none did. + return format.Message(actual, "to panic") + } + + if matcher.object == nil { + // We wanted a panic with a specific value to occur, but none did. + switch matcher.Expected.(type) { + case omegaMatcher: + return format.Message(actual, "to panic with a value matching", matcher.Expected) + default: + return format.Message(actual, "to panic with", matcher.Expected) + } + } + + // We got a panic, but the value isn't what we expected. + switch matcher.Expected.(type) { + case omegaMatcher: + return format.Message( + actual, + fmt.Sprintf( + "to panic with a value matching\n%s\nbut panicked with\n%s", + format.Object(matcher.Expected, 1), + format.Object(matcher.object, 1), + ), + ) + default: + return format.Message( + actual, + fmt.Sprintf( + "to panic with\n%s\nbut panicked with\n%s", + format.Object(matcher.Expected, 1), + format.Object(matcher.object, 1), + ), + ) + } } func (matcher *PanicMatcher) NegatedFailureMessage(actual interface{}) (message string) { - return format.Message(actual, fmt.Sprintf("not to panic, but panicked with\n%s", format.Object(matcher.object, 1))) + if matcher.Expected == nil { + // We didn't want any panic to occur, but one did. + return format.Message(actual, fmt.Sprintf("not to panic, but panicked with\n%s", format.Object(matcher.object, 1))) + } + + // We wanted a to ensure a panic with a specific value did not occur, but it did. + switch matcher.Expected.(type) { + case omegaMatcher: + return format.Message( + actual, + fmt.Sprintf( + "not to panic with a value matching\n%s\nbut panicked with\n%s", + format.Object(matcher.Expected, 1), + format.Object(matcher.object, 1), + ), + ) + default: + return format.Message(actual, "not to panic with", matcher.Expected) + } } diff -Nru golang-gomega-1.9.0/matchers/panic_matcher_test.go golang-gomega-1.10.3/matchers/panic_matcher_test.go --- golang-gomega-1.9.0/matchers/panic_matcher_test.go 2020-02-01 10:40:48.000000000 +0000 +++ golang-gomega-1.10.3/matchers/panic_matcher_test.go 2020-10-12 17:54:53.000000000 +0000 @@ -35,7 +35,7 @@ }) When("assertion fails", func() { - It("prints the object passed to Panic when negative", func() { + It("prints the object passed to panic() when negative", func() { failuresMessages := InterceptGomegaFailures(func() { Expect(func() { panic("ack!") }).NotTo(Panic()) }) @@ -50,3 +50,115 @@ }) }) }) + +var _ = Describe("PanicWith", func() { + When("a specific panic value is expected", func() { + matcher := PanicWith("ack!") + + When("no panic occurs", func() { + actual := func() {} + + It("prints a message that includes the expected value", func() { + failuresMessages := InterceptGomegaFailures(func() { + Expect(actual).To(matcher) + }) + Expect(failuresMessages).To(ConsistOf( + MatchRegexp("Expected\n\\s+: .+\nto panic with\\s+: ack!"), + )) + }) + + It("passes when negated", func() { + Expect(actual).NotTo(matcher) + }) + }) + + When("the panic value matches", func() { + actual := func() { panic("ack!") } + + It("passes", func() { + Expect(actual).To(matcher) + }) + + It("prints a message that includes the (un)expected value when negated", func() { + failuresMessages := InterceptGomegaFailures(func() { + Expect(actual).NotTo(matcher) + }) + Expect(failuresMessages).To(ConsistOf( + MatchRegexp("Expected\n\\s+: .+\nnot to panic with\\s+: ack!"), + )) + }) + }) + + When("the panic value does not match", func() { + actual := func() { panic("unexpected!") } + + It("prints a message that includes both the actual and expected values", func() { + failuresMessages := InterceptGomegaFailures(func() { + Expect(actual).To(matcher) + }) + Expect(failuresMessages).To(ConsistOf( + MatchRegexp("Expected\n\\s+: .+\nto panic with\\s+: ack!\nbut panicked with\n\\s+: unexpected!"), + )) + }) + + It("passes when negated", func() { + Expect(actual).NotTo(matcher) + }) + }) + }) + + When("the expected value is actually a matcher", func() { + matcher := PanicWith(MatchRegexp("ack")) + + When("no panic occurs", func() { + actual := func() {} + + It("prints a message that includes the expected value", func() { + failuresMessages := InterceptGomegaFailures(func() { + Expect(actual).To(matcher) + }) + Expect(failuresMessages).To(ConsistOf( + MatchRegexp("Expected\n\\s+: .+\nto panic with a value matching\n.+MatchRegexpMatcher.+ack"), + )) + }) + + It("passes when negated", func() { + Expect(actual).NotTo(matcher) + }) + }) + + When("the panic value matches", func() { + actual := func() { panic("ack!") } + + It("passes", func() { + Expect(actual).To(matcher) + }) + + It("prints a message that includes the (un)expected value when negated", func() { + failuresMessages := InterceptGomegaFailures(func() { + Expect(actual).NotTo(matcher) + }) + Expect(failuresMessages).To(ConsistOf( + MatchRegexp("Expected\n\\s+: .+\nnot to panic with a value matching\n.+MatchRegexpMatcher.+ack"), + )) + }) + }) + + When("the panic value does not match", func() { + actual := func() { panic("unexpected!") } + + It("prints a message that includes both the actual and expected values", func() { + failuresMessages := InterceptGomegaFailures(func() { + Expect(actual).To(matcher) + }) + Expect(failuresMessages).To(ConsistOf( + MatchRegexp("Expected\n\\s+: .+\nto panic with a value matching\n.+MatchRegexpMatcher.+ack.+\nbut panicked with\n\\s+: unexpected!"), + )) + }) + + It("passes when negated", func() { + Expect(actual).NotTo(matcher) + }) + }) + }) +}) diff -Nru golang-gomega-1.9.0/matchers.go golang-gomega-1.10.3/matchers.go --- golang-gomega-1.9.0/matchers.go 2020-02-01 10:40:48.000000000 +0000 +++ golang-gomega-1.10.3/matchers.go 2020-10-12 17:54:53.000000000 +0000 @@ -390,6 +390,16 @@ return &matchers.PanicMatcher{} } +//PanicWith succeeds if actual is a function that, when invoked, panics with a specific value. +//Actual must be a function that takes no arguments and returns no results. +// +//By default PanicWith uses Equal() to perform the match, however a +//matcher can be passed in instead: +// Expect(fn).Should(PanicWith(MatchRegexp(`.+Foo$`))) +func PanicWith(expected interface{}) types.GomegaMatcher { + return &matchers.PanicMatcher{Expected: expected} +} + //BeAnExistingFile succeeds if a file exists. //Actual must be a string representing the abs path to the file being checked. func BeAnExistingFile() types.GomegaMatcher { @@ -408,6 +418,15 @@ return &matchers.BeADirectoryMatcher{} } +//HaveHTTPStatus succeeds if the Status or StatusCode field of an HTTP response matches. +//Actual must be either a *http.Response or *httptest.ResponseRecorder. +//Expected must be either an int or a string. +// Expect(resp).Should(HaveHTTPStatus(http.StatusOK)) // asserts that resp.StatusCode == 200 +// Expect(resp).Should(HaveHTTPStatus("404 Not Found")) // asserts that resp.Status == "404 Not Found" +func HaveHTTPStatus(expected interface{}) types.GomegaMatcher { + return &matchers.HaveHTTPStatusMatcher{Expected: expected} +} + //And succeeds only if all of the given matchers succeed. //The matchers are tried in order, and will fail-fast if one doesn't succeed. // Expect("hi").To(And(HaveLen(2), Equal("hi")) diff -Nru golang-gomega-1.9.0/.travis.yml golang-gomega-1.10.3/.travis.yml --- golang-gomega-1.9.0/.travis.yml 2020-02-01 10:40:48.000000000 +0000 +++ golang-gomega-1.10.3/.travis.yml 2020-10-12 17:54:53.000000000 +0000 @@ -1,8 +1,8 @@ language: go go: - - 1.12.x - - 1.13.x + - 1.14.x + - 1.15.x - gotip env: