-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmime_extract_manual_test.go
More file actions
38 lines (35 loc) · 1.27 KB
/
Copy pathmime_extract_manual_test.go
File metadata and controls
38 lines (35 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"os"
"strings"
"testing"
)
// TestExtractAttachmentFromRawEmail_RealCapture verifies against a REAL
// captured raw email (same probe message used to fix the identical bug in
// machin-resend-inbox), not a synthetic fixture. Skips if the file isn't
// present — this is a manual verification aid, not a permanent CI fixture
// (the raw file isn't committed).
func TestExtractAttachmentFromRawEmail_RealCapture(t *testing.T) {
raw, err := os.ReadFile("/tmp/lacure-raw-email-go.eml")
if err != nil {
t.Skip("no real capture at /tmp/lacure-raw-email-go.eml, skipping")
}
data, err := extractAttachmentFromRawEmail(raw, "devis-probe.pdf")
if err != nil {
t.Fatalf("extract failed: %v", err)
}
if len(data) != 240 {
t.Fatalf("expected 240 bytes (Resend's own reported size), got %d", len(data))
}
if !strings.HasPrefix(string(data), "%PDF") {
t.Fatalf("expected a PDF header, got: %q", string(data[:20]))
}
if !strings.Contains(string(data), "fake devis for attachment probe") {
t.Fatalf("expected the known probe content, got: %q", string(data))
}
t.Logf("extracted %d bytes: %s", len(data), string(data))
_, err = extractAttachmentFromRawEmail(raw, "nosuchfile.xyz")
if err == nil {
t.Fatal("expected an error for a nonexistent filename")
}
}