VILLASweb-backend-go/routes/user/user_test.go
smavros 6aee1a7aca Improves NewAuthenticateForTest():
- As NewTestEndpoint() the credentials are passed as interface{} and
    marsaling is happening inside the function.
    - Add check for ignored error from http.NewRequest()
2019-08-11 20:03:23 +02:00

36 lines
828 B
Go

package user
import (
"testing"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
)
func TestUserEndpoints(t *testing.T) {
myUsers := []common.User{common.User0}
msgUsers := common.ResponseMsgUsers{Users: myUsers}
db := common.DummyInitDB()
defer db.Close()
common.DummyOnlyAdminDB(db)
router := gin.Default()
api := router.Group("/api")
VisitorAuthenticate(api.Group("/authenticate"))
api.Use(Authentication(true))
RegisterUserEndpoints(api.Group("/users"))
token, err := common.NewAuthenticateForTest(router,
"/api/authenticate", "POST", common.CredAdmin, 200)
assert.NoError(t, err)
// test GET user/
err = common.NewTestEndpoint(router, token, "/api/users", "GET",
nil, 200, msgUsers)
assert.NoError(t, err)
}