(item failure, capBytes int)
| 409 | } |
| 410 | |
| 411 | func truncateFailureRecord(item failure, capBytes int) ([]byte, bool, error) { |
| 412 | if capBytes <= 0 { |
| 413 | return nil, false, nil |
| 414 | } |
| 415 | output := []byte(item.Output) |
| 416 | low, high := 0, len(output) |
| 417 | var best []byte |
| 418 | for low <= high { |
| 419 | mid := low + (high-low)/2 |
| 420 | recordLine, err := marshalRecord(failureRecord{ |
| 421 | Package: item.Package, |
| 422 | Test: item.Test, |
| 423 | ElapsedS: item.Elapsed, |
| 424 | Output: strings.ToValidUTF8(string(output[:mid]), ""), |
| 425 | OutputTruncated: true, |
| 426 | }) |
| 427 | if err != nil { |
| 428 | return nil, false, err |
| 429 | } |
| 430 | if len(recordLine) <= capBytes { |
| 431 | best = slices.Clone(recordLine) |
| 432 | low = mid + 1 |
| 433 | continue |
| 434 | } |
| 435 | high = mid - 1 |
| 436 | } |
| 437 | if best == nil { |
| 438 | return nil, false, nil |
| 439 | } |
| 440 | return best, true, nil |
| 441 | } |
| 442 | |
| 443 | func marshalRecord(record any) ([]byte, error) { |
| 444 | line, err := json.Marshal(record) |
no test coverage detected