Files
Reims-Go/internal/plugin/market/test_helpers_test.go
T
千川白浪 9006e6d9a7
CI / verify (push) Canceled after 0s
CI / rolling-release (push) Canceled after 0s
refactor: 抽离 HostAPIService 并将 internal/plugin 拆分为四层无环子包 (#202)
2026-12-05 06:05:41 -07:00

54 lines
1.1 KiB
Go

package market_test
import (
"archive/zip"
"crypto/ed25519"
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"fmt"
"os"
"path/filepath"
"strings"
"testing"
)
func makePluginZip(t *testing.T, files map[string][]byte, priv ed25519.PrivateKey, corruptSum bool) string {
t.Helper()
zipPath := filepath.Join(t.TempDir(), "plugin.zip")
f, err := os.Create(zipPath)
if err != nil {
t.Fatal(err)
}
zw := zip.NewWriter(f)
var sumLines []string
for rel, content := range files {
w, err := zw.Create(rel)
if err != nil {
t.Fatal(err)
}
_, _ = w.Write(content)
h := sha256.Sum256(content)
hexSum := hex.EncodeToString(h[:])
if corruptSum {
hexSum = strings.Repeat("0", 64)
}
sumLines = append(sumLines, fmt.Sprintf("%s %s", hexSum, rel))
}
sumsBytes := []byte(strings.Join(sumLines, "\n") + "\n")
w, _ := zw.Create("SHA256SUMS")
_, _ = w.Write(sumsBytes)
if len(priv) > 0 {
sig := ed25519.Sign(priv, sumsBytes)
sw, _ := zw.Create("SHA256SUMS.sig")
_, _ = sw.Write([]byte(base64.StdEncoding.EncodeToString(sig)))
}
if err := zw.Close(); err != nil {
t.Fatal(err)
}
_ = f.Close()
return zipPath
}