Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

pushmirror_test.go 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package repo_test
  4. import (
  5. "testing"
  6. "time"
  7. "code.gitea.io/gitea/models/db"
  8. repo_model "code.gitea.io/gitea/models/repo"
  9. "code.gitea.io/gitea/models/unittest"
  10. "code.gitea.io/gitea/modules/timeutil"
  11. "github.com/stretchr/testify/assert"
  12. )
  13. func TestPushMirrorsIterate(t *testing.T) {
  14. assert.NoError(t, unittest.PrepareTestDatabase())
  15. now := timeutil.TimeStampNow()
  16. repo_model.InsertPushMirror(db.DefaultContext, &repo_model.PushMirror{
  17. RemoteName: "test-1",
  18. LastUpdateUnix: now,
  19. Interval: 1,
  20. })
  21. long, _ := time.ParseDuration("24h")
  22. repo_model.InsertPushMirror(db.DefaultContext, &repo_model.PushMirror{
  23. RemoteName: "test-2",
  24. LastUpdateUnix: now,
  25. Interval: long,
  26. })
  27. repo_model.InsertPushMirror(db.DefaultContext, &repo_model.PushMirror{
  28. RemoteName: "test-3",
  29. LastUpdateUnix: now,
  30. Interval: 0,
  31. })
  32. time.Sleep(1 * time.Millisecond)
  33. repo_model.PushMirrorsIterate(db.DefaultContext, 1, func(idx int, bean interface{}) error {
  34. m, ok := bean.(*repo_model.PushMirror)
  35. assert.True(t, ok)
  36. assert.Equal(t, "test-1", m.RemoteName)
  37. assert.Equal(t, m.RemoteName, m.GetRemoteName())
  38. return nil
  39. })
  40. }