From 6ff23839528db66ae91e88d6b687b63c769f8f43 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Tue, 27 Jun 2023 11:48:13 +0200 Subject: [PATCH] [TESTS] createUser via the user model helper for integration tests (squash) --- tests/integration/integration_test.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index f3d542511a..025325e31d 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -23,6 +23,7 @@ import ( "time" "code.gitea.io/gitea/models/auth" + "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" gitea_context "code.gitea.io/gitea/modules/context" @@ -241,18 +242,19 @@ 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, +func createUser(ctx context.Context, t testing.TB, user *user_model.User) func() { + user.MustChangePassword = false + user.LowerName = strings.ToLower(user.Name) + + assert.NoError(t, db.Insert(ctx, user)) + + if len(user.Email) > 0 { + changePrimaryEmail := true + assert.NoError(t, user_model.UpdateUser(ctx, user, changePrimaryEmail)) } - assert.NoError(t, user_model.CreateUser(u, &user_model.CreateUserOverwriteOptions{})) return func() { - assert.NoError(t, user_service.DeleteUser(context.Background(), u, true)) + assert.NoError(t, user_service.DeleteUser(ctx, user, true)) } }