Skip to content
quarry Artifact [22b2931eff]
Login

Artifact [22b2931eff]

Artifact 22b2931eff4bf3b72f8340b8d6bd0ea0630da72ec92c425334eb58a84abb1124:


package main

import (
	"path/filepath"
	"strings"
	"testing"

	"craftdesign.group/quarry/internal/oltp"
)

// A person's uploaded picture is found like a repository's or a team's
// — leaving the kind out drew everyone as their identicon however many
// times they uploaded — and an upload shows at once, not at the next
// cache interval.
func TestAPersonsPictureIsFound(t *testing.T) {
	db, err := oltp.Open(filepath.Join(t.TempDir(), "oltp.db"))
	if err != nil {
		t.Fatal(err)
	}
	t.Cleanup(func() { db.Close() })
	set := func(etag string) {
		if err := db.SetAvatar(oltp.Avatar{Kind: oltp.AvatarUser, Name: "dan", Key: "k-" + etag, Mime: "image/png", ETag: etag, Bytes: 10}); err != nil {
			t.Fatal(err)
		}
	}
	set(strings.Repeat("a", 64))
	m := newMarkCache(db)
	if tag, ok := m.tag("user", "dan"); !ok || tag[:4] != "aaaa" {
		t.Fatalf("FAIL: dan's picture was not found (%q, %v)", tag, ok)
	}
	set(strings.Repeat("b", 64))
	m.refresh()
	if tag, _ := m.tag("user", "dan"); tag[:4] != "bbbb" {
		t.Fatalf("FAIL: after a new upload and a refresh the lookup still answers %q", tag)
	}
	if _, ok := m.tag("user", "eve"); ok {
		t.Fatal("FAIL: someone with no picture was answered as having one")
	}
	t.Log("ok: a person's picture is found, a new one shows after refresh, no picture stays none")
}