项目文件夹

文件
wehub-resource-sync f99010fae1
CI / lint (push) Failing after 1s
CI / frontend (push) Failing after 1s
CI / scripts (push) Failing after 1s
CI / Go Test (ubuntu-latest) (push) Failing after 0s
CI / frontend-node-25 (push) Failing after 1s
CI / docs (push) Failing after 0s
CI / coverage (push) Failing after 0s
CI / e2e (push) Failing after 0s
Docker / build-and-push (push) Failing after 1s
CI / integration (push) Failing after 4m43s
CI / Go Test (windows-latest) (push) Has been cancelled
CI / Desktop Unit Tests (Windows) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Linux (arm64)) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Linux) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Windows) (push) Has been cancelled
Desktop Artifacts (macOS) / Desktop Build (macOS (aarch64)) (push) Has been cancelled
Desktop Artifacts (macOS) / Desktop Build (macOS (x86_64)) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:30:36 +08:00

63 行
1.6 KiB
Go

package importer
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestBuildAssetIndex(t *testing.T) {
dir := t.TempDir()
dalleDir := filepath.Join(dir, "dalle-generations")
require.NoError(t, os.MkdirAll(dalleDir, 0o755))
require.NoError(t, os.WriteFile(
filepath.Join(dalleDir, "file-abc123-aaaa1111-bbbb-cccc-dddd-eeeeeeeeeeee.webp"),
[]byte("fake image"), 0o644,
))
userDir := filepath.Join(dir, "user-xyz")
require.NoError(t, os.MkdirAll(userDir, 0o755))
require.NoError(t, os.WriteFile(
filepath.Join(userDir, "file_deadbeef-aaaa1111-bbbb-cccc-dddd-eeeeeeeeeeee.png"),
[]byte("fake upload"), 0o644,
))
idx := BuildAssetIndex(dir)
path, ok := idx.Resolve("file-service://file-abc123")
assert.True(t, ok)
assert.Contains(t, path, "file-abc123")
path, ok = idx.Resolve("sediment://file_deadbeef")
assert.True(t, ok)
assert.Contains(t, path, "file_deadbeef")
_, ok = idx.Resolve("file-service://file-unknown")
assert.False(t, ok)
}
func TestCopyAsset(t *testing.T) {
src := filepath.Join(t.TempDir(), "source.webp")
require.NoError(t, os.WriteFile(src, []byte("image data"), 0o644))
assetsDir := filepath.Join(t.TempDir(), "assets")
ref, err := CopyAsset(src, assetsDir)
require.NoError(t, err)
assert.Contains(t, ref, "asset://")
assert.Contains(t, ref, ".webp")
// Second call should return same ref (dedup).
ref2, err := CopyAsset(src, assetsDir)
require.NoError(t, err)
assert.Equal(t, ref, ref2)
entries, err := os.ReadDir(assetsDir)
require.NoError(t, err)
assert.Len(t, entries, 1)
}