Add auth test util
This commit is contained in:
parent
34f8cc6b77
commit
42c5cc15d8
|
|
@ -0,0 +1,11 @@
|
|||
package test
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gotify/server/model"
|
||||
)
|
||||
|
||||
// WithUser fake an authentication for testing.
|
||||
func WithUser(ctx *gin.Context, userID uint) {
|
||||
ctx.Set("user", &model.User{ID: userID})
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package test_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gotify/server/auth"
|
||||
"github.com/gotify/server/mode"
|
||||
"github.com/gotify/server/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestFakeAuth(t *testing.T) {
|
||||
mode.Set(mode.TestDev)
|
||||
|
||||
ctx, _ := gin.CreateTestContext(nil)
|
||||
test.WithUser(ctx, 5)
|
||||
assert.Equal(t, uint(5), auth.GetUserID(ctx))
|
||||
}
|
||||
Loading…
Reference in New Issue