47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestWriteCreatorMediaPublishesOnlyCompleteFiles(t *testing.T) {
|
|
destination := filepath.Join(t.TempDir(), "source")
|
|
if err := writeCreatorMedia(destination, []byte("media")); err != nil {
|
|
t.Fatalf("write media: %v", err)
|
|
}
|
|
content, err := os.ReadFile(destination)
|
|
if err != nil {
|
|
t.Fatalf("read media: %v", err)
|
|
}
|
|
if string(content) != "media" {
|
|
t.Fatalf("unexpected media: %q", content)
|
|
}
|
|
matches, err := filepath.Glob(filepath.Join(filepath.Dir(destination), ".creator-media-*"))
|
|
if err != nil {
|
|
t.Fatalf("find temporary media: %v", err)
|
|
}
|
|
if len(matches) != 0 {
|
|
t.Fatalf("temporary files remain: %v", matches)
|
|
}
|
|
}
|
|
|
|
func TestWriteCreatorMediaRejectsEmptyAndOversizedFiles(t *testing.T) {
|
|
destination := filepath.Join(t.TempDir(), "source")
|
|
if err := writeCreatorMedia(destination, nil); err == nil {
|
|
t.Fatal("expected empty media to be rejected")
|
|
}
|
|
if err := writeCreatorMedia(destination, make([]byte, maxCreatorMediaBytes+1)); err == nil {
|
|
t.Fatal("expected oversized media to be rejected")
|
|
}
|
|
}
|
|
|
|
func TestTranscribeCreatorAudioRequiresExplicitProvider(t *testing.T) {
|
|
t.Setenv("CREATOR_TRANSCRIPTION_BIN", "")
|
|
if _, err := transcribeCreatorAudio(context.Background(), "/tmp/audio.wav", "base"); err == nil {
|
|
t.Fatal("expected missing provider error")
|
|
}
|
|
}
|