2021-06-14 17:20:43 +00:00
|
|
|
// Copyright 2021 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.
|
|
|
|
|
2021-12-10 01:27:50 +00:00
|
|
|
package repo
|
2021-06-14 17:20:43 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2021-11-12 14:36:47 +00:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2021-06-14 17:20:43 +00:00
|
|
|
"code.gitea.io/gitea/modules/timeutil"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPushMirrorsIterate(t *testing.T) {
|
2021-11-12 14:36:47 +00:00
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2021-06-14 17:20:43 +00:00
|
|
|
|
|
|
|
now := timeutil.TimeStampNow()
|
|
|
|
|
|
|
|
InsertPushMirror(&PushMirror{
|
|
|
|
RemoteName: "test-1",
|
|
|
|
LastUpdateUnix: now,
|
|
|
|
Interval: 1,
|
|
|
|
})
|
|
|
|
|
|
|
|
long, _ := time.ParseDuration("24h")
|
|
|
|
InsertPushMirror(&PushMirror{
|
|
|
|
RemoteName: "test-2",
|
|
|
|
LastUpdateUnix: now,
|
|
|
|
Interval: long,
|
|
|
|
})
|
|
|
|
|
|
|
|
InsertPushMirror(&PushMirror{
|
|
|
|
RemoteName: "test-3",
|
|
|
|
LastUpdateUnix: now,
|
|
|
|
Interval: 0,
|
|
|
|
})
|
|
|
|
|
|
|
|
time.Sleep(1 * time.Millisecond)
|
|
|
|
|
2022-02-28 19:41:06 +00:00
|
|
|
PushMirrorsIterate(1, func(idx int, bean interface{}) error {
|
2021-06-14 17:20:43 +00:00
|
|
|
m, ok := bean.(*PushMirror)
|
|
|
|
assert.True(t, ok)
|
|
|
|
assert.Equal(t, "test-1", m.RemoteName)
|
|
|
|
assert.Equal(t, m.RemoteName, m.GetRemoteName())
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|