package unit import ( "context" "fmt" "testing" "time" "github.com/break/junhong_cmp_fiber/pkg/constants" ) // createContextWithUserID 创建带用户 ID 的 context func createContextWithUserID(userID uint) context.Context { return context.WithValue(context.Background(), constants.ContextKeyUserID, userID) } // generateUniqueUsername 生成唯一的用户名(用于测试) func generateUniqueUsername(prefix string, t *testing.T) string { return fmt.Sprintf("%s_%d", prefix, time.Now().UnixNano()) } // generateUniquePhone 生成唯一的手机号(用于测试) func generateUniquePhone() string { // 使用时间戳后8位生成唯一手机号 timestamp := time.Now().UnixNano() suffix := timestamp % 100000000 // 8位数字 return fmt.Sprintf("138%08d", suffix) }