Streamd v0.2.0: rename, modules panel, stable/beta channels
All checks were successful
release / build-and-upload (push) Successful in 7m5s
All checks were successful
release / build-and-upload (push) Successful in 7m5s
- Rename product/host binary to streamd (drm compat copy still shipped) - Go module path streamd; STREAMD_* env aliases; agent UA streamd-agent - Panel Modules store + agent pull sync (modstore / modsync) - Rolling stable + beta download tags; README/docs channel curl blocks - Release notes in docs/releases/v0.2.0.md attached by Forgejo Actions
This commit is contained in:
parent
066e018749
commit
da8e1123ec
140 changed files with 2949 additions and 851 deletions
149
apps/streamd/internal/modstore/modstore_test.go
Normal file
149
apps/streamd/internal/modstore/modstore_test.go
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
package modstore
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func makeZip(t *testing.T, files map[string][]byte) []byte {
|
||||
t.Helper()
|
||||
var buf bytes.Buffer
|
||||
zw := zip.NewWriter(&buf)
|
||||
for name, body := range files {
|
||||
w, err := zw.Create(name)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := w.Write(body); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if err := zw.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
func TestInstallZipFlatAndYAMLOnly(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
s := New(root)
|
||||
|
||||
arch := runtime.GOOS + "-" + runtime.GOARCH
|
||||
binName := "demo"
|
||||
if runtime.GOOS == "windows" {
|
||||
binName += ".exe"
|
||||
}
|
||||
zipBytes := makeZip(t, map[string][]byte{
|
||||
"module.yaml": []byte("package: com.example\nchannels: {}\n"),
|
||||
".bin/" + arch + "/" + binName: []byte("fake-binary"),
|
||||
".bin/linux-amd64/demo": []byte("linux-bin"),
|
||||
})
|
||||
|
||||
info, err := s.InstallZip(zipBytes, "demo")
|
||||
if err != nil {
|
||||
t.Fatalf("InstallZip: %v", err)
|
||||
}
|
||||
if info.Name != "demo" || !info.HasYAML || !info.HasPackage {
|
||||
t.Fatalf("info = %+v", info)
|
||||
}
|
||||
if info.PackageSHA256 == "" || info.YAMLSHA256 == "" {
|
||||
t.Fatalf("missing hashes: %+v", info)
|
||||
}
|
||||
pkgHash := info.PackageSHA256
|
||||
yamlHash := info.YAMLSHA256
|
||||
|
||||
// Host binary should be promoted.
|
||||
promoted := filepath.Join(root, "demo", ".bin", binName)
|
||||
if !fileExists(promoted) {
|
||||
t.Fatalf("expected promoted binary at %s", promoted)
|
||||
}
|
||||
|
||||
// YAML-only update must not change package hash.
|
||||
info2, err := s.WriteYAML("demo", []byte("package: com.example\nchannels:\n one: {label: One}\n"))
|
||||
if err != nil {
|
||||
t.Fatalf("WriteYAML: %v", err)
|
||||
}
|
||||
if info2.PackageSHA256 != pkgHash {
|
||||
t.Fatalf("package hash changed on yaml edit: %s -> %s", pkgHash, info2.PackageSHA256)
|
||||
}
|
||||
if info2.YAMLSHA256 == yamlHash {
|
||||
t.Fatal("yaml hash should change after edit")
|
||||
}
|
||||
|
||||
raw, err := s.ReadYAML("demo")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(string(raw), "one:") {
|
||||
t.Fatalf("yaml not updated: %s", raw)
|
||||
}
|
||||
|
||||
f, size, err := s.OpenPackage("demo")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer f.Close()
|
||||
if size != int64(len(zipBytes)) {
|
||||
t.Fatalf("package size %d want %d", size, len(zipBytes))
|
||||
}
|
||||
}
|
||||
|
||||
func TestInstallZipTopLevelFolder(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
s := New(root)
|
||||
zipBytes := makeZip(t, map[string][]byte{
|
||||
"bbc/module.yaml": []byte("package: bbc.iplayer.android\n"),
|
||||
"bbc/.bin/linux-amd64/bbc": []byte("bin"),
|
||||
"bbc/.bin/windows-amd64/bbc.exe": []byte("winbin"),
|
||||
})
|
||||
info, err := s.InstallZip(zipBytes, "")
|
||||
if err != nil {
|
||||
t.Fatalf("InstallZip: %v", err)
|
||||
}
|
||||
if info.Name != "bbc" {
|
||||
t.Fatalf("name=%q", info.Name)
|
||||
}
|
||||
list, err := s.List()
|
||||
if err != nil || len(list) != 1 || list[0].Name != "bbc" {
|
||||
t.Fatalf("list=%v err=%v", list, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestZipSlipRejected(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
s := New(root)
|
||||
var buf bytes.Buffer
|
||||
zw := zip.NewWriter(&buf)
|
||||
w, err := zw.Create("../evil.yaml")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, _ = w.Write([]byte("x"))
|
||||
_ = zw.Close()
|
||||
_, err = s.InstallZip(buf.Bytes(), "demo")
|
||||
if err == nil {
|
||||
t.Fatal("expected zip-slip error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDelete(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
s := New(root)
|
||||
zipBytes := makeZip(t, map[string][]byte{
|
||||
"module.yaml": []byte("package: x\n"),
|
||||
})
|
||||
if _, err := s.InstallZip(zipBytes, "xmod"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.Delete("xmod"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(root, "xmod")); !os.IsNotExist(err) {
|
||||
t.Fatalf("dir still present: %v", err)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue