Files
MeBox/internal/service/ffmpeg_tools_test.go
T
truewhile b0fe40142a Rebrand MMTL to MeBox (name, logo, Docker image) (#17)
* Rebrand MMTL to MeBox across codebase and assets

Rename the project display name, Go module path, environment variable
prefix (MEBOX_*), Docker image references, and UI branding from MMTL/mmtl
to MeBox/mebox. Replace logo assets with the new MeBox icon and keep
legacy SQLite migration support for existing mmtl.db deployments.

Co-authored-by: truewhile <truewhile@users.noreply.github.com>

* Fix logo icons: use cube-only crop without truncated text

Previous icon generation cropped too much of the source image, including
partial MeBox wordmark text that was cut off in square icon containers.
Regenerate logo-64/192/512, favicon, and SVG from cube-only region.

Co-authored-by: truewhile <truewhile@users.noreply.github.com>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: truewhile <truewhile@users.noreply.github.com>
2026-09-02 16:26:28 +08:00

81 lines
2.3 KiB
Go

package service
import (
"context"
"runtime"
"strings"
"testing"
"go.uber.org/zap"
"github.com/truewhile/MeBox/internal/config"
)
func TestFFmpegTargetForPlatform(t *testing.T) {
target, err := ffmpegTargetForPlatform()
switch runtime.GOOS {
case "windows", "linux", "darwin":
if err != nil {
t.Fatalf("supported platform %s/%s should resolve a target: %v", runtime.GOOS, runtime.GOARCH, err)
}
if target == nil || target.Label == "" || len(target.Archives) == 0 {
t.Fatalf("target incomplete: %#v", target)
}
if target.Kind != "zip" && target.Kind != "tar.xz" {
t.Fatalf("unexpected archive kind: %s", target.Kind)
}
for _, u := range target.Archives {
if !strings.HasPrefix(u, "https://") {
t.Fatalf("archive url not https: %s", u)
}
}
default:
if err == nil {
t.Fatalf("unsupported platform %s/%s should fail", runtime.GOOS, runtime.GOARCH)
}
}
}
func TestSafeZipTargetRejectsTraversal(t *testing.T) {
root := t.TempDir()
for _, name := range []string{"../evil", "..\\evil", "/etc/passwd", "a/../../evil"} {
if _, err := safeZipTarget(root, name); err == nil {
t.Fatalf("expected traversal rejection for %q", name)
}
}
if _, err := safeZipTarget(root, "bin/ffmpeg.exe"); err != nil {
t.Fatalf("valid relative path should pass: %v", err)
}
}
func TestFFmpegToolsStatusNoPanic(t *testing.T) {
svc := NewFFmpegToolsService(&config.Config{}, zap.NewNop(), nil)
st := svc.Status(context.Background())
for _, key := range []string{"installing", "message", "error", "install_dir", "target", "ffmpeg", "ffprobe"} {
if _, ok := st[key]; !ok {
t.Fatalf("status missing key %q: %#v", key, st)
}
}
ffmpeg, ok := st["ffmpeg"].(ffToolInfo)
if !ok {
t.Fatalf("ffmpeg field not ffToolInfo: %T", st["ffmpeg"])
}
if ffmpeg.Installed {
t.Fatalf("empty config should not report installed ffmpeg: %#v", st)
}
}
func TestStartInstallRejectsConcurrent(t *testing.T) {
svc := NewFFmpegToolsService(&config.Config{App: config.AppConfig{DataDir: t.TempDir()}}, zap.NewNop(), nil)
// 不真实运行:直接占用 running 标记模拟进行中的安装。
svc.mu.Lock()
svc.running = true
svc.mu.Unlock()
if err := svc.StartInstall(context.Background()); err == nil {
t.Fatalf("second install while running should be rejected")
}
svc.mu.Lock()
svc.running = false
svc.mu.Unlock()
}