1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-09-15 18:57:01 +00:00

feat: Add new Action Cache (#1913)

* feat: Add new Action Cache

* fix some linter errors / warnings

* fix lint

* fix empty fpath parameter returns empty archive

* rename fpath to includePrefix
This commit is contained in:
ChristopherHX 2023-08-08 18:07:23 +02:00 committed by GitHub
parent fd5b21b7be
commit 39fe8cd25e
2 changed files with 214 additions and 0 deletions

View file

@ -0,0 +1,37 @@
package runner
import (
"archive/tar"
"bytes"
"context"
"io"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
//nolint:gosec
func TestActionCache(t *testing.T) {
a := assert.New(t)
cache := &GoGitActionCache{
Path: os.TempDir(),
}
ctx := context.Background()
sha, err := cache.Fetch(ctx, "christopherhx/script", "https://github.com/christopherhx/script", "main", "")
a.NoError(err)
a.NotEmpty(sha)
atar, err := cache.GetTarArchive(ctx, "christopherhx/script", sha, "node_modules")
a.NoError(err)
a.NotEmpty(atar)
mytar := tar.NewReader(atar)
th, err := mytar.Next()
a.NoError(err)
a.NotEqual(0, th.Size)
buf := &bytes.Buffer{}
// G110: Potential DoS vulnerability via decompression bomb (gosec)
_, err = io.Copy(buf, mytar)
a.NoError(err)
str := buf.String()
a.NotEmpty(str)
}