-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
topicselectorlru_test.go
38 lines (27 loc) · 1.35 KB
/
topicselectorlru_test.go
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
package mercure
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestMatchLRU(t *testing.T) {
tss, err := NewTopicSelectorStoreLRU(DefaultTopicSelectorStoreLRUMaxEntriesPerShard, DefaultTopicSelectorStoreLRUMaxEntriesPerShard)
require.NoError(t, err)
assert.False(t, tss.match("foo", "bar"))
assert.True(t, tss.match("https://example.com/foo/bar", "https://example.com/{foo}/bar"))
_, found := tss.cache.Get("t_https://example.com/{foo}/bar")
assert.True(t, found)
_, found = tss.cache.Get("m_https://example.com/{foo}/bar_https://example.com/foo/bar")
assert.True(t, found)
assert.True(t, tss.match("https://example.com/foo/bar", "https://example.com/{foo}/bar"))
assert.False(t, tss.match("https://example.com/foo/bar/baz", "https://example.com/{foo}/bar"))
_, found = tss.cache.Get("t_https://example.com/{foo}/bar")
assert.True(t, found)
_, found = tss.cache.Get("m_https://example.com/{foo}/bar_https://example.com/foo/bar")
assert.True(t, found)
assert.True(t, tss.match("https://example.com/kevin/dunglas", "https://example.com/{fistname}/{lastname}"))
assert.True(t, tss.match("https://example.com/foo/bar", "*"))
assert.True(t, tss.match("https://example.com/foo/bar", "https://example.com/foo/bar"))
assert.True(t, tss.match("foo", "foo"))
assert.False(t, tss.match("foo", "bar"))
}