webtest: without assert
continuous-integration/drone the build failed
Details
continuous-integration/drone the build failed
Details
This commit is contained in:
parent
48b828b029
commit
d38a2a28c3
|
@ -11,13 +11,14 @@ import (
|
|||
|
||||
func TestAPIStatus(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
s := webtest.New(assert)
|
||||
s, err := webtest.New()
|
||||
assert.NoError(err)
|
||||
defer s.Close()
|
||||
assert.NotNil(s)
|
||||
|
||||
obj := Status{}
|
||||
// GET
|
||||
err := s.Request(http.MethodGet, "/api/status", nil, http.StatusOK, &obj)
|
||||
err = s.Request(http.MethodGet, "/api/status", nil, http.StatusOK, &obj)
|
||||
assert.NoError(err)
|
||||
assert.Equal(VERSION, obj.Version)
|
||||
assert.Equal(EXTRAS, obj.Extras)
|
||||
|
|
|
@ -12,7 +12,8 @@ import (
|
|||
|
||||
func TestAPILogin(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
s := webtest.New(assert)
|
||||
s, err := webtest.New()
|
||||
assert.NoError(err)
|
||||
defer s.Close()
|
||||
assert.NotNil(s)
|
||||
SetupMigration(s.DB)
|
||||
|
@ -20,7 +21,7 @@ func TestAPILogin(t *testing.T) {
|
|||
|
||||
hErr := web.HTTPError{}
|
||||
// invalid
|
||||
err := s.Request(http.MethodPost, "/api/v1/auth/login", 1, http.StatusBadRequest, &hErr)
|
||||
err = s.Request(http.MethodPost, "/api/v1/auth/login", 1, http.StatusBadRequest, &hErr)
|
||||
assert.NoError(err)
|
||||
assert.Equal(web.APIErrorInvalidRequestFormat, hErr.Message)
|
||||
|
||||
|
|
|
@ -13,7 +13,8 @@ import (
|
|||
|
||||
func TestAPIPasswordCode(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
s := webtest.New(assert)
|
||||
s, err := webtest.New()
|
||||
assert.NoError(err)
|
||||
defer s.Close()
|
||||
assert.NotNil(s)
|
||||
SetupMigration(s.DB)
|
||||
|
@ -27,7 +28,7 @@ func TestAPIPasswordCode(t *testing.T) {
|
|||
|
||||
hErr := web.HTTPError{}
|
||||
// invalid
|
||||
err := s.Request(http.MethodPost, "/api/v1/auth/password/code", &passwordNew, http.StatusBadRequest, &hErr)
|
||||
err = s.Request(http.MethodPost, "/api/v1/auth/password/code", &passwordNew, http.StatusBadRequest, &hErr)
|
||||
assert.NoError(err)
|
||||
assert.Equal(web.APIErrorInvalidRequestFormat, hErr.Message)
|
||||
|
||||
|
|
|
@ -12,7 +12,8 @@ import (
|
|||
|
||||
func TestAPIPassword(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
s := webtest.New(assert)
|
||||
s, err := webtest.New()
|
||||
assert.NoError(err)
|
||||
defer s.Close()
|
||||
assert.NotNil(s)
|
||||
SetupMigration(s.DB)
|
||||
|
@ -23,7 +24,7 @@ func TestAPIPassword(t *testing.T) {
|
|||
|
||||
hErr := web.HTTPError{}
|
||||
// no auth
|
||||
err := s.Request(http.MethodPost, "/api/v1/my/auth/password", &passwordNew, http.StatusUnauthorized, &hErr)
|
||||
err = s.Request(http.MethodPost, "/api/v1/my/auth/password", &passwordNew, http.StatusUnauthorized, &hErr)
|
||||
assert.NoError(err)
|
||||
assert.Equal(APIErrorNoSession, hErr.Message)
|
||||
|
||||
|
|
|
@ -12,7 +12,8 @@ import (
|
|||
|
||||
func TestAPIStatus(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
s := webtest.New(assert)
|
||||
s, err := webtest.New()
|
||||
assert.NoError(err)
|
||||
defer s.Close()
|
||||
assert.NotNil(s)
|
||||
SetupMigration(s.DB)
|
||||
|
@ -20,7 +21,7 @@ func TestAPIStatus(t *testing.T) {
|
|||
|
||||
hErr := web.HTTPError{}
|
||||
// invalid
|
||||
err := s.Request(http.MethodGet, "/api/v1/auth/status", nil, http.StatusUnauthorized, &hErr)
|
||||
err = s.Request(http.MethodGet, "/api/v1/auth/status", nil, http.StatusUnauthorized, &hErr)
|
||||
assert.NoError(err)
|
||||
assert.Equal(APIErrorNoSession, hErr.Message)
|
||||
|
||||
|
|
|
@ -11,12 +11,13 @@ import (
|
|||
|
||||
func TestMetricsLoaded(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
s := webtest.New(assert)
|
||||
s, err := webtest.New()
|
||||
assert.NoError(err)
|
||||
defer s.Close()
|
||||
assert.NotNil(s)
|
||||
|
||||
// GET
|
||||
err := s.Request(http.MethodGet, "/metrics", nil, http.StatusOK, nil)
|
||||
err = s.Request(http.MethodGet, "/metrics", nil, http.StatusOK, nil)
|
||||
assert.NoError(err)
|
||||
|
||||
UP = func() bool { return false }
|
||||
|
|
|
@ -10,7 +10,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"dev.sum7.eu/genofire/golang-lib/database"
|
||||
"dev.sum7.eu/genofire/golang-lib/mailer"
|
||||
|
@ -28,7 +27,6 @@ type testServer struct {
|
|||
Close func()
|
||||
gin *gin.Engine
|
||||
ws *web.Service
|
||||
assert *assert.Assertions
|
||||
lastCookies []*http.Cookie
|
||||
}
|
||||
|
||||
|
@ -39,7 +37,7 @@ type Login struct {
|
|||
}
|
||||
|
||||
// New starts WebService for testing
|
||||
func New(assert *assert.Assertions) *testServer {
|
||||
func New() (*testServer, error) {
|
||||
// db setup
|
||||
dbConfig := database.Database{
|
||||
Connection: DBConnection,
|
||||
|
@ -49,10 +47,11 @@ func New(assert *assert.Assertions) *testServer {
|
|||
}
|
||||
err := dbConfig.Run()
|
||||
if err != nil && err != database.ErrNothingToMigrate {
|
||||
fmt.Println(err.Error())
|
||||
assert.Nil(err)
|
||||
return nil, err
|
||||
}
|
||||
if dbConfig.DB == nil {
|
||||
return nil, database.ErrNotConnected
|
||||
}
|
||||
assert.NotNil(dbConfig.DB)
|
||||
|
||||
// api setup
|
||||
gin.EnableJsonDecoderDisallowUnknownFields()
|
||||
|
@ -61,7 +60,9 @@ func New(assert *assert.Assertions) *testServer {
|
|||
mock, mail := mailer.NewFakeServer()
|
||||
|
||||
err = mail.Setup()
|
||||
assert.Nil(err)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ws := &web.Service{
|
||||
DB: dbConfig.DB,
|
||||
|
@ -79,8 +80,7 @@ func New(assert *assert.Assertions) *testServer {
|
|||
Close: mock.Close,
|
||||
gin: r,
|
||||
ws: ws,
|
||||
assert: assert,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
// DatabaseForget, to run a test without a database
|
||||
|
@ -116,7 +116,6 @@ func (s *testServer) Request(method, url string, body interface{}, expectCode in
|
|||
s.gin.ServeHTTP(w, req)
|
||||
|
||||
// valid statusCode
|
||||
s.assert.Equal(expectCode, w.Code, "expected http status code")
|
||||
if expectCode != w.Code {
|
||||
return fmt.Errorf("wrong status code, body: %v", w.Body)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue