fix: address batch image ci failures

This commit is contained in:
Turtle_Li committed 2026-07-07 10:50:36 +08:00
1 parent 89edba8028
commit aff148167c
11 files changed
+63 -51

No files matched your search

@@ -4,7 +4,11 @@ package repository
import (
"context"
"crypto/sha1"
"encoding/hex"
"errors"
"regexp"
"strings"
"testing"
"time"
@@ -12,6 +16,10 @@ import (
"github.com/stretchr/testify/require"
)
func newBatchImageRepositoryWithSQL(sqlq batchImageSQLExecutor) *batchImageRepository {
return &batchImageRepository{sql: sqlq}
}
func TestBatchImageRepository_CreateJobAndDuplicates(t *testing.T) {
ctx := context.Background()
tx := testTx(t)
@@ -325,7 +333,26 @@ func TestBatchImageRepository_AppendEvent(t *testing.T) {
func batchImageTestID(t *testing.T, prefix string) string {
t.Helper()
return "imgbatch_" + uniqueTestValue(t, prefix)
safePrefix := batchImageSafeTestIDSegment(prefix, 20)
sum := sha1.Sum([]byte(t.Name()))
return "imgbatch_" + safePrefix + "_" + hex.EncodeToString(sum[:])[:16]
}
func batchImageSafeTestIDSegment(v string, maxLen int) string {
v = strings.ToLower(strings.TrimSpace(v))
v = regexp.MustCompile(`[^a-z0-9_-]+`).ReplaceAllString(v, "-")
v = strings.Trim(v, "-_")
if v == "" {
v = "job"
}
if len(v) > maxLen {
v = v[:maxLen]
v = strings.Trim(v, "-_")
}
if v == "" {
return "job"
}
return v
}
func batchImageTestStringPtr(v string) *string {