You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
2.6 KiB
93 lines
2.6 KiB
5 years ago
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
4 years ago
|
package integrations
|
||
5 years ago
|
|
||
|
import (
|
||
4 years ago
|
"context"
|
||
5 years ago
|
"testing"
|
||
|
|
||
|
"code.gitea.io/gitea/models"
|
||
|
"code.gitea.io/gitea/modules/git"
|
||
4 years ago
|
migration "code.gitea.io/gitea/modules/migrations/base"
|
||
5 years ago
|
"code.gitea.io/gitea/modules/repository"
|
||
4 years ago
|
mirror_service "code.gitea.io/gitea/services/mirror"
|
||
5 years ago
|
release_service "code.gitea.io/gitea/services/release"
|
||
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
4 years ago
|
func TestMirrorPull(t *testing.T) {
|
||
|
defer prepareTestEnv(t)()
|
||
5 years ago
|
|
||
|
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
|
||
|
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
|
||
|
repoPath := models.RepoPath(user.Name, repo.Name)
|
||
|
|
||
4 years ago
|
opts := migration.MigrateOptions{
|
||
5 years ago
|
RepoName: "test_mirror",
|
||
|
Description: "Test mirror",
|
||
|
Private: false,
|
||
|
Mirror: true,
|
||
|
CloneAddr: repoPath,
|
||
|
Wiki: true,
|
||
|
Releases: false,
|
||
5 years ago
|
}
|
||
5 years ago
|
|
||
5 years ago
|
mirrorRepo, err := repository.CreateRepository(user, user, models.CreateRepoOptions{
|
||
5 years ago
|
Name: opts.RepoName,
|
||
|
Description: opts.Description,
|
||
|
IsPrivate: opts.Private,
|
||
|
IsMirror: opts.Mirror,
|
||
|
Status: models.RepositoryBeingMigrated,
|
||
|
})
|
||
|
assert.NoError(t, err)
|
||
|
|
||
4 years ago
|
ctx := context.Background()
|
||
|
|
||
|
mirror, err := repository.MigrateRepositoryGitData(ctx, user, mirrorRepo, opts)
|
||
5 years ago
|
assert.NoError(t, err)
|
||
|
|
||
|
gitRepo, err := git.OpenRepository(repoPath)
|
||
|
assert.NoError(t, err)
|
||
5 years ago
|
defer gitRepo.Close()
|
||
5 years ago
|
|
||
|
findOptions := models.FindReleasesOptions{IncludeDrafts: true, IncludeTags: true}
|
||
|
initCount, err := models.GetReleaseCountByRepoID(mirror.ID, findOptions)
|
||
|
assert.NoError(t, err)
|
||
|
|
||
|
assert.NoError(t, release_service.CreateRelease(gitRepo, &models.Release{
|
||
|
RepoID: repo.ID,
|
||
|
PublisherID: user.ID,
|
||
|
TagName: "v0.2",
|
||
|
Target: "master",
|
||
|
Title: "v0.2 is released",
|
||
|
Note: "v0.2 is released",
|
||
|
IsDraft: false,
|
||
|
IsPrerelease: false,
|
||
|
IsTag: true,
|
||
4 years ago
|
}, nil, ""))
|
||
5 years ago
|
|
||
|
err = mirror.GetMirror()
|
||
|
assert.NoError(t, err)
|
||
|
|
||
4 years ago
|
ok := mirror_service.SyncPullMirror(ctx, mirror.ID)
|
||
5 years ago
|
assert.True(t, ok)
|
||
|
|
||
|
count, err := models.GetReleaseCountByRepoID(mirror.ID, findOptions)
|
||
5 years ago
|
assert.NoError(t, err)
|
||
5 years ago
|
assert.EqualValues(t, initCount+1, count)
|
||
|
|
||
|
release, err := models.GetRelease(repo.ID, "v0.2")
|
||
|
assert.NoError(t, err)
|
||
|
assert.NoError(t, release_service.DeleteReleaseByID(release.ID, user, true))
|
||
|
|
||
4 years ago
|
ok = mirror_service.SyncPullMirror(ctx, mirror.ID)
|
||
5 years ago
|
assert.True(t, ok)
|
||
|
|
||
|
count, err = models.GetReleaseCountByRepoID(mirror.ID, findOptions)
|
||
5 years ago
|
assert.NoError(t, err)
|
||
5 years ago
|
assert.EqualValues(t, initCount, count)
|
||
|
}
|