Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/examples/sequence-diag…
Browse files Browse the repository at this point in the history
…rams-with-postgres-database/github.com/go-spectest/spectest-0.0.18
  • Loading branch information
nao1215 authored Mar 17, 2024
2 parents 4e35638 + 421f486 commit 836bb6f
Show file tree
Hide file tree
Showing 30 changed files with 377 additions and 147 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/linux_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: "1"
check-latest: true

- name: Run tests with coverage report output
run: go test -cover -coverpkg=./... -coverprofile=coverage.out ./...
- uses: k1LoW/octocov-action@v0
- uses: k1LoW/octocov-action@v1
2 changes: 1 addition & 1 deletion .github/workflows/mac_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: "1"
check-latest: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/multi_ver_unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: "1"
check-latest: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: "1"
check-latest: true
Expand Down
220 changes: 220 additions & 0 deletions assert_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
package spectest

import (
"fmt"
"net/http"
"testing"
)

type mockTestingT struct{}

func (m *mockTestingT) Errorf(format string, args ...interface{}) {}
func (m *mockTestingT) Fatal(args ...interface{}) {}
func (m *mockTestingT) Fatalf(format string, args ...interface{}) {}
func (m *mockTestingT) Name() string { return "mock" }

func TestApiTestAssertStatusCodes(t *testing.T) {
tests := []struct {
responseStatus []int
Expand All @@ -30,3 +38,215 @@ func TestApiTestAssertStatusCodes(t *testing.T) {
}
}
}

func Test_DefaultVerifier_True(t *testing.T) {
t.Parallel()
verifier := &DefaultVerifier{}
mock := &mockTestingT{}
tests := []struct {
name string
args bool
want bool
}{
{
name: "should return true",
args: true,
want: true,
},
{
name: "should return false",
args: false,
want: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actual := verifier.True(mock, tt.args)
if actual != tt.want {
t.Fatalf("Expected %t but received %t", actual, tt.want)
}
})
}
}

func Test_DefaultVerifier_JSONEq(t *testing.T) {
t.Parallel()

verifier := &DefaultVerifier{}
mock := &mockTestingT{}

type args struct {
expected string
actual string
}

tests := []struct {
name string
args args
want bool
}{
{
name: "should return true",
args: args{
expected: `{"name":"John","age":30,"car":null}`,
actual: `{"name":"John","age":30,"car":null}`,
},
want: true,
},
{
name: "should failure with different values",
args: args{
expected: `{"name":"John","age":30,"car":null}`,
actual: `{"name":"John","age":31,"car":null}`,
},
want: false,
},
{
name: "should failure to parse expected",
args: args{
expected: `{"name":"John","age":30,"car":null`,
actual: `{"name":"John","age":30,"car":null}`,
},
want: false,
},
{
name: "should failure to parse actual",
args: args{
expected: `{"name":"John","age":30,"car":null}`,
actual: `{"name":"John","age":30,"car":null`,
},
want: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actual := verifier.JSONEq(mock, tt.args.expected, tt.args.actual)
if actual != tt.want {
t.Fatalf("Expected %t but received %t", actual, tt.want)
}
})
}
}

func Test_DefaultVerifier_Equal(t *testing.T) {
t.Parallel()

verifier := &DefaultVerifier{}
mock := &mockTestingT{}

var notOperationFunc = func() {}

type args struct {
expected interface{}
actual interface{}
}

tests := []struct {
name string
args args
want bool
}{
{
name: "should return true",
args: args{
expected: 1,
actual: 1,
},
want: true,
},
{
name: "should return false because not operation function was given",
args: args{
expected: notOperationFunc,
actual: notOperationFunc,
},
want: false,
},
{
name: "should return false because different values",
args: args{
expected: 1,
actual: 2,
},
want: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actual := verifier.Equal(mock, tt.args.expected, tt.args.actual)
if actual != tt.want {
t.Fatalf("Expected %t but received %t", actual, tt.want)
}
})
}
}

func Test_DefaultVerifier_Fail(t *testing.T) {
t.Parallel()

verifier := &DefaultVerifier{}
mock := &mockTestingT{}

tests := []struct {
name string
args []interface{}
t TestingT
}{
{
// FIXME: change the name of this test more better
name: "pat1",
args: []interface{}{},
t: mock,
},
{
name: "pat2",
args: []interface{}{"foo"},
t: mock,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
res := verifier.Fail(tt.t, tt.name, tt.args...)
if res {
t.Fatal("Expected false but received true")
}
})
}
}

func Test_DefaultVerifier_NoError(t *testing.T) {
t.Parallel()

verifier := &DefaultVerifier{}
mock := &mockTestingT{}

tests := []struct {
name string
args error
want bool
}{
{
name: "should return true",
args: nil,
want: true,
},
{
name: "should return false",
args: fmt.Errorf("error"),
want: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actual := verifier.NoError(mock, tt.args)
if actual != tt.want {
t.Fatalf("Expected %t but received %t", actual, tt.want)
}
})
}
}
14 changes: 7 additions & 7 deletions examples/echo/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/go-spectest/spectest/examples/echo
go 1.18

require (
github.com/go-spectest/spectest v0.0.15
github.com/go-spectest/spectest v0.0.18
github.com/labstack/echo v3.3.10+incompatible
)

Expand All @@ -12,21 +12,21 @@ require (
github.com/PaesslerAG/jsonpath v0.1.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-spectest/diff v0.0.0-20231006143314-ce490574d4a9 // indirect
github.com/go-spectest/markdown v0.0.6 // indirect
github.com/go-spectest/markdown v0.0.7 // indirect
github.com/go-spectest/mermaid v0.0.1 // indirect
github.com/karrick/godirwalk v1.17.0 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/mattn/go-colorable v0.1.11 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/nao1215/gorky v0.2.1 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/tenntenn/testtime v0.2.2 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.1 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
)
29 changes: 16 additions & 13 deletions examples/echo/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,26 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-spectest/diff v0.0.0-20231006143314-ce490574d4a9 h1:I05FIUaZLNe9Jo6ZCvODDGBqHMk3TYd7V/wV9dZhwXk=
github.com/go-spectest/diff v0.0.0-20231006143314-ce490574d4a9/go.mod h1:wWRXl4ClWLDIPkL/lS8SSxojHRg1cGngvPcya/mYhf0=
github.com/go-spectest/markdown v0.0.6 h1:S1KBMTYLwaF+gscqdG2XU4ne0axqAWDuFuGrOOv2a80=
github.com/go-spectest/markdown v0.0.6/go.mod h1:OaFedfVlu5+eqe5tI2j3+LD/39T7k5JZAklxTul98EQ=
github.com/go-spectest/markdown v0.0.7 h1:Pr+A/YBCtEruReeMMzBKQ4ftvNtlWuaiWRqgNaETA8Q=
github.com/go-spectest/markdown v0.0.7/go.mod h1:OaFedfVlu5+eqe5tI2j3+LD/39T7k5JZAklxTul98EQ=
github.com/go-spectest/mermaid v0.0.1 h1:Mi4dxGbdW1swgOqsUaSNQaKHO/mgO7Afk0Qwt4ASa2Y=
github.com/go-spectest/mermaid v0.0.1/go.mod h1:S3YmRsGuV/EsSadoMn1C/XHr8+aXZ33UON8nuD+xi3w=
github.com/go-spectest/spectest v0.0.15 h1:eSKPVVjnD+gNYOxZ8vfV3B7gR/e3yi6/kc9lqQddNFs=
github.com/go-spectest/spectest v0.0.15/go.mod h1:fgAZM8EeVPEE5/dIS0AHY9SPzy5IYVu+ZxLZXstqA1U=
github.com/go-spectest/spectest v0.0.18 h1:ni/m9HQJpnt2OhOMk0iKwR3PcxVVm57bycvCePJj+Uk=
github.com/go-spectest/spectest v0.0.18/go.mod h1:uJr62Wbe6+vJ4xepfId8aodSOulwOl6Y1ikRJbKhWdE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/karrick/godirwalk v1.17.0 h1:b4kY7nqDdioR/6qnbHQyDvmA17u5G1cZ6J+CZXwSWoI=
github.com/karrick/godirwalk v1.17.0/go.mod h1:j4mkqPuvaLI8mp1DroR3P6ad7cyYd4c1qeJ3RV7ULlk=
github.com/labstack/echo v3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8bbnE7CX5OEgg=
github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s=
github.com/labstack/gommon v0.4.0 h1:y7cvthEAEbU0yHOf4axH8ZG2NH8knB9iNSoTO8dyIk8=
github.com/labstack/gommon v0.4.0/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
github.com/mattn/go-colorable v0.1.11 h1:nQ+aFkoE2TMGc0b68U2OKSexC+eq46+XwZzWXHRmPYs=
github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98=
github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
Expand All @@ -47,8 +49,8 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyC
github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52WA1u4=
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
Expand All @@ -57,12 +59,13 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
Loading

0 comments on commit 836bb6f

Please sign in to comment.