2021-06-14 22:50:43 +05:30
|
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2021-06-14 22:50:43 +05:30
|
|
|
|
2022-06-06 13:31:49 +05:30
|
|
|
package repo_test
|
2021-06-14 22:50:43 +05:30
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2022-07-30 22:15:59 +05:30
|
|
|
"code.gitea.io/gitea/models/db"
|
2022-06-06 13:31:49 +05:30
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-12 20:06:47 +05:30
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2021-06-14 22:50:43 +05:30
|
|
|
"code.gitea.io/gitea/modules/timeutil"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPushMirrorsIterate(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2021-06-14 22:50:43 +05:30
|
|
|
|
|
|
|
now := timeutil.TimeStampNow()
|
|
|
|
|
2023-12-26 01:55:29 +05:30
|
|
|
db.Insert(db.DefaultContext, &repo_model.PushMirror{
|
2021-06-14 22:50:43 +05:30
|
|
|
RemoteName: "test-1",
|
|
|
|
LastUpdateUnix: now,
|
|
|
|
Interval: 1,
|
|
|
|
})
|
|
|
|
|
|
|
|
long, _ := time.ParseDuration("24h")
|
2023-12-26 01:55:29 +05:30
|
|
|
db.Insert(db.DefaultContext, &repo_model.PushMirror{
|
2021-06-14 22:50:43 +05:30
|
|
|
RemoteName: "test-2",
|
|
|
|
LastUpdateUnix: now,
|
|
|
|
Interval: long,
|
|
|
|
})
|
|
|
|
|
2023-12-26 01:55:29 +05:30
|
|
|
db.Insert(db.DefaultContext, &repo_model.PushMirror{
|
2021-06-14 22:50:43 +05:30
|
|
|
RemoteName: "test-3",
|
|
|
|
LastUpdateUnix: now,
|
|
|
|
Interval: 0,
|
|
|
|
})
|
|
|
|
|
|
|
|
time.Sleep(1 * time.Millisecond)
|
|
|
|
|
2023-07-05 00:06:08 +05:30
|
|
|
repo_model.PushMirrorsIterate(db.DefaultContext, 1, func(idx int, bean any) error {
|
2022-06-06 13:31:49 +05:30
|
|
|
m, ok := bean.(*repo_model.PushMirror)
|
2021-06-14 22:50:43 +05:30
|
|
|
assert.True(t, ok)
|
|
|
|
assert.Equal(t, "test-1", m.RemoteName)
|
|
|
|
assert.Equal(t, m.RemoteName, m.GetRemoteName())
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|