internal/pkg: implement tar artifact
All checks were successful
Test / Create distribution (push) Successful in 43s
Test / Sandbox (push) Successful in 2m34s
Test / Hakurei (push) Successful in 3m36s
Test / ShareFS (push) Successful in 3m40s
Test / Hpkg (push) Successful in 4m13s
Test / Sandbox (race detector) (push) Successful in 4m57s
Test / Hakurei (race detector) (push) Successful in 5m53s
Test / Flake checks (push) Successful in 1m44s

This is useful for unpacking tarballs downloaded from the internet.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-01-04 01:08:59 +09:00
parent fa93476896
commit d76b9d04b8
4 changed files with 435 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
package pkg_test
import (
"archive/tar"
"bytes"
"crypto/sha512"
"encoding/binary"
@@ -40,7 +41,7 @@ func TestIdent(t *testing.T) {
want pkg.ID
}{
{"tar", pkg.KindTar, []byte{
1, 0, 0, 0, 0, 0, 0, 0,
pkg.TarGzip, 0, 0, 0, 0, 0, 0, 0,
}, []pkg.Artifact{
stubArtifact{pkg.KindHTTP, pkg.ID{}},
}, pkg.MustDecode("HnySzeLQvSBZuTUcvfmLEX_OmH4yJWWH788NxuLuv7kVn8_uPM6Ks4rqFWM2NZJY")},
@@ -74,6 +75,7 @@ func checkWithCache(t *testing.T, testCases []cacheTestCase) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Helper()
t.Parallel()
base := check.MustAbs(t.TempDir())
@@ -307,7 +309,7 @@ func TestCache(t *testing.T) {
{"directory", nil, func(t *testing.T, base *check.Absolute, c *pkg.Cache) {
id := pkg.KindTar.Ident(
binary.LittleEndian.AppendUint64(nil, 1),
binary.LittleEndian.AppendUint64(nil, pkg.TarGzip),
stubArtifact{pkg.KindHTTP, testdataChecksum},
)
makeSample := func(work *check.Absolute) error {
@@ -371,7 +373,7 @@ func TestCache(t *testing.T) {
// check exist
id0 := pkg.KindTar.Ident(
binary.LittleEndian.AppendUint64(nil, 1),
binary.LittleEndian.AppendUint64(nil, pkg.TarGzip),
stubArtifact{pkg.KindHTTP, pkg.ID{}},
)
wantPathname0 := base.Append(
@@ -478,6 +480,10 @@ func TestErrors(t *testing.T) {
{"ResponseStatusError", pkg.ResponseStatusError(
http.StatusNotAcceptable,
), "the requested URL returned non-OK status: Not Acceptable"},
{"DisallowedTypeflagError", pkg.DisallowedTypeflagError(
tar.TypeChar,
), "disallowed typeflag '3'"},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {