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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main

import (
	"net/http"
	"os"
	"testing"
	"time"
)

// TestLivePdfjsSync exercises the real download and ingest against GitHub.
// Skipped unless MAILWEB_LIVE=1, since the test suite must not need a network.
func TestLivePdfjsSync(t *testing.T) {
	if os.Getenv("MAILWEB_LIVE") == "" {
		t.Skip("set MAILWEB_LIVE=1 to exercise the real GitHub download")
	}
	client := &http.Client{Timeout: 120 * time.Second}
	v, err := pdfjsLatestVersion(client)
	if err != nil {
		t.Fatalf("latest version: %v", err)
	}
	t.Logf("latest version: %s", v)

	assets, err := pdfjsDownload(client, v)
	if err != nil {
		t.Fatalf("download: %v", err)
	}
	var total int
	for _, a := range assets {
		total += len(a.Content)
	}
	t.Logf("downloaded %d files, %.1f MB", len(assets), float64(total)/1048576)
	for _, a := range assets {
		if len(a.Content) == 0 {
			t.Errorf("%s is empty", a.Path)
		}
	}

	db := newTestServer(t).db
	gen, err := pdfjsIngest(db.Write, v, assets)
	if err != nil {
		t.Fatalf("ingest: %v", err)
	}
	t.Logf("ingested as generation %d", gen)

	got, g2, err := loadPdfjsAsset(db.Read, "web/viewer.html")
	if err != nil {
		t.Fatalf("load viewer.html: %v", err)
	}
	if g2 != gen {
		t.Errorf("generation %d, want %d", g2, gen)
	}
	if got.MimeType != "text/html; charset=utf-8" {
		t.Errorf("viewer.html mime %q", got.MimeType)
	}
	t.Logf("viewer.html is %d bytes, %s", len(got.Content), got.MimeType)
}