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.

repo_pushmirror_test.go 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "testing"
  7. "time"
  8. "code.gitea.io/gitea/models/db"
  9. "code.gitea.io/gitea/modules/timeutil"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. func TestPushMirrorsIterate(t *testing.T) {
  13. assert.NoError(t, db.PrepareTestDatabase())
  14. now := timeutil.TimeStampNow()
  15. InsertPushMirror(&PushMirror{
  16. RemoteName: "test-1",
  17. LastUpdateUnix: now,
  18. Interval: 1,
  19. })
  20. long, _ := time.ParseDuration("24h")
  21. InsertPushMirror(&PushMirror{
  22. RemoteName: "test-2",
  23. LastUpdateUnix: now,
  24. Interval: long,
  25. })
  26. InsertPushMirror(&PushMirror{
  27. RemoteName: "test-3",
  28. LastUpdateUnix: now,
  29. Interval: 0,
  30. })
  31. time.Sleep(1 * time.Millisecond)
  32. PushMirrorsIterate(func(idx int, bean interface{}) error {
  33. m, ok := bean.(*PushMirror)
  34. assert.True(t, ok)
  35. assert.Equal(t, "test-1", m.RemoteName)
  36. assert.Equal(t, m.RemoteName, m.GetRemoteName())
  37. return nil
  38. })
  39. }