From bb165fadf6cc12822394ee7bc4e0a47c4383ba83 Mon Sep 17 00:00:00 2001 From: oliverpool Date: Wed, 22 May 2024 11:46:51 +0200 Subject: [PATCH] test: check hook_task deletion move test to integration to ensure Sqlite + MySQL testing --- models/fixtures/hook_task.yml | 6 ++++++ .../integration/repo_delete_test.go | 20 ++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) rename services/repository/delete_test.go => tests/integration/repo_delete_test.go (73%) diff --git a/models/fixtures/hook_task.yml b/models/fixtures/hook_task.yml index d573406b36..fc0e03bca1 100644 --- a/models/fixtures/hook_task.yml +++ b/models/fixtures/hook_task.yml @@ -35,3 +35,9 @@ "X-Head": "42" } } + +- + id: 4 + hook_id: 3 + uuid: uuid4 + is_delivered: false diff --git a/services/repository/delete_test.go b/tests/integration/repo_delete_test.go similarity index 73% rename from services/repository/delete_test.go rename to tests/integration/repo_delete_test.go index 869b8af11d..10e99db444 100644 --- a/services/repository/delete_test.go +++ b/tests/integration/repo_delete_test.go @@ -1,7 +1,7 @@ // Copyright 2017 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -package repository_test +package integration import ( "testing" @@ -11,6 +11,7 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" + webhook_model "code.gitea.io/gitea/models/webhook" repo_service "code.gitea.io/gitea/services/repository" "github.com/stretchr/testify/assert" @@ -51,5 +52,22 @@ func TestDeleteOwnerRepositoriesDirectly(t *testing.T) { user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) + deletedHookID := unittest.AssertExistsAndLoadBean(t, &webhook_model.Webhook{RepoID: 1}).ID + unittest.AssertExistsAndLoadBean(t, &webhook_model.HookTask{ + HookID: deletedHookID, + }) + + preservedHookID := unittest.AssertExistsAndLoadBean(t, &webhook_model.Webhook{RepoID: 3}).ID + unittest.AssertExistsAndLoadBean(t, &webhook_model.HookTask{ + HookID: preservedHookID, + }) + assert.NoError(t, repo_service.DeleteOwnerRepositoriesDirectly(db.DefaultContext, user)) + + unittest.AssertNotExistsBean(t, &webhook_model.HookTask{ + HookID: deletedHookID, + }) + unittest.AssertExistsAndLoadBean(t, &webhook_model.HookTask{ + HookID: preservedHookID, + }) }