fix: 修复发布流水线 LFS 资产校验
This commit is contained in:
58
versionctl/projectversion/release_assets_test.go
Normal file
58
versionctl/projectversion/release_assets_test.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package projectversion
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestCheckReleaseAssets(t *testing.T) {
|
||||
t.Run("valid assets", func(t *testing.T) {
|
||||
root := setupReleaseAssetRoot(t)
|
||||
|
||||
require.NoError(t, CheckReleaseAssets(root))
|
||||
})
|
||||
|
||||
t.Run("lfs pointer", func(t *testing.T) {
|
||||
root := setupReleaseAssetRoot(t)
|
||||
writeReleaseAsset(t, root, "assets/icon.ico", []byte("version https://git-lfs.github.com/spec/v1\noid sha256:abc\nsize 123\n"))
|
||||
|
||||
err := CheckReleaseAssets(root)
|
||||
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "assets/icon.ico 是 Git LFS pointer")
|
||||
})
|
||||
|
||||
t.Run("invalid format", func(t *testing.T) {
|
||||
root := setupReleaseAssetRoot(t)
|
||||
writeReleaseAsset(t, root, "frontend/public/icon.png", []byte("not a png"))
|
||||
|
||||
err := CheckReleaseAssets(root)
|
||||
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "frontend/public/icon.png 不是有效的前端 PNG 图标")
|
||||
})
|
||||
}
|
||||
|
||||
func setupReleaseAssetRoot(t *testing.T) string {
|
||||
t.Helper()
|
||||
|
||||
root := t.TempDir()
|
||||
writeReleaseAsset(t, root, "assets/icon.ico", []byte{0x00, 0x00, 0x01, 0x00, 0x01})
|
||||
writeReleaseAsset(t, root, "assets/icon.icns", []byte("icnsdata"))
|
||||
writeReleaseAsset(t, root, "assets/icon.png", []byte{0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00})
|
||||
writeReleaseAsset(t, root, "frontend/public/icon.png", []byte{0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00})
|
||||
|
||||
return root
|
||||
}
|
||||
|
||||
func writeReleaseAsset(t *testing.T, root, relPath string, content []byte) {
|
||||
t.Helper()
|
||||
|
||||
fullPath := filepath.Join(root, relPath)
|
||||
require.NoError(t, os.MkdirAll(filepath.Dir(fullPath), 0o755))
|
||||
require.NoError(t, os.WriteFile(fullPath, content, 0o600))
|
||||
}
|
||||
Reference in New Issue
Block a user