blob: b8335ba3c4f31c7472538425e119d13c0a8336d3 [file] [log] [blame]
package recent
import (
"testing"
"github.com/stretchr/testify/assert"
"go.skia.org/infra/go/testutils"
)
func TestRecent(t *testing.T) {
testutils.SmallTest(t)
r := New()
list := r.List()
assert.Len(t, list, 0)
r.Add([]byte("{}"))
list = r.List()
assert.Len(t, list, 1)
json := "{\"foo\": 2}"
r.Add([]byte(json))
list = r.List()
assert.Len(t, list, 2)
// Confirm that new additions show up at the beginning
// of the list.
assert.Equal(t, json, list[0].JSON)
// Confirm that we never store more than MAX_RECENT entries.
for i := 0; i < MAX_RECENT+5; i++ {
r.Add([]byte("{}"))
}
assert.Len(t, r.recent, MAX_RECENT)
}