Files
creator-hub/cmd/control-plane/creator_material_test.go
T

54 lines
1.6 KiB
Go

package main
import (
"context"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"testing"
)
func TestDownloadCreatorMaterialPublishesOnlyCompleteFiles(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/source" {
t.Fatalf("unexpected path: %s", r.URL.Path)
}
_, _ = w.Write([]byte("media"))
}))
defer server.Close()
destination := filepath.Join(t.TempDir(), "source")
if err := downloadCreatorMaterial(context.Background(), server.URL+"/source", destination); err != nil {
t.Fatalf("download material: %v", err)
}
content, err := os.ReadFile(destination)
if err != nil {
t.Fatalf("read material: %v", err)
}
if string(content) != "media" {
t.Fatalf("unexpected material: %q", content)
}
if _, err := os.Stat(destination + ".tmp"); !os.IsNotExist(err) {
t.Fatalf("temporary file remains: %v", err)
}
}
func TestDownloadCreatorMaterialRejectsInvalidResponses(t *testing.T) {
server := httptest.NewServer(http.NotFoundHandler())
defer server.Close()
if err := downloadCreatorMaterial(context.Background(), server.URL, filepath.Join(t.TempDir(), "source")); err == nil {
t.Fatal("expected HTTP failure")
}
if err := downloadCreatorMaterial(context.Background(), "file:///tmp/source", filepath.Join(t.TempDir(), "source")); err == nil {
t.Fatal("expected non-HTTP URL failure")
}
}
func TestTranscribeCreatorAudioRequiresExplicitProvider(t *testing.T) {
t.Setenv("CREATOR_TRANSCRIPTION_BIN", "")
if _, err := transcribeCreatorAudio(context.Background(), "/tmp/audio.wav"); err == nil {
t.Fatal("expected missing provider error")
}
}