From 273bef1be3e7512c90ff5cc60cd3b633ce1762b7 Mon Sep 17 00:00:00 2001 From: Gusted Date: Tue, 21 Dec 2021 04:12:27 +0100 Subject: [PATCH] Fix continuance tests (#18027) --- integrations/api_repo_lfs_test.go | 8 ++++++++ integrations/mirror_push_test.go | 28 ++++++++++++++++++++++++++++ integrations/repo_tag_test.go | 20 ++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/integrations/api_repo_lfs_test.go b/integrations/api_repo_lfs_test.go index 26f7e50f5bf..947d157d5be 100644 --- a/integrations/api_repo_lfs_test.go +++ b/integrations/api_repo_lfs_test.go @@ -278,6 +278,10 @@ func TestAPILFSBatch(t *testing.T) { meta, err = models.GetLFSMetaObjectByOid(repo.ID, p.Oid) assert.NoError(t, err) assert.NotNil(t, meta) + + // Cleanup + err = contentStore.Delete(p.RelativePath()) + assert.NoError(t, err) }) t.Run("AlreadyExists", func(t *testing.T) { @@ -378,6 +382,10 @@ func TestAPILFSUpload(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, meta) }) + + // Cleanup + err = contentStore.Delete(p.RelativePath()) + assert.NoError(t, err) }) t.Run("MetaAlreadyExists", func(t *testing.T) { diff --git a/integrations/mirror_push_test.go b/integrations/mirror_push_test.go index c8b73880eed..b231b7a9196 100644 --- a/integrations/mirror_push_test.go +++ b/integrations/mirror_push_test.go @@ -9,6 +9,7 @@ import ( "fmt" "net/http" "net/url" + "strconv" "testing" "code.gitea.io/gitea/models" @@ -68,6 +69,12 @@ func testMirrorPush(t *testing.T, u *url.URL) { assert.NoError(t, err) assert.Equal(t, srcCommit.ID, mirrorCommit.ID) + + // Cleanup + doRemovePushMirror(ctx, fmt.Sprintf("%s%s/%s", u.String(), url.PathEscape(ctx.Username), url.PathEscape(mirrorRepo.Name)), user.LowerName, userPassword, int(mirrors[0].ID))(t) + mirrors, err = repo_model.GetPushMirrorsByRepoID(srcRepo.ID) + assert.NoError(t, err) + assert.Len(t, mirrors, 0) } func doCreatePushMirror(ctx APITestContext, address, username, password string) func(t *testing.T) { @@ -89,3 +96,24 @@ func doCreatePushMirror(ctx APITestContext, address, username, password string) assert.Contains(t, flashCookie.Value, "success") } } + +func doRemovePushMirror(ctx APITestContext, address, username, password string, pushMirrorID int) func(t *testing.T) { + return func(t *testing.T) { + csrf := GetCSRF(t, ctx.Session, fmt.Sprintf("/%s/%s/settings", url.PathEscape(ctx.Username), url.PathEscape(ctx.Reponame))) + + req := NewRequestWithValues(t, "POST", fmt.Sprintf("/%s/%s/settings", url.PathEscape(ctx.Username), url.PathEscape(ctx.Reponame)), map[string]string{ + "_csrf": csrf, + "action": "push-mirror-remove", + "push_mirror_id": strconv.Itoa(pushMirrorID), + "push_mirror_address": address, + "push_mirror_username": username, + "push_mirror_password": password, + "push_mirror_interval": "0", + }) + ctx.Session.MakeRequest(t, req, http.StatusFound) + + flashCookie := ctx.Session.GetCookie("macaron_flash") + assert.NotNil(t, flashCookie) + assert.Contains(t, flashCookie.Value, "success") + } +} diff --git a/integrations/repo_tag_test.go b/integrations/repo_tag_test.go index b90dcf0585c..4c06044c6ec 100644 --- a/integrations/repo_tag_test.go +++ b/integrations/repo_tag_test.go @@ -74,4 +74,24 @@ func TestCreateNewTagProtected(t *testing.T) { assert.Contains(t, err.Error(), "Tag v-2 is protected") }) }) + + // Cleanup + releases, err := models.GetReleasesByRepoID(repo.ID, models.FindReleasesOptions{ + IncludeTags: true, + TagNames: []string{"v-1", "v-1.1"}, + }) + assert.NoError(t, err) + + for _, release := range releases { + err = models.DeleteReleaseByID(release.ID) + assert.NoError(t, err) + } + + protectedTags, err := models.GetProtectedTags(repo.ID) + assert.NoError(t, err) + + for _, protectedTag := range protectedTags { + err = models.DeleteProtectedTag(protectedTag) + assert.NoError(t, err) + } }