实现直连 Sora 客户端、媒体落地与清理策略\n更新网关与前端配置以支持 Sora 平台\n补齐单元测试与契约测试,新增 curl 测试脚本\n\n测试: go test ./... -tags=unit
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
//go:build unit
|
|
|
|
package service
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/Wei-Shaw/sub2api/internal/config"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestSoraMediaCleanupService_RunCleanup(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
cfg := &config.Config{
|
|
Sora: config.SoraConfig{
|
|
Storage: config.SoraStorageConfig{
|
|
Type: "local",
|
|
LocalPath: tmpDir,
|
|
Cleanup: config.SoraStorageCleanupConfig{
|
|
Enabled: true,
|
|
RetentionDays: 1,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
storage := NewSoraMediaStorage(cfg)
|
|
require.NoError(t, storage.EnsureLocalDirs())
|
|
|
|
oldImage := filepath.Join(storage.ImageRoot(), "old.png")
|
|
newVideo := filepath.Join(storage.VideoRoot(), "new.mp4")
|
|
require.NoError(t, os.WriteFile(oldImage, []byte("old"), 0o644))
|
|
require.NoError(t, os.WriteFile(newVideo, []byte("new"), 0o644))
|
|
|
|
oldTime := time.Now().Add(-48 * time.Hour)
|
|
require.NoError(t, os.Chtimes(oldImage, oldTime, oldTime))
|
|
|
|
cleanup := NewSoraMediaCleanupService(storage, cfg)
|
|
cleanup.runCleanup()
|
|
|
|
require.NoFileExists(t, oldImage)
|
|
require.FileExists(t, newVideo)
|
|
}
|