From d79f37b1adc572522d5f2ef8904d02f4b80ec534 Mon Sep 17 00:00:00 2001 From: anthonyfong100 <32214050+anthonyfong100@users.noreply.github.com> Date: Mon, 1 Mar 2021 23:03:47 +0800 Subject: [PATCH] Feature/testing t interface (#108) * abstract out *testing.T through an interface * add in ginkgo test example Co-authored-by: kuo.fong --- README.md | 1 + apitest.go | 5 +- apitest_test.go | 2 +- assert.go | 36 ++++++++------ examples/ginkgo/server.go | 58 +++++++++++++++++++++++ examples/ginkgo/server_suite_test.go | 13 +++++ examples/ginkgo/server_test.go | 71 ++++++++++++++++++++++++++++ examples/go.mod | 7 +-- examples/go.sum | 35 ++++++++++++++ mocks/verifier.go | 25 +++++----- 10 files changed, 217 insertions(+), 36 deletions(-) create mode 100644 examples/ginkgo/server.go create mode 100644 examples/ginkgo/server_suite_test.go create mode 100644 examples/ginkgo/server_test.go diff --git a/README.md b/README.md index b2fc2a5..4ad2120 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ go get -u github.com/steinfletcher/apitest | [httprouter](https://github.com/steinfletcher/apitest/tree/master/examples/httprouter) | High performance HTTP request router that scales well | | [mocks](https://github.com/steinfletcher/apitest/tree/master/examples/mocks) | example mocking out external http calls | | [sequence diagrams](https://github.com/steinfletcher/apitest/tree/master/examples/sequence-diagrams) | generate sequence diagrams from tests. See the [demo](http://demo-html.apitest.dev.s3-website-eu-west-1.amazonaws.com/) | +| [Ginkgo](https://github.com/steinfletcher/apitest/tree/master/examples/ginkgo) | Ginkgo BDD test framework| ### Companion libraries diff --git a/apitest.go b/apitest.go index f290c6d..c1c4287 100644 --- a/apitest.go +++ b/apitest.go @@ -14,7 +14,6 @@ import ( "runtime/debug" "sort" "strings" - "testing" "time" ) @@ -45,7 +44,7 @@ type APITest struct { mocksObservers []Observe recorderHook RecorderHook mocks []*Mock - t *testing.T + t TestingT httpClient *http.Client transport *Transport meta map[string]interface{} @@ -466,7 +465,7 @@ func (r *Request) FormData(name string, values ...string) *Request { } // Expect marks the request spec as complete and following code will define the expected response -func (r *Request) Expect(t *testing.T) *Response { +func (r *Request) Expect(t TestingT) *Response { r.apiTest.t = t return r.apiTest.response } diff --git a/apitest_test.go b/apitest_test.go index a99b500..1fd2464 100644 --- a/apitest_test.go +++ b/apitest_test.go @@ -1101,7 +1101,7 @@ func TestApiTest_ErrorIfMockInvocationsDoNotMatchTimes(t *testing.T) { End() verifier := mocks.NewVerifier() - verifier.FailFn = func(t *testing.T, failureMessage string, msgAndArgs ...interface{}) bool { + verifier.FailFn = func(t apitest.TestingT, failureMessage string, msgAndArgs ...interface{}) bool { assert.Equal(t, "mock was not invoked expected times", failureMessage) return true } diff --git a/assert.go b/assert.go index d2e1e1f..e2edca6 100644 --- a/assert.go +++ b/assert.go @@ -2,40 +2,48 @@ package apitest import ( "fmt" - "github.com/stretchr/testify/assert" "net/http" - "testing" + + "github.com/stretchr/testify/assert" ) +// TestingT is an interface to wrap the native *testing.T interface, this allows integration with GinkgoT() interface +// GinkgoT interface defined in https://github.com/onsi/ginkgo/blob/55c858784e51c26077949c81b6defb6b97b76944/ginkgo_dsl.go#L91 +type TestingT interface { + Errorf(format string, args ...interface{}) + Fatal(args ...interface{}) + Fatalf(format string, args ...interface{}) +} + // Verifier is the assertion interface allowing consumers to inject a custom assertion implementation. // It also allows failure scenarios to be tested within apitest type Verifier interface { - Equal(t *testing.T, expected, actual interface{}, msgAndArgs ...interface{}) bool - JSONEq(t *testing.T, expected string, actual string, msgAndArgs ...interface{}) bool - Fail(t *testing.T, failureMessage string, msgAndArgs ...interface{}) bool - NoError(t *testing.T, err error, msgAndArgs ...interface{}) bool + Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool + JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) bool + Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) bool + NoError(t TestingT, err error, msgAndArgs ...interface{}) bool } // testifyVerifier is a verifier that use https://github.com/stretchr/testify to perform assertions type testifyVerifier struct{} // JSONEq asserts that two JSON strings are equivalent -func (a testifyVerifier) JSONEq(t *testing.T, expected string, actual string, msgAndArgs ...interface{}) bool { +func (a testifyVerifier) JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) bool { return assert.JSONEq(t, expected, actual, msgAndArgs...) } // Equal asserts that two objects are equal -func (a testifyVerifier) Equal(t *testing.T, expected, actual interface{}, msgAndArgs ...interface{}) bool { +func (a testifyVerifier) Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool { return assert.Equal(t, expected, actual, msgAndArgs...) } // Fail reports a failure -func (a testifyVerifier) Fail(t *testing.T, failureMessage string, msgAndArgs ...interface{}) bool { +func (a testifyVerifier) Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) bool { return assert.Fail(t, failureMessage, msgAndArgs...) } // NoError asserts that a function returned no error -func (a testifyVerifier) NoError(t *testing.T, err error, msgAndArgs ...interface{}) bool { +func (a testifyVerifier) NoError(t TestingT, err error, msgAndArgs ...interface{}) bool { return assert.NoError(t, err, msgAndArgs...) } @@ -49,22 +57,22 @@ type NoopVerifier struct{} var _ Verifier = NoopVerifier{} // Equal does not perform any assertion and always returns true -func (n NoopVerifier) Equal(t *testing.T, expected, actual interface{}, msgAndArgs ...interface{}) bool { +func (n NoopVerifier) Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool { return true } // JSONEq does not perform any assertion and always returns true -func (n NoopVerifier) JSONEq(t *testing.T, expected string, actual string, msgAndArgs ...interface{}) bool { +func (n NoopVerifier) JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) bool { return true } // Fail does not perform any assertion and always returns true -func (n NoopVerifier) Fail(t *testing.T, failureMessage string, msgAndArgs ...interface{}) bool { +func (n NoopVerifier) Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) bool { return true } // NoError asserts that a function returned no error -func (n NoopVerifier) NoError(t *testing.T, err error, msgAndArgs ...interface{}) bool { +func (n NoopVerifier) NoError(t TestingT, err error, msgAndArgs ...interface{}) bool { return true } diff --git a/examples/ginkgo/server.go b/examples/ginkgo/server.go new file mode 100644 index 0000000..f150a90 --- /dev/null +++ b/examples/ginkgo/server.go @@ -0,0 +1,58 @@ +package server + +import ( + "encoding/json" + "log" + "net/http" + + "github.com/gorilla/mux" +) + +type user struct { + ID string `json:"id"` + Name string `json:"name"` +} + +type application struct { + Router *mux.Router +} + +func NewApp() *application { + router := mux.NewRouter() + router.HandleFunc("/user/{id}", getUser()).Methods("GET") + return &application{Router: router} +} + +func (a *application) start() { + log.Fatal(http.ListenAndServe("localhost:8888", a.Router)) +} + +func getUser() http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + id := mux.Vars(r)["id"] + http.SetCookie(w, &http.Cookie{ + Name: "TomsFavouriteDrink", + Value: "Beer", + Path: "/", + }) + + if id == "1234" { + user := &user{ID: id, Name: "Andy"} + bytes, _ := json.Marshal(user) + _, err := w.Write(bytes) + if err != nil { + panic(err) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + return + } + + w.WriteHeader(http.StatusNotFound) + } +} + +func main() { + NewApp().start() +} diff --git a/examples/ginkgo/server_suite_test.go b/examples/ginkgo/server_suite_test.go new file mode 100644 index 0000000..68bae57 --- /dev/null +++ b/examples/ginkgo/server_suite_test.go @@ -0,0 +1,13 @@ +package server_test + +import ( + "testing" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +func TestHandlers(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Server Suite") +} diff --git a/examples/ginkgo/server_test.go b/examples/ginkgo/server_test.go new file mode 100644 index 0000000..09fb4bc --- /dev/null +++ b/examples/ginkgo/server_test.go @@ -0,0 +1,71 @@ +package server_test + +import ( + "net/http" + + "github.com/gorilla/mux" + . "github.com/onsi/ginkgo" + "github.com/steinfletcher/apitest" + jsonpath "github.com/steinfletcher/apitest-jsonpath" + server "github.com/steinfletcher/apitest/examples/ginkgo" +) + +var _ = Describe("Ginkgo/Server", func() { + + var ( + t GinkgoTInterface + router *mux.Router + ) + + BeforeEach(func() { + t = GinkgoT() + router = server.NewApp().Router + }) + + Context("Successful CookieMatching", func() { + It("cookies should be set correctly", func() { + apitest.New(). + Handler(router). + Get("/user/1234"). + Expect(t). + Cookies(apitest.NewCookie("TomsFavouriteDrink"). + Value("Beer"). + Path("/")). + Status(http.StatusOK). + End() + }) + }) + + Context("Successful GetUser", func() { + It("Get User body should return desired value", func() { + apitest.New(). + Handler(router). + Get("/user/1234"). + Expect(t). + Body(`{"id": "1234", "name": "Andy"}`). + Status(http.StatusOK). + End() + }) + + It("Get User jsonpath should return desired value", func() { + apitest.New(). + Handler(router). + Get("/user/1234"). + Expect(t). + Assert(jsonpath.Equal(`$.id`, "1234")). + Status(http.StatusOK). + End() + }) + }) + + Context("Unsuccessful GetUser", func() { + It("User not found error should be raised", func() { + apitest.New(). + Handler(router). + Get("/user/1515"). + Expect(t). + Status(http.StatusNotFound). + End() + }) + }) +}) diff --git a/examples/go.mod b/examples/go.mod index e886f48..1a44e3e 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -15,7 +15,6 @@ require ( github.com/gin-gonic/gin v1.6.2 github.com/go-sql-driver/mysql v1.5.0 github.com/gofiber/fiber v1.11.0 - github.com/golang/protobuf v1.4.0 // indirect github.com/google/go-querystring v1.0.0 // indirect github.com/gorilla/mux v1.7.4 github.com/imkira/go-interpol v1.1.0 // indirect @@ -40,8 +39,8 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.1 // indirect github.com/moul/http2curl v1.0.0 // indirect - github.com/onsi/ginkgo v1.12.0 // indirect - github.com/onsi/gomega v1.9.0 // indirect + github.com/onsi/ginkgo v1.15.0 + github.com/onsi/gomega v1.10.1 github.com/pkg/errors v0.9.1 // indirect github.com/pressly/goose v2.6.0+incompatible github.com/ryanuber/columnize v2.1.0+incompatible // indirect @@ -56,8 +55,6 @@ require ( github.com/yudai/gojsondiff v1.0.0 // indirect github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect github.com/yudai/pp v2.0.1+incompatible // indirect - golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0 // indirect - golang.org/x/sys v0.0.0-20200427175716-29b57079015a // indirect ) go 1.13 diff --git a/examples/go.sum b/examples/go.sum index 5f5b5a7..91520c9 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -42,6 +42,8 @@ github.com/flosch/pongo2 v0.0.0-20190707114632-bbf5a6c351f4 h1:GY1+t5Dr9OKADM64S github.com/flosch/pongo2 v0.0.0-20190707114632-bbf5a6c351f4/go.mod h1:T9YF2M40nIgbVgp3rreNmTged+9HrbNTIQf1PsaIiTA= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= +github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/gavv/monotime v0.0.0-20190418164738-30dba4353424 h1:Vh7rylVZRZCj6W41lRlP17xPk4Nq260H4Xo/DDYmEZk= github.com/gavv/monotime v0.0.0-20190418164738-30dba4353424/go.mod h1:vmp8DIyckQMXOPl0AQVHt+7n5h7Gb7hS6CUydiV8QeA= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= @@ -75,6 +77,8 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= github.com/golang/protobuf v1.4.0 h1:oOuy+ugB+P/kBdUnG5QaMXSIyJ1q38wWSojYCb3z5VQ= 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= @@ -173,12 +177,19 @@ github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9 github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/moul/http2curl v1.0.0 h1:dRMWoAtb+ePxMlLkrCbAqh4TlPHXvoGUSQ323/9Zahs= github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ= +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/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.0 h1:Iw5WCbBcaAAd0fpRb1c9r5YCylv4XDoCSigm1zLevwU= github.com/onsi/ginkgo v1.12.0/go.mod h1:oUhWkIvk5aDxtKvDDuw8gItl8pKl42LzjC9KZE0HfGg= +github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/ginkgo v1.15.0 h1:1V1NfVQR87RtWAgp1lv9JZJ5Jap+XFGKPi00andXGi4= +github.com/onsi/ginkgo v1.15.0/go.mod h1:hF8qUzuuC8DJGygJH3726JnCZX4MYbRB8yFfISqnKUg= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.9.0 h1:R1uwffexN6Pr340GtYRIdZmAiN4J+iw6WG4wog1DUXg= github.com/onsi/gomega v1.9.0/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA= +github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE= +github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74= github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -250,11 +261,15 @@ github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3Ifn github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM= github.com/yudai/pp v2.0.1+incompatible h1:Q4//iY4pNF6yPLZIigmvcl7k/bPgrcTPIFIcmawg5bI= github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -264,39 +279,57 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0 h1:Jcxah/M+oLZ/R4/z5RzfPzGbPXnVDPkEDtf2JnuxN+U= golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 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-20190222072716-a9d3bda3a223/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-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200427175716-29b57079015a h1:08u6b1caTT9MQY4wSbmsd4Ulm6DmgNYnbImBuZjGJow= golang.org/x/sys v0.0.0-20200427175716-29b57079015a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210112080510-489259a85091 h1:DMyOG0U+gKfu8JZzg2UQe9MeaC1X+xQWlAKcRnjxjCw= +golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +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/tools v0.0.0-20181221001348-537d06c36207/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190125232054-d66bd3c5d5a6/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190515012406-7d7faa4812bd/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200114235610-7ae403b6b589 h1:rjUrONFu4kLchcZTfp3/96bR8bW8dIa8uz3cR5n0cgM= golang.org/x/tools v0.0.0-20200114235610-7ae403b6b589/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e h1:4nW4NLDYnU28ojHaHO8OVxFHk/aQ33U01a9cjED+pzE= +golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 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= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/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 h1:qdOKuR/EIArgaWNjetjgTzgVTAZ+S/WXVrq9HW9zimw= 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/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -310,6 +343,8 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8/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= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= sourcegraph.com/sourcegraph/appdash v0.0.0-20180110180208-2cc67fd64755/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU= diff --git a/mocks/verifier.go b/mocks/verifier.go index f3b76b4..feff5a9 100644 --- a/mocks/verifier.go +++ b/mocks/verifier.go @@ -2,63 +2,62 @@ package mocks import ( "github.com/steinfletcher/apitest" - "testing" ) var _ apitest.Verifier = MockVerifier{} // MockVerifier is a mock of the Verifier interface that is used in tests of apitest type MockVerifier struct { - EqualFn func(t *testing.T, expected, actual interface{}, msgAndArgs ...interface{}) bool + EqualFn func(t apitest.TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool EqualInvoked bool - JSONEqFn func(t *testing.T, expected string, actual string, msgAndArgs ...interface{}) bool + JSONEqFn func(t apitest.TestingT, expected string, actual string, msgAndArgs ...interface{}) bool JSONEqInvoked bool - FailFn func(t *testing.T, failureMessage string, msgAndArgs ...interface{}) bool + FailFn func(t apitest.TestingT, failureMessage string, msgAndArgs ...interface{}) bool FailInvoked bool - NoErrorFn func(t *testing.T, err error, msgAndArgs ...interface{}) bool + NoErrorFn func(t apitest.TestingT, err error, msgAndArgs ...interface{}) bool NoErrorInvoked bool } func NewVerifier() MockVerifier { return MockVerifier{ - EqualFn: func(t *testing.T, expected, actual interface{}, msgAndArgs ...interface{}) bool { + EqualFn: func(t apitest.TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool { return true }, - JSONEqFn: func(t *testing.T, expected string, actual string, msgAndArgs ...interface{}) bool { + JSONEqFn: func(t apitest.TestingT, expected string, actual string, msgAndArgs ...interface{}) bool { return true }, - FailFn: func(t *testing.T, failureMessage string, msgAndArgs ...interface{}) bool { + FailFn: func(t apitest.TestingT, failureMessage string, msgAndArgs ...interface{}) bool { return true }, - NoErrorFn: func(t *testing.T, err error, msgAndArgs ...interface{}) bool { + NoErrorFn: func(t apitest.TestingT, err error, msgAndArgs ...interface{}) bool { return true }, } } // Equal mocks the Equal method of the Verifier -func (m MockVerifier) Equal(t *testing.T, expected, actual interface{}, msgAndArgs ...interface{}) bool { +func (m MockVerifier) Equal(t apitest.TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool { m.EqualInvoked = true return m.EqualFn(t, expected, actual, msgAndArgs) } // JSONEq mocks the JSONEq method of the Verifier -func (m MockVerifier) JSONEq(t *testing.T, expected string, actual string, msgAndArgs ...interface{}) bool { +func (m MockVerifier) JSONEq(t apitest.TestingT, expected string, actual string, msgAndArgs ...interface{}) bool { m.JSONEqInvoked = true return m.JSONEqFn(t, expected, actual, msgAndArgs) } // Fail mocks the Fail method of the Verifier -func (m MockVerifier) Fail(t *testing.T, failureMessage string, msgAndArgs ...interface{}) bool { +func (m MockVerifier) Fail(t apitest.TestingT, failureMessage string, msgAndArgs ...interface{}) bool { m.FailInvoked = true return m.FailFn(t, failureMessage, msgAndArgs) } // NoError asserts that a function returned no error -func (m MockVerifier) NoError(t *testing.T, err error, msgAndArgs ...interface{}) bool { +func (m MockVerifier) NoError(t apitest.TestingT, err error, msgAndArgs ...interface{}) bool { m.NoErrorInvoked = true return m.NoErrorFn(t, err, msgAndArgs) }