From c7cf1307ca227ff9f4935391582c058823419d7b Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Mon, 5 Jun 2023 11:43:31 +0200 Subject: [PATCH] [TESTS] createUser via the user model helper for integration tests (cherry picked from commit c1d14c5fffeb823385b2984cfcdb3e195bfb151d) (cherry picked from commit e0e8aabc985af153cf1fcb2064c17f68ec37f3a2) (cherry picked from commit 392a415070af7f4e872c7bb013f259e2dcc8b7b4) --- tests/integration/integration_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index ff209f8934..f3d542511a 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -24,6 +24,7 @@ import ( "code.gitea.io/gitea/models/auth" "code.gitea.io/gitea/models/unittest" + user_model "code.gitea.io/gitea/models/user" gitea_context "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/json" @@ -33,6 +34,7 @@ import ( "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/routers" + user_service "code.gitea.io/gitea/services/user" "code.gitea.io/gitea/tests" "github.com/PuerkitoBio/goquery" @@ -239,6 +241,21 @@ func getUserToken(t testing.TB, userName string, scope ...auth.AccessTokenScope) return getTokenForLoggedInUser(t, loginUser(t, userName), scope...) } +func createUser(t testing.TB, userName, email, password string) func() { + u := &user_model.User{ + Name: userName, + Email: email, + Passwd: password, + MustChangePassword: false, + LoginType: auth.Plain, + } + + assert.NoError(t, user_model.CreateUser(u, &user_model.CreateUserOverwriteOptions{})) + return func() { + assert.NoError(t, user_service.DeleteUser(context.Background(), u, true)) + } +} + func loginUser(t testing.TB, userName string) *TestSession { t.Helper()