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