Skip to content

Commit 836bb6f

Browse files
authored
Merge branch 'main' into dependabot/go_modules/examples/sequence-diagrams-with-postgres-database/github.com/go-spectest/spectest-0.0.18
2 parents 4e35638 + 421f486 commit 836bb6f

File tree

30 files changed

+377
-147
lines changed

30 files changed

+377
-147
lines changed

.github/workflows/linux_test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ jobs:
2020
steps:
2121
- uses: actions/checkout@v4
2222

23-
- uses: actions/setup-go@v4
23+
- uses: actions/setup-go@v5
2424
with:
2525
go-version: "1"
2626
check-latest: true
2727

2828
- name: Run tests with coverage report output
2929
run: go test -cover -coverpkg=./... -coverprofile=coverage.out ./...
30-
- uses: k1LoW/octocov-action@v0
30+
- uses: k1LoW/octocov-action@v1

.github/workflows/mac_test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
steps:
2121
- uses: actions/checkout@v4
2222

23-
- uses: actions/setup-go@v4
23+
- uses: actions/setup-go@v5
2424
with:
2525
go-version: "1"
2626
check-latest: true

.github/workflows/multi_ver_unittest.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
steps:
1616
- uses: actions/checkout@v4
1717
- name: Setup Go ${{ matrix.go-version }}
18-
uses: actions/setup-go@v4
18+
uses: actions/setup-go@v5
1919
with:
2020
go-version: ${{ matrix.go-version }}
2121

.github/workflows/test-examples.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
steps:
2121
- uses: actions/checkout@v4
2222

23-
- uses: actions/setup-go@v4
23+
- uses: actions/setup-go@v5
2424
with:
2525
go-version: "1"
2626
check-latest: true

.github/workflows/windows_test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
steps:
2121
- uses: actions/checkout@v4
2222

23-
- uses: actions/setup-go@v4
23+
- uses: actions/setup-go@v5
2424
with:
2525
go-version: "1"
2626
check-latest: true

assert_test.go

+220
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
package spectest
22

33
import (
4+
"fmt"
45
"net/http"
56
"testing"
67
)
78

9+
type mockTestingT struct{}
10+
11+
func (m *mockTestingT) Errorf(format string, args ...interface{}) {}
12+
func (m *mockTestingT) Fatal(args ...interface{}) {}
13+
func (m *mockTestingT) Fatalf(format string, args ...interface{}) {}
14+
func (m *mockTestingT) Name() string { return "mock" }
15+
816
func TestApiTestAssertStatusCodes(t *testing.T) {
917
tests := []struct {
1018
responseStatus []int
@@ -30,3 +38,215 @@ func TestApiTestAssertStatusCodes(t *testing.T) {
3038
}
3139
}
3240
}
41+
42+
func Test_DefaultVerifier_True(t *testing.T) {
43+
t.Parallel()
44+
verifier := &DefaultVerifier{}
45+
mock := &mockTestingT{}
46+
tests := []struct {
47+
name string
48+
args bool
49+
want bool
50+
}{
51+
{
52+
name: "should return true",
53+
args: true,
54+
want: true,
55+
},
56+
{
57+
name: "should return false",
58+
args: false,
59+
want: false,
60+
},
61+
}
62+
63+
for _, tt := range tests {
64+
t.Run(tt.name, func(t *testing.T) {
65+
actual := verifier.True(mock, tt.args)
66+
if actual != tt.want {
67+
t.Fatalf("Expected %t but received %t", actual, tt.want)
68+
}
69+
})
70+
}
71+
}
72+
73+
func Test_DefaultVerifier_JSONEq(t *testing.T) {
74+
t.Parallel()
75+
76+
verifier := &DefaultVerifier{}
77+
mock := &mockTestingT{}
78+
79+
type args struct {
80+
expected string
81+
actual string
82+
}
83+
84+
tests := []struct {
85+
name string
86+
args args
87+
want bool
88+
}{
89+
{
90+
name: "should return true",
91+
args: args{
92+
expected: `{"name":"John","age":30,"car":null}`,
93+
actual: `{"name":"John","age":30,"car":null}`,
94+
},
95+
want: true,
96+
},
97+
{
98+
name: "should failure with different values",
99+
args: args{
100+
expected: `{"name":"John","age":30,"car":null}`,
101+
actual: `{"name":"John","age":31,"car":null}`,
102+
},
103+
want: false,
104+
},
105+
{
106+
name: "should failure to parse expected",
107+
args: args{
108+
expected: `{"name":"John","age":30,"car":null`,
109+
actual: `{"name":"John","age":30,"car":null}`,
110+
},
111+
want: false,
112+
},
113+
{
114+
name: "should failure to parse actual",
115+
args: args{
116+
expected: `{"name":"John","age":30,"car":null}`,
117+
actual: `{"name":"John","age":30,"car":null`,
118+
},
119+
want: false,
120+
},
121+
}
122+
123+
for _, tt := range tests {
124+
t.Run(tt.name, func(t *testing.T) {
125+
actual := verifier.JSONEq(mock, tt.args.expected, tt.args.actual)
126+
if actual != tt.want {
127+
t.Fatalf("Expected %t but received %t", actual, tt.want)
128+
}
129+
})
130+
}
131+
}
132+
133+
func Test_DefaultVerifier_Equal(t *testing.T) {
134+
t.Parallel()
135+
136+
verifier := &DefaultVerifier{}
137+
mock := &mockTestingT{}
138+
139+
var notOperationFunc = func() {}
140+
141+
type args struct {
142+
expected interface{}
143+
actual interface{}
144+
}
145+
146+
tests := []struct {
147+
name string
148+
args args
149+
want bool
150+
}{
151+
{
152+
name: "should return true",
153+
args: args{
154+
expected: 1,
155+
actual: 1,
156+
},
157+
want: true,
158+
},
159+
{
160+
name: "should return false because not operation function was given",
161+
args: args{
162+
expected: notOperationFunc,
163+
actual: notOperationFunc,
164+
},
165+
want: false,
166+
},
167+
{
168+
name: "should return false because different values",
169+
args: args{
170+
expected: 1,
171+
actual: 2,
172+
},
173+
want: false,
174+
},
175+
}
176+
177+
for _, tt := range tests {
178+
t.Run(tt.name, func(t *testing.T) {
179+
actual := verifier.Equal(mock, tt.args.expected, tt.args.actual)
180+
if actual != tt.want {
181+
t.Fatalf("Expected %t but received %t", actual, tt.want)
182+
}
183+
})
184+
}
185+
}
186+
187+
func Test_DefaultVerifier_Fail(t *testing.T) {
188+
t.Parallel()
189+
190+
verifier := &DefaultVerifier{}
191+
mock := &mockTestingT{}
192+
193+
tests := []struct {
194+
name string
195+
args []interface{}
196+
t TestingT
197+
}{
198+
{
199+
// FIXME: change the name of this test more better
200+
name: "pat1",
201+
args: []interface{}{},
202+
t: mock,
203+
},
204+
{
205+
name: "pat2",
206+
args: []interface{}{"foo"},
207+
t: mock,
208+
},
209+
}
210+
211+
for _, tt := range tests {
212+
t.Run(tt.name, func(t *testing.T) {
213+
res := verifier.Fail(tt.t, tt.name, tt.args...)
214+
if res {
215+
t.Fatal("Expected false but received true")
216+
}
217+
})
218+
}
219+
}
220+
221+
func Test_DefaultVerifier_NoError(t *testing.T) {
222+
t.Parallel()
223+
224+
verifier := &DefaultVerifier{}
225+
mock := &mockTestingT{}
226+
227+
tests := []struct {
228+
name string
229+
args error
230+
want bool
231+
}{
232+
{
233+
name: "should return true",
234+
args: nil,
235+
want: true,
236+
},
237+
{
238+
name: "should return false",
239+
args: fmt.Errorf("error"),
240+
want: false,
241+
},
242+
}
243+
244+
for _, tt := range tests {
245+
t.Run(tt.name, func(t *testing.T) {
246+
actual := verifier.NoError(mock, tt.args)
247+
if actual != tt.want {
248+
t.Fatalf("Expected %t but received %t", actual, tt.want)
249+
}
250+
})
251+
}
252+
}

examples/echo/go.mod

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/go-spectest/spectest/examples/echo
33
go 1.18
44

55
require (
6-
github.com/go-spectest/spectest v0.0.15
6+
github.com/go-spectest/spectest v0.0.18
77
github.com/labstack/echo v3.3.10+incompatible
88
)
99

@@ -12,21 +12,21 @@ require (
1212
github.com/PaesslerAG/jsonpath v0.1.1 // indirect
1313
github.com/davecgh/go-spew v1.1.1 // indirect
1414
github.com/go-spectest/diff v0.0.0-20231006143314-ce490574d4a9 // indirect
15-
github.com/go-spectest/markdown v0.0.6 // indirect
15+
github.com/go-spectest/markdown v0.0.7 // indirect
1616
github.com/go-spectest/mermaid v0.0.1 // indirect
1717
github.com/karrick/godirwalk v1.17.0 // indirect
1818
github.com/labstack/gommon v0.4.0 // indirect
19-
github.com/mattn/go-colorable v0.1.11 // indirect
20-
github.com/mattn/go-isatty v0.0.18 // indirect
19+
github.com/mattn/go-colorable v0.1.13 // indirect
20+
github.com/mattn/go-isatty v0.0.20 // indirect
2121
github.com/mattn/go-runewidth v0.0.14 // indirect
2222
github.com/nao1215/gorky v0.2.1 // indirect
2323
github.com/olekukonko/tablewriter v0.0.5 // indirect
2424
github.com/rivo/uniseg v0.2.0 // indirect
2525
github.com/tenntenn/testtime v0.2.2 // indirect
2626
github.com/valyala/bytebufferpool v1.0.0 // indirect
2727
github.com/valyala/fasttemplate v1.2.1 // indirect
28-
golang.org/x/crypto v0.14.0 // indirect
28+
golang.org/x/crypto v0.17.0 // indirect
2929
golang.org/x/net v0.17.0 // indirect
30-
golang.org/x/sys v0.13.0 // indirect
31-
golang.org/x/text v0.13.0 // indirect
30+
golang.org/x/sys v0.15.0 // indirect
31+
golang.org/x/text v0.14.0 // indirect
3232
)

examples/echo/go.sum

+16-13
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,26 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
88
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
99
github.com/go-spectest/diff v0.0.0-20231006143314-ce490574d4a9 h1:I05FIUaZLNe9Jo6ZCvODDGBqHMk3TYd7V/wV9dZhwXk=
1010
github.com/go-spectest/diff v0.0.0-20231006143314-ce490574d4a9/go.mod h1:wWRXl4ClWLDIPkL/lS8SSxojHRg1cGngvPcya/mYhf0=
11-
github.com/go-spectest/markdown v0.0.6 h1:S1KBMTYLwaF+gscqdG2XU4ne0axqAWDuFuGrOOv2a80=
12-
github.com/go-spectest/markdown v0.0.6/go.mod h1:OaFedfVlu5+eqe5tI2j3+LD/39T7k5JZAklxTul98EQ=
11+
github.com/go-spectest/markdown v0.0.7 h1:Pr+A/YBCtEruReeMMzBKQ4ftvNtlWuaiWRqgNaETA8Q=
12+
github.com/go-spectest/markdown v0.0.7/go.mod h1:OaFedfVlu5+eqe5tI2j3+LD/39T7k5JZAklxTul98EQ=
1313
github.com/go-spectest/mermaid v0.0.1 h1:Mi4dxGbdW1swgOqsUaSNQaKHO/mgO7Afk0Qwt4ASa2Y=
1414
github.com/go-spectest/mermaid v0.0.1/go.mod h1:S3YmRsGuV/EsSadoMn1C/XHr8+aXZ33UON8nuD+xi3w=
15-
github.com/go-spectest/spectest v0.0.15 h1:eSKPVVjnD+gNYOxZ8vfV3B7gR/e3yi6/kc9lqQddNFs=
16-
github.com/go-spectest/spectest v0.0.15/go.mod h1:fgAZM8EeVPEE5/dIS0AHY9SPzy5IYVu+ZxLZXstqA1U=
15+
github.com/go-spectest/spectest v0.0.18 h1:ni/m9HQJpnt2OhOMk0iKwR3PcxVVm57bycvCePJj+Uk=
16+
github.com/go-spectest/spectest v0.0.18/go.mod h1:uJr62Wbe6+vJ4xepfId8aodSOulwOl6Y1ikRJbKhWdE=
1717
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
1818
github.com/karrick/godirwalk v1.17.0 h1:b4kY7nqDdioR/6qnbHQyDvmA17u5G1cZ6J+CZXwSWoI=
1919
github.com/karrick/godirwalk v1.17.0/go.mod h1:j4mkqPuvaLI8mp1DroR3P6ad7cyYd4c1qeJ3RV7ULlk=
2020
github.com/labstack/echo v3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8bbnE7CX5OEgg=
2121
github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s=
2222
github.com/labstack/gommon v0.4.0 h1:y7cvthEAEbU0yHOf4axH8ZG2NH8knB9iNSoTO8dyIk8=
2323
github.com/labstack/gommon v0.4.0/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
24-
github.com/mattn/go-colorable v0.1.11 h1:nQ+aFkoE2TMGc0b68U2OKSexC+eq46+XwZzWXHRmPYs=
2524
github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
25+
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
26+
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
2627
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
27-
github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98=
28-
github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
28+
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
29+
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
30+
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
2931
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
3032
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
3133
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
@@ -47,8 +49,8 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyC
4749
github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52WA1u4=
4850
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
4951
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
50-
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
51-
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
52+
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
53+
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
5254
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
5355
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
5456
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
@@ -57,12 +59,13 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
5759
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
5860
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
5961
golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
62+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
6063
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
61-
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
62-
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
64+
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
65+
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
6366
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
64-
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
65-
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
67+
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
68+
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
6669
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
6770
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
6871
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

0 commit comments

Comments
 (0)