File: policy_test.go

package info (click to toggle)
golang-github-anacrolix-missinggo 2.1.0-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 872 kB
  • sloc: makefile: 4
file content (24 lines) | stat: -rw-r--r-- 525 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package filecache

import (
	"testing"
	"time"

	"github.com/stretchr/testify/assert"
)

func testChooseForgottenKey(t *testing.T, p Policy) {
	assert.Equal(t, 0, p.NumItems())
	assert.Panics(t, func() { p.Choose() })
	p.Used(key("a"), time.Now())
	assert.Equal(t, 1, p.NumItems())
	p.Used(key("a"), time.Now().Add(1))
	assert.Equal(t, 1, p.NumItems())
	p.Forget(key("a"))
	assert.Equal(t, 0, p.NumItems())
	assert.Panics(t, func() { p.Choose() })
}

func testPolicy(t *testing.T, p Policy) {
	testChooseForgottenKey(t, p)
}