Skip to content

Commit

Permalink
update go version and get rid of testify (fix #12)
Browse files Browse the repository at this point in the history
  • Loading branch information
josuebrunel committed Mar 14, 2023
1 parent d1a7f77 commit f455e5d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 49 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.13.x, 1.14.x, 1.15.x]
go-version: [">=1.20.x"]
os: [ubuntu-latest,]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -27,16 +27,13 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: coverage.lcov
- name: Check lint
run: |
go get -u golang.org/x/lint/golint
golint ./...

doc:
name: Renew documentation
runs-on: ubuntu-latest
steps:
- name: Pull new module version
run: go get -u github.com/josuebrunel/echowbt
run: go list -m
env:
GOPROXY: https://proxy.golang.org
GO111MODULE: on
Expand Down
15 changes: 13 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
module github.com/josuebrunel/echowbt

go 1.13
go 1.20

require (
github.com/labstack/echo/v4 v4.1.17
github.com/labstack/gommon v0.3.0
github.com/stretchr/testify v1.4.0
)

require (
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/mattn/go-colorable v0.1.7 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.1 // indirect
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect
golang.org/x/net v0.0.0-20200822124328-c89045814202 // indirect
golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6 // indirect
golang.org/x/text v0.3.3 // indirect
)
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
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=
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/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
80 changes: 40 additions & 40 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package echowbt

import (
"fmt"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/labstack/gommon/log"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"net/http"
"reflect"
"strings"
"testing"

"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/labstack/gommon/log"
)

type User struct {
Expand Down Expand Up @@ -94,73 +94,73 @@ func App() (app Application) {
return
}

type EchoWBTestSuite struct {
suite.Suite
Client Client
func assert(t *testing.T, x, y any) {
if !reflect.DeepEqual(x, y) {
t.Fatalf("AssertionError: %v != %v", x, y)
}
}

func (e *EchoWBTestSuite) SetupSuite() {
e.Client = New()
e.Client.SetHeaders(DictString{"Authorization": "Token <mytoken>"})
func NewTestClient() Client {
client := New()
client.SetHeaders(DictString{"Authorization": "Token <mytoken>"})
return client
}

func TestEchoWBT(t *testing.T) {
suite.Run(t, new(EchoWBTestSuite))
}
var testclient Client = NewTestClient()

func (e *EchoWBTestSuite) TestGet() {
func TestGet(t *testing.T) {
url := NewURL("/", nil, nil)
rec := e.Client.Get(url, GenericHandler(), nil, DictString{})
assert.Equal(e.T(), http.StatusOK, rec.Code)
rec := testclient.Get(url, GenericHandler(), nil, DictString{})
assert(t, http.StatusOK, rec.Code)
url = NewURL("/", nil, DictString{"lastname": "kouka", "firstname": "kim"})
rec = e.Client.Get(url, GenericHandler(), nil, DictString{})
assert.Equal(e.T(), http.StatusOK, rec.Code)
rec = testclient.Get(url, GenericHandler(), nil, DictString{})
assert(t, http.StatusOK, rec.Code)
url = NewURL("/:id", DictString{"id": "1"}, nil)
rec = e.Client.Get(url, GenericHandler(), nil, DictString{})
assert.Equal(e.T(), http.StatusOK, rec.Code)
rec = testclient.Get(url, GenericHandler(), nil, DictString{})
assert(t, http.StatusOK, rec.Code)
data := JSONDecode(rec.Body)
assert.Equal(e.T(), "Loking", data["lastname"])
assert(t, "Loking", data["lastname"])
}

func (e *EchoWBTestSuite) TestPost() {
func TestPost(t *testing.T) {
url := URL{Path: "/"}
u := User{Firstname: "Josué", Lastname: "Kouka", Age: 30}
rec := e.Client.Post(url, GenericHandler(), JSONEncode(u), DictString{})
assert.Equal(e.T(), http.StatusCreated, rec.Code)
rec := testclient.Post(url, GenericHandler(), JSONEncode(u), DictString{})
assert(t, http.StatusCreated, rec.Code)
// post form
headers := DictString{"Content-Type": "application/x-www-form-urlencoded"}
rec = e.Client.Post(url, GenericHandler(), []byte("firstname=Josué&lastname=Kouka"), headers)
assert.Equal(e.T(), "Hello Josué", rec.Body.String())
rec = testclient.Post(url, GenericHandler(), []byte("firstname=Josué&lastname=Kouka"), headers)
assert(t, "Hello Josué", rec.Body.String())
}

func (e *EchoWBTestSuite) TestPostMultipartForm() {
func TestPostMultipartForm(t *testing.T) {
url := URL{Path: "/"}
form, _ := FormData(DictString{"firstname": "Josué", "lastname": "Kouka"}, DictString{"bio": "testdata/bio.txt"})
headers := DictString{"Content-Type": form.ContentType}
rec := e.Client.Post(url, GenericHandler(), form.Data, headers)
assert.Equal(e.T(), http.StatusCreated, rec.Code)
rec := testclient.Post(url, GenericHandler(), form.Data, headers)
assert(t, http.StatusCreated, rec.Code)
expected := "Hello Josué ! Your file bio.txt is up."
assert.Equal(e.T(), expected, rec.Body.String())
assert(t, expected, rec.Body.String())
}

func (e *EchoWBTestSuite) TestPut() {
func TestPut(t *testing.T) {
url := NewURL("/:id", DictString{"id": "1"}, nil)
u := User{Firstname: "Josué", Lastname: "Kouka", Age: 30}
headers := DictString{"Authorization": "Bearer <mytoken>"}
rec := e.Client.Put(url, GenericHandler(), JSONEncode(u), headers)
assert.Equal(e.T(), http.StatusNoContent, rec.Code)
rec := testclient.Put(url, GenericHandler(), JSONEncode(u), headers)
assert(t, http.StatusNoContent, rec.Code)
}

func (e *EchoWBTestSuite) TestPatch() {
func TestPatch(t *testing.T) {
url := NewURL("/:id", DictString{"id": "1"}, nil)
u := User{Firstname: "Josué", Lastname: "Kouka", Age: 30}
headers := DictString{"Authorization": "Bearer <mytoken>"}
rec := e.Client.Patch(url, GenericHandler(), JSONEncode(u), headers)
assert.Equal(e.T(), http.StatusNoContent, rec.Code)
rec := testclient.Patch(url, GenericHandler(), JSONEncode(u), headers)
assert(t, http.StatusNoContent, rec.Code)
}

func (e *EchoWBTestSuite) TestDelete() {
func TestDelete(t *testing.T) {
url := NewURL("/:id", DictString{"id": "1"}, nil)
rec := e.Client.Delete(url, GenericHandler(), nil, DictString{})
assert.Equal(e.T(), http.StatusAccepted, rec.Code)
rec := testclient.Delete(url, GenericHandler(), nil, DictString{})
assert(t, http.StatusAccepted, rec.Code)
}

0 comments on commit f455e5d

Please sign in to comment.