mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-12 13:22:55 +02:00
tests
This commit is contained in:
parent
4415797c89
commit
cfc8a32d9f
@ -1,47 +0,0 @@
|
|||||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
package convert
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
|
||||||
access_model "code.gitea.io/gitea/models/perm/access"
|
|
||||||
perm_model "code.gitea.io/gitea/models/perm"
|
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
|
||||||
"code.gitea.io/gitea/models/unittest"
|
|
||||||
"code.gitea.io/gitea/modules/timeutil"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestToRepoIncludesLastPullSyncSuccess(t *testing.T) {
|
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
||||||
|
|
||||||
ctx := t.Context()
|
|
||||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
|
||||||
repo.IsMirror = true
|
|
||||||
require.NoError(t, repo_model.DeleteMirrorByRepoID(ctx, repo.ID))
|
|
||||||
repo.LastPullSyncSuccessUnix = timeutil.TimeStamp(1714000000)
|
|
||||||
require.NoError(t, repo_model.UpdateRepositoryColsNoAutoTime(ctx, repo, "is_mirror", "last_pull_sync_success_unix"))
|
|
||||||
|
|
||||||
mirror := &repo_model.Mirror{
|
|
||||||
RepoID: repo.ID,
|
|
||||||
Interval: time.Hour,
|
|
||||||
}
|
|
||||||
require.NoError(t, db.Insert(ctx, mirror))
|
|
||||||
|
|
||||||
mirror.UpdatedUnix = timeutil.TimeStamp(1715000000)
|
|
||||||
mirror.NextUpdateUnix = timeutil.TimeStamp(1716000000)
|
|
||||||
require.NoError(t, repo_model.UpdateMirror(ctx, mirror))
|
|
||||||
|
|
||||||
apiRepo := ToRepo(ctx, repo, access_model.Permission{AccessMode: perm_model.AccessModeRead})
|
|
||||||
require.NotNil(t, apiRepo)
|
|
||||||
|
|
||||||
assert.Equal(t, mirror.UpdatedUnix.AsTime(), apiRepo.MirrorUpdated)
|
|
||||||
assert.Equal(t, repo.LastPullSyncSuccessUnix.AsTime(), apiRepo.LastPullSyncSuccess)
|
|
||||||
assert.NotEqual(t, apiRepo.MirrorUpdated, apiRepo.LastPullSyncSuccess)
|
|
||||||
}
|
|
||||||
@ -93,6 +93,10 @@ func TestMirrorPull(t *testing.T) {
|
|||||||
ok := mirror_service.SyncPullMirror(ctx, mirrorRepo.ID)
|
ok := mirror_service.SyncPullMirror(ctx, mirrorRepo.ID)
|
||||||
assert.True(t, ok)
|
assert.True(t, ok)
|
||||||
|
|
||||||
|
mirror := unittest.AssertExistsAndLoadBean(t, &repo_model.Mirror{RepoID: mirrorRepo.ID})
|
||||||
|
mirrorRepo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: mirrorRepo.ID})
|
||||||
|
assert.Equal(t, mirror.UpdatedUnix, mirrorRepo.LastPullSyncSuccessUnix)
|
||||||
|
|
||||||
// actually there is a tag in the source repo, so after "sync", that tag will also come into the mirror
|
// actually there is a tag in the source repo, so after "sync", that tag will also come into the mirror
|
||||||
initCount++
|
initCount++
|
||||||
|
|
||||||
@ -110,4 +114,15 @@ func TestMirrorPull(t *testing.T) {
|
|||||||
count, err = db.Count[repo_model.Release](t.Context(), findOptions)
|
count, err = db.Count[repo_model.Release](t.Context(), findOptions)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, initCount, count)
|
assert.Equal(t, initCount, count)
|
||||||
|
|
||||||
|
mirrorRepo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: mirrorRepo.ID})
|
||||||
|
lastPullSyncSuccess := mirrorRepo.LastPullSyncSuccessUnix
|
||||||
|
mirror = unittest.AssertExistsAndLoadBean(t, &repo_model.Mirror{RepoID: mirrorRepo.ID})
|
||||||
|
assert.NoError(t, mirror_service.UpdateAddress(ctx, mirror, repoPath+"-missing"))
|
||||||
|
|
||||||
|
ok = mirror_service.SyncPullMirror(ctx, mirrorRepo.ID)
|
||||||
|
assert.False(t, ok)
|
||||||
|
|
||||||
|
mirrorRepo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: mirrorRepo.ID})
|
||||||
|
assert.Equal(t, lastPullSyncSuccess, mirrorRepo.LastPullSyncSuccessUnix)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user