summaryrefslogtreecommitdiff
path: root/internal/cache/status_test.go
blob: 10dee5bcae3ee1334111f0e7c99c9d3169e987c9 (plain)
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
package cache_test

import (
	"testing"

	"github.com/superseriousbusiness/gotosocial/internal/cache"
	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
)

func TestStatusCache(t *testing.T) {
	cache := cache.NewStatusCache()

	// Attempt to place a status
	status := gtsmodel.Status{
		ID:  "id",
		URI: "uri",
		URL: "url",
	}
	cache.Put(&status)

	var ok bool
	var check *gtsmodel.Status

	// Check we can retrieve
	check, ok = cache.GetByID(status.ID)
	if !ok || !statusIs(&status, check) {
		t.Fatal("Could not find expected status")
	}
	check, ok = cache.GetByURI(status.URI)
	if !ok || !statusIs(&status, check) {
		t.Fatal("Could not find expected status")
	}
	check, ok = cache.GetByURL(status.URL)
	if !ok || !statusIs(&status, check) {
		t.Fatal("Could not find expected status")
	}
}

func statusIs(status1, status2 *gtsmodel.Status) bool {
	return status1.ID == status2.ID && status1.URI == status2.URI && status1.URL == status2.URL
}