Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove Gomega dependency in favour of Testify #206

Merged
merged 2 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ require (
github.com/asyncapi/converter-go v0.3.0
github.com/asyncapi/spec-json-schemas/v4 v4.3.1
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815
github.com/onsi/gomega v1.27.10
github.com/onsi/gomega v1.27.10 // indirect
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.8.2
github.com/xeipuuv/gojsonpointer v0.0.0-20190809123943-df4f5c81cb3b // indirect
github.com/xeipuuv/gojsonschema v1.2.0
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
github.com/xeipuuv/gojsonpointer v0.0.0-20190809123943-df4f5c81cb3b h1:6cLsL+2FW6dRAdl5iMtHgRogVCff0QpRi9653YmdcJA=
github.com/xeipuuv/gojsonpointer v0.0.0-20190809123943-df4f5c81cb3b/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
Expand Down
5 changes: 2 additions & 3 deletions pkg/decode/decode_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package decode

import (
. "github.com/onsi/gomega"
"github.com/stretchr/testify/assert"

"strings"
"testing"
)

func TestToMap1(t *testing.T) {
g := NewWithT(t)
reader := strings.NewReader("123")
_, err := ToMap(reader)
g.Expect(err).Should(HaveOccurred())
assert.Error(t, err)
}
13 changes: 5 additions & 8 deletions pkg/error/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@ package error
import (
"testing"

"github.com/pkg/errors"
"github.com/stretchr/testify/assert"

. "github.com/onsi/gomega"
"github.com/pkg/errors"
)

var errTest = errors.New("test error")

func TestNewNil(t *testing.T) {
g := NewWithT(t)
err := New()
g.Expect(err).To(BeNil())
assert.NoError(t, err)
}

func TestNew(t *testing.T) {
g := NewWithT(t)
err := New(errTest)
g.Expect(err.Error()).To(Equal("test error"))
assert.Error(t, err, "test error")
}

func TestJoin(t *testing.T) {
Expand All @@ -46,9 +44,8 @@ func TestJoin(t *testing.T) {
}
for _, tC := range testCases {
t.Run(tC.desc, func(t *testing.T) {
g := NewWithT(t)
errMsg := Join(tC.errs, "|")
g.Expect(errMsg).To(Equal(tC.expectedMessage))
assert.Equal(t, tC.expectedMessage, errMsg)
})
}
}
15 changes: 7 additions & 8 deletions pkg/jsonpath/loader_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package jsonpath

import (
. "github.com/onsi/gomega"

"bytes"
"encoding/json"
"io"
"io/ioutil"
"net/http"
"testing"

"github.com/stretchr/testify/assert"
)

func data() io.ReadCloser {
Expand Down Expand Up @@ -45,13 +45,13 @@ func TestLoader(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
g := NewWithT(t)
loader := NewRefLoader(&ClientMock{})
actual, err := loader.Load(test.name)
g.Expect(err).ShouldNot(HaveOccurred())
g.Expect(actual).To(Equal(map[string]interface{}{
assert.NoError(t, err)
expected := map[string]interface{}{
"test": "me",
}))
}
assert.Equal(t, expected, actual)
})
}
}
Expand All @@ -65,10 +65,9 @@ func TestLoaderErr(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
g := NewWithT(t)
loader := NewRefLoader(&ClientMock{})
_, err := loader.Load(test.name)
g.Expect(err).Should(HaveOccurred())
assert.Error(t, err)
})
}
}
31 changes: 14 additions & 17 deletions pkg/jsonpath/reference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package jsonpath

import (
"fmt"
. "github.com/onsi/gomega"
"testing"

"github.com/stretchr/testify/assert"
)

func TestDecodeItemName(t *testing.T) {
Expand All @@ -26,10 +27,9 @@ func TestDecodeItemName(t *testing.T) {
}
for _, test := range tests {
t.Run(fmt.Sprintf(`Expect:"%s"`, test.expected), func(t *testing.T) {
g := NewWithT(t)
actual, err := DecodeEntryKey(test.name)
g.Expect(err).ShouldNot(HaveOccurred())
g.Expect(actual).To(Equal(test.expected))
assert.NoError(t, err)
assert.Equal(t, test.expected, actual)
})
}
}
Expand All @@ -51,9 +51,8 @@ func TestDecodeItemNameErr(t *testing.T) {
}
for _, test := range tests {
t.Run(fmt.Sprintf(`Expect err:"%s"`, test.name), func(t *testing.T) {
g := NewWithT(t)
_, err := DecodeEntryKey(test.name)
g.Expect(err).Should(HaveOccurred())
assert.Error(t, err)
})
}
}
Expand All @@ -65,8 +64,7 @@ func TestNewReference(t *testing.T) {
}{
{
strRef: "/test/path#/test/me/plz",
expected:
Ref{
expected: Ref{
pointer: "/test/me/plz",
uri: "/test/path",
path: []string{"test", "me", "plz"},
Expand All @@ -75,10 +73,9 @@ func TestNewReference(t *testing.T) {
}
for _, test := range tests {
t.Run(test.strRef, func(t *testing.T) {
g := NewWithT(t)
ref, err := NewRef(test.strRef)
g.Expect(err).ShouldNot(HaveOccurred())
g.Expect(ref).To(Equal(test.expected))
assert.NoError(t, err)
assert.Equal(t, test.expected, ref)
})
}
}
Expand All @@ -89,15 +86,13 @@ func TestNewReference_ShouldReturnError(t *testing.T) {
"",
} {
t.Run(test, func(t *testing.T) {
g := NewWithT(t)
_, err := NewRef(test)
g.Expect(err).Should(HaveOccurred())
assert.Error(t, err)
})
}
}

func TestGetRefObject(t *testing.T) {
g := NewWithT(t)
v := map[string]interface{}{
"test": map[string]interface{}{
"me": map[string]interface{}{
Expand All @@ -106,8 +101,10 @@ func TestGetRefObject(t *testing.T) {
},
}
actual, err := GetRefObject([]string{"test", "me"}, v)
g.Expect(err).ShouldNot(HaveOccurred())
g.Expect(actual).To(Equal(map[string]interface{}{
assert.NoError(t, err)

expected := map[string]interface{}{
"plz": true,
}))
}
assert.Equal(t, expected, actual)
}
12 changes: 5 additions & 7 deletions pkg/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"path/filepath"
"testing"

. "github.com/onsi/gomega"
"github.com/stretchr/testify/assert"
)

const oneOfJSONFile = "./testdata/oneof.json"
Expand All @@ -19,13 +19,12 @@ var (
)

func TestMessageProcessor_BuildParser(t *testing.T) {
g := NewWithT(t)
parse := noopMessageProcessor.BuildParser()
writer := bytes.NewBufferString("")
reader, err := os.Open(oneOfJSONFile)
g.Expect(err).ShouldNot(HaveOccurred())
assert.NoError(t, err)
err = parse(reader, writer)
g.Expect(err).ShouldNot(HaveOccurred())
assert.NoError(t, err)
}

func TestNewReader(t *testing.T) {
Expand Down Expand Up @@ -54,10 +53,9 @@ func TestNewReader(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
g := NewWithT(t)
r, err := NewReader(test.doc)
g.Expect(err).ShouldNot(HaveOccurred())
g.Expect(r).ShouldNot(BeNil())
assert.NoError(t, err)
assert.NotNil(t, r)
})
}
}
9 changes: 4 additions & 5 deletions pkg/parser/v2/hlsp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package v2
import (
"github.com/asyncapi/parser-go/pkg/decode"
"github.com/asyncapi/parser-go/pkg/jsonpath"
. "github.com/onsi/gomega"
"github.com/stretchr/testify/assert"

"fmt"
"net/http"
Expand Down Expand Up @@ -53,16 +53,15 @@ func TestParser_Parse(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
g := NewWithT(t)
refLoader := jsonpath.NewRefLoader(http.DefaultClient)
p := NewParser(refLoader, test.blackListedPaths...)
err := p.Parse(test.doc)
if test.expectedErr {
g.Expect(err).Should(HaveOccurred())
assert.Error(t, err)
return
}
g.Expect(err).ShouldNot(HaveOccurred())
g.Expect(test.doc).To(Equal(test.expectedDoc))
assert.NoError(t, err)
assert.Equal(t, test.expectedDoc, test.doc)
})
}
}
Expand Down
22 changes: 10 additions & 12 deletions pkg/schema/asyncapi/v2/message_processor_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package v2

import (
. "github.com/onsi/gomega"

"encoding/json"
"errors"
"fmt"
"os"
"testing"

"github.com/stretchr/testify/assert"
)

func Test_schemaFormat(t *testing.T) {
Expand Down Expand Up @@ -38,9 +38,8 @@ func Test_schemaFormat(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
g := NewWithT(t)
format := schemaFormat(tt.args.m)
g.Expect(format).To(Equal(tt.want))
assert.Equal(t, tt.want, format)
})
}
}
Expand Down Expand Up @@ -70,11 +69,11 @@ func TestDispatcher_Add(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
g := NewWithT(t)
err := tt.d.Add(tt.args.pm, tt.args.labels...)
g.Expect(err).ShouldNot(HaveOccurred())
assert.NoError(t, err)

for _, label := range tt.args.labels {
g.Expect(tt.d[label]).NotTo(BeNil())
assert.NotNil(t, tt.d[label])
}
})
}
Expand Down Expand Up @@ -112,19 +111,18 @@ func Test_extractMessages(t *testing.T) {
panic(fmt.Sprintf("invalid test data in: '%s'", tt.channelFile))
}
t.Run(tt.name, func(t *testing.T) {
g := NewWithT(t)
got, err := extractMessages(channel)
if tt.wantErr {
g.Expect(err).Should(HaveOccurred())
assert.NoError(t, err)
return
}
g.Expect(got).To(Equal(expectedMsgs))

assert.Equal(t, expectedMsgs, got)
})
}
}

func TestBuildMessageProcessor(t *testing.T) {
g := NewWithT(t)
testErr := errors.New("test error")
d := Dispatcher{
"test1": func(_ interface{}) error {
Expand All @@ -142,7 +140,7 @@ func TestBuildMessageProcessor(t *testing.T) {
}
processMessages := BuildMessageProcessor(d)
err = processMessages(document)
g.Expect(err).Should(HaveOccurred())
assert.Error(t, err)
}

func load(path string, v interface{}, t *testing.T) error {
Expand Down
7 changes: 3 additions & 4 deletions pkg/schema/jsonschema/draft07/jsonschema_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package draft07

import (
. "github.com/onsi/gomega"
"github.com/stretchr/testify/assert"

"encoding/json"
"testing"
)

func TestParseInvalidSchemaObject(t *testing.T) {
g := NewWithT(t)
v := "this will not work"
err := Parse(v)
g.Expect(err).Should(HaveOccurred())
assert.Error(t, err)
}

func TestParse(t *testing.T) {
Expand All @@ -31,7 +30,7 @@ func TestParse(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
err := Parse(&test.v)
NewWithT(t).Expect(err).ShouldNot(HaveOccurred())
assert.NoError(t, err)
})
}
}
Expand Down
Loading
Loading