Migration This is my new public git source viewer. Source coming soon. Please contact with concerns/bugs. Contact me

internal/core/core_test.go

554bcfc63721b22faf8bca78d5518d76e24a4d20 · 921 B · 27 lines raw

1 package core
2
3 import (
4 "strings"
5 "testing"
6 )
7
8 // The site revision is the site-level analogue of RepoInfo.GPGKeyring: it
9 // must be part of contentIdentity or a notice change cannot invalidate the
10 // module cache or the response ETag.
11 func TestContentIdentityIncludesSiteRevision(t *testing.T) {
12 a := NewCtx(&Site{RevFn: func() string { return "rev-a" }}, nil, RepoInfo{}, "main")
13 b := NewCtx(&Site{RevFn: func() string { return "rev-b" }}, nil, RepoInfo{}, "main")
14 a.Commit, b.Commit = "sha", "sha"
15 if a.contentIdentity() == b.contentIdentity() {
16 t.Fatal("site revision is not part of contentIdentity")
17 }
18 }
19
20 // Tests construct bare *Ctx values (see blob_test.go) and LoadTemplates
21 // parses with &Ctx{}; contentIdentity must tolerate a nil Site.
22 func TestContentIdentityNilSite(t *testing.T) {
23 got := (&Ctx{}).contentIdentity()
24 if !strings.HasPrefix(got, "|") {
25 t.Fatalf("contentIdentity() = %q", got)
26 }
27 }