mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-09-30 19:22:09 +00:00
chore: cache: move repo != cache.Repo in readCache
- it only is used after calling readCache - add unit test it reduces the number of testcase to be considered in handler
This commit is contained in:
parent
6c4e705f97
commit
c28a98082b
3 changed files with 63 additions and 20 deletions
54
act/artifactcache/caches_test.go
Normal file
54
act/artifactcache/caches_test.go
Normal file
|
@ -0,0 +1,54 @@
|
|||
package artifactcache
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/timshannon/bolthold"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestCacheReadWrite(t *testing.T) {
|
||||
caches, err := newCaches(t.TempDir(), "secret", logrus.New())
|
||||
require.NoError(t, err)
|
||||
t.Run("NotFound", func(t *testing.T) {
|
||||
found, err := caches.readCache(456, "repo")
|
||||
assert.Nil(t, found)
|
||||
assert.ErrorIs(t, err, bolthold.ErrNotFound)
|
||||
})
|
||||
|
||||
repo := "repository"
|
||||
cache := &Cache{
|
||||
Repo: repo,
|
||||
Key: "key",
|
||||
Version: "version",
|
||||
Size: 444,
|
||||
}
|
||||
now := time.Now().Unix()
|
||||
cache.CreatedAt = now
|
||||
cache.UsedAt = now
|
||||
cache.Repo = repo
|
||||
|
||||
t.Run("Insert", func(t *testing.T) {
|
||||
db, err := caches.openDB()
|
||||
require.NoError(t, err)
|
||||
defer db.Close()
|
||||
assert.NoError(t, insertCache(db, cache))
|
||||
})
|
||||
|
||||
t.Run("Found", func(t *testing.T) {
|
||||
found, err := caches.readCache(cache.ID, cache.Repo)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, cache.ID, found.ID)
|
||||
})
|
||||
|
||||
t.Run("InvalidRepo", func(t *testing.T) {
|
||||
invalidRepo := "INVALID REPO"
|
||||
found, err := caches.readCache(cache.ID, invalidRepo)
|
||||
assert.Nil(t, found)
|
||||
assert.ErrorContains(t, err, invalidRepo)
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue