feat: ConvertGUI v2.0 (Wails + preview/trim + NSIS + Gitea CI)
Build Windows Installer / build (push) Successful in 4m11s
Build Windows Installer / build (push) Successful in 4m11s
This commit is contained in:
40 files changed
+6084
-266
No files matched your search
@@ -0,0 +1,87 @@
|
||||
package preview
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"convert/internal/media"
|
||||
)
|
||||
|
||||
func TestPreviewServer_RangeThumbAndProxy(t *testing.T) {
|
||||
bins := media.FindBinaries("", "")
|
||||
if bins.FFmpeg == "" || bins.FFprobe == "" {
|
||||
t.Skip("ffmpeg/ffprobe not installed")
|
||||
}
|
||||
|
||||
tmpDir := t.TempDir()
|
||||
src := filepath.Join(tmpDir, "clip.mkv")
|
||||
gen := exec.Command(bins.FFmpeg,
|
||||
"-hide_banner", "-loglevel", "error",
|
||||
"-f", "lavfi", "-i", "testsrc=duration=2:size=320x180:rate=30",
|
||||
"-f", "lavfi", "-i", "sine=frequency=440:duration=2",
|
||||
"-c:v", "libx264", "-preset", "ultrafast", "-c:a", "aac", "-y", src,
|
||||
)
|
||||
if out, err := gen.CombinedOutput(); err != nil {
|
||||
t.Fatalf("failed generating sample mkv: %v (%s)", err, string(out))
|
||||
}
|
||||
|
||||
info, err := media.Probe(bins.FFprobe, src)
|
||||
if err != nil {
|
||||
t.Fatalf("probe failed: %v", err)
|
||||
}
|
||||
|
||||
srv, err := Start(bins.FFmpeg)
|
||||
if err != nil {
|
||||
t.Fatalf("preview server start failed: %v", err)
|
||||
}
|
||||
defer srv.Close()
|
||||
|
||||
id := srv.Register(info)
|
||||
|
||||
// 1. Test Range request on /video
|
||||
req, _ := http.NewRequest("GET", srv.BaseURL()+"/video?id="+id, nil)
|
||||
req.Header.Set("Range", "bytes=0-127")
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
t.Fatalf("GET /video failed: %v", err)
|
||||
}
|
||||
resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusPartialContent {
|
||||
t.Fatalf("expected 206 Partial Content, got %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
// 2. Test /thumb JPEG generation
|
||||
tResp, err := http.Get(srv.BaseURL() + "/thumb?id=" + id + "&t=0.5")
|
||||
if err != nil {
|
||||
t.Fatalf("GET /thumb failed: %v", err)
|
||||
}
|
||||
tBody, _ := io.ReadAll(tResp.Body)
|
||||
tResp.Body.Close()
|
||||
if tResp.StatusCode != http.StatusOK || len(tBody) < 100 || tBody[0] != 0xFF || tBody[1] != 0xD8 {
|
||||
t.Fatalf("expected valid JPEG thumbnail, status=%d len=%d", tResp.StatusCode, len(tBody))
|
||||
}
|
||||
|
||||
// 3. Test /proxy MKV -> MP4 remux
|
||||
pResp, err := http.Get(srv.BaseURL() + "/proxy?id=" + id + "&merge=0")
|
||||
if err != nil {
|
||||
t.Fatalf("GET /proxy failed: %v", err)
|
||||
}
|
||||
pBody, _ := io.ReadAll(pResp.Body)
|
||||
pResp.Body.Close()
|
||||
if pResp.StatusCode != http.StatusOK || len(pBody) < 500 {
|
||||
t.Fatalf("expected valid MP4 proxy, status=%d len=%d", pResp.StatusCode, len(pBody))
|
||||
}
|
||||
|
||||
// 4. Test unknown ID returns 404
|
||||
nfResp, err := http.Get(srv.BaseURL() + "/video?id=nonexistent")
|
||||
if err != nil {
|
||||
t.Fatalf("GET /video 404 failed: %v", err)
|
||||
}
|
||||
nfResp.Body.Close()
|
||||
if nfResp.StatusCode != http.StatusNotFound {
|
||||
t.Fatalf("expected 404, got %d", nfResp.StatusCode)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user