Skip to content

Commit

Permalink
Upgrade to go 1.18, and ginkgo v2
Browse files Browse the repository at this point in the history
Ginkgo V2 is backwards incompatible, and popular enough,
it's time we need to upgrade.
  • Loading branch information
rgalanakis committed Oct 19, 2022
1 parent e360084 commit 3337e47
Show file tree
Hide file tree
Showing 19 changed files with 77 additions and 79 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
name: PR Checks
on: pull_request
on:
pull_request:
push: { branches: [master] }
jobs:
run-tests:
runs-on: ubuntu-latest
Expand All @@ -8,10 +10,10 @@ jobs:
uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- name: Set up Go 1.13.x
- name: Set up Go 1.18.x
uses: actions/setup-go@v1
with:
go-version: 1.13.x
go-version: 1.18.x
- uses: actions/cache@v1
with:
path: ~/go/pkg/mod
Expand Down
21 changes: 10 additions & 11 deletions errmatch/errmatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@ import (
// The expected value is used to construct a gomega.MatchError matcher,
// and then it is used to check one of the following:
//
// - actual passes MatchError(expected)
// - actual can be unwrapped, and the unwrapped value passes BeCausedBy.
// - pkg/errors.Cause(actual) passes MatchError(expected).
// This would be hit when you use pkg/errors.Wrap.
// Note that this only looks for the 'cause' error,
// and would not work to match error messages of intermediate wrapped errors.
// However, you can use BeCausedBy("outer: inner") (or MatchError) to match the full message.
// - any of ((*multierror.Error)actual).Errors passes BeCausedBy.
// That is, if you use errors.Wrap in conjunction with multierror,
// the individual errors in multierror are unwrapped with errors.Cause.
// - actual passes MatchError(expected)
// - actual can be unwrapped, and the unwrapped value passes BeCausedBy.
// - pkg/errors.Cause(actual) passes MatchError(expected).
// This would be hit when you use pkg/errors.Wrap.
// Note that this only looks for the 'cause' error,
// and would not work to match error messages of intermediate wrapped errors.
// However, you can use BeCausedBy("outer: inner") (or MatchError) to match the full message.
// - any of ((*multierror.Error)actual).Errors passes BeCausedBy.
// That is, if you use errors.Wrap in conjunction with multierror,
// the individual errors in multierror are unwrapped with errors.Cause.
//
// If all of those do not pass, BeCausedBy fails.
//
func BeCausedBy(expected interface{}) types.GomegaMatcher {
return &matchers.BeCausedByMatcher{MatchError: gomega.MatchError(expected)}
}
2 changes: 1 addition & 1 deletion errmatch/matchers/be_caused_by_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package matchers_test
import (
"errors"
"github.com/hashicorp/go-multierror"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
pkgerrors "github.com/pkg/errors"
. "github.com/rgalanakis/golangal/errmatch"
Expand Down
2 changes: 1 addition & 1 deletion errmatch/matchers/matchers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package matchers_test
import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

Expand Down
15 changes: 12 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
module github.com/rgalanakis/golangal

go 1.12
go 1.18

require (
github.com/hashicorp/go-multierror v1.1.0
github.com/onsi/ginkgo v1.11.0
github.com/onsi/gomega v1.8.1
github.com/onsi/ginkgo/v2 v2.3.1
github.com/onsi/gomega v1.22.0
github.com/pkg/errors v0.9.1
)

require (
github.com/google/go-cmp v0.5.8 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
43 changes: 16 additions & 27 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,35 +1,24 @@
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.0 h1:B9UzwGQJehnUY1yNrnwREHc3fGbC2xefo8g4TbElacI=
github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.11.0 h1:JAKSXpt1YjtLA7YpPiqO9ss6sNXEsPfSGdwN0UHqzrw=
github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.8.1 h1:C5Dqfs/LeauYDX0jJXIe2SWmwCbGzx9yF8C8xy3Lh34=
github.com/onsi/gomega v1.8.1/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA=
github.com/onsi/ginkgo/v2 v2.3.1 h1:8SbseP7qM32WcvE6VaN6vfXxv698izmsJ1UQX9ve7T8=
github.com/onsi/ginkgo/v2 v2.3.1/go.mod h1:Sv4yQXwG5VmF7tm3Q5Z+RWUpPo24LF1mpnz2crUb8Ys=
github.com/onsi/gomega v1.22.0 h1:AIg2/OntwkBiCg5Tt1ayyiF1ArFrWFoCSMtMi/wdApk=
github.com/onsi/gomega v1.22.0/go.mod h1:iYAIXgPSaDHak0LCMA+AWBpIKBr8WZicMxnE8luStNc=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
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/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
36 changes: 17 additions & 19 deletions golangal.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
package golangal

import (
"github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
"github.com/rgalanakis/golangal/internal"
"github.com/rgalanakis/golangal/matchers"
"io/ioutil"
"os"
)

type ginkgoHook func(body interface{}, timeout ...float64) bool
type ginkgoHook func(args ...interface{}) bool

// EachTempDir returns a function that returns a temporary directory string when invoked
// that is cached across a single test.
// The temporary directory is cleaned up after the test has finished.
//
// Example:
//
// tempdir := golangal.EachTempDir()
// It("writes a file", func() {
// path := filepath.Join(tempdir(), "some-file.txt")
// ...
// })
// tempdir := golangal.EachTempDir()
// It("writes a file", func() {
// path := filepath.Join(tempdir(), "some-file.txt")
// ...
// })
func EachTempDir() func() string {
return eachTempDir("each", ginkgo.BeforeEach, ginkgo.AfterEach)
}
Expand All @@ -46,11 +46,11 @@ func eachTempDir(scope string, before, after ginkgoHook) func() string {
//
// Example:
//
// addEnvVar := golangal.EnvVars()
// It("reads the env", func() {
// addEnvVar("MY_CONFIG_VAR", "XYZ")
// ...
// })
// addEnvVar := golangal.EnvVars()
// It("reads the env", func() {
// addEnvVar("MY_CONFIG_VAR", "XYZ")
// ...
// })
func EnvVars() func(key, value string) {
var envVars map[string]*string
ginkgo.BeforeEach(func() {
Expand Down Expand Up @@ -119,14 +119,13 @@ func MatchLen(m interface{}) gomega.OmegaMatcher {
// If m is a gomega matcher, it is matched against the field value.
// Otherwise, test against field equality.
//
// Expect(MyStruct{Field1: 10}).To(MatchField("Field1", 10))
// Expect(MyStruct{Field1: 10}).To(MatchField("Field1", BeNumerically(">", 5)))
// Expect(MyStruct{Field1: 10}).To(MatchField("Field1", 10))
// Expect(MyStruct{Field1: 10}).To(MatchField("Field1", BeNumerically(">", 5)))
//
// You can match multiple fields by using SatisfyAll or And:
//
// o := MyStruct{Field1: 10, Field2: true}
// Expect(o).To(SatisfyAll(MatchField("Field1", 10), MatchField("Field2", BeTrue())))
//
// o := MyStruct{Field1: 10, Field2: true}
// Expect(o).To(SatisfyAll(MatchField("Field1", 10), MatchField("Field2", BeTrue())))
func MatchField(name string, m interface{}) gomega.OmegaMatcher {
return &matchers.MatchFieldMatcher{Name: name, Matcher: internal.CoerceToMatcher(m)}
}
Expand All @@ -147,8 +146,7 @@ func MatchPtrField(name string, m interface{}) gomega.OmegaMatcher {
// We can circumvent this by using a noop matcher, and allowing Gomega's internal Expect behavior
// to assert that an error wasn't returned (this matcher will fail if it receives an error).
//
// Expect(DoSomethingHard()).To(NotError())
//
// Expect(DoSomethingHard()).To(NotError())
func NotError() gomega.OmegaMatcher {
return &matchers.NotErrorMatcher{}
}
2 changes: 1 addition & 1 deletion golangal_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package golangal_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/rgalanakis/golangal"
"os"
Expand Down
2 changes: 1 addition & 1 deletion matchers/at_every_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package matchers_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/rgalanakis/golangal"
)
Expand Down
2 changes: 1 addition & 1 deletion matchers/at_index_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package matchers_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/rgalanakis/golangal"
)
Expand Down
2 changes: 1 addition & 1 deletion matchers/at_key_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package matchers_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/rgalanakis/golangal"
)
Expand Down
2 changes: 1 addition & 1 deletion matchers/have_header_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package matchers_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/rgalanakis/golangal"
"github.com/rgalanakis/golangal/matchers"
Expand Down
7 changes: 4 additions & 3 deletions matchers/have_json_body_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package matchers_test

import (
"bytes"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/rgalanakis/golangal"
"github.com/rgalanakis/golangal/matchers"
Expand Down Expand Up @@ -32,9 +32,10 @@ var _ = Describe("HaveJsonBodyMatcher", func() {
Expect(success).To(BeFalse())
Expect(err).ToNot(HaveOccurred())
Expect(matcher.FailureMessage(resp)).To(HavePrefix(`Expected
<map[string]interface {} | len:1>: {"a": 1}
<map[string]interface {} | len:1>: {"a": <float64>1}
to have {key: value} matching
<map[interface {}]interface {} | len:1>: {"b": {Expected: 2}}`))
<map[interface {}]interface {} | len:1>: {
<string>"b": <*matchers.BeEquivalentToMatcher | 0`))
})
It("fails if the body is not valid json", func() {
resp := newRr(`{"a`)
Expand Down
2 changes: 1 addition & 1 deletion matchers/have_response_code_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package matchers_test

import (
"bytes"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/rgalanakis/golangal"
"github.com/rgalanakis/golangal/matchers"
Expand Down
2 changes: 1 addition & 1 deletion matchers/match_field_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package matchers_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/rgalanakis/golangal"
)
Expand Down
2 changes: 1 addition & 1 deletion matchers/match_len_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package matchers_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/rgalanakis/golangal"
)
Expand Down
2 changes: 1 addition & 1 deletion matchers/match_ptr_field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package matchers_test

import (
"fmt"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/rgalanakis/golangal"
)
Expand Down
2 changes: 1 addition & 1 deletion matchers/matchers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package matchers_test
import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

Expand Down
2 changes: 1 addition & 1 deletion matchers/not_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package matchers_test

import (
"errors"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/rgalanakis/golangal"
)
Expand Down

0 comments on commit 3337e47

Please sign in to comment.