summaryrefslogtreecommitdiff
path: root/events/wildcard_test.go
blob: dfa65e63a238a898e009278dedfb43121c71c3bc (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
42
43
44
45
46
47
48
49
50
51
52
53
54
package events

import (
	"testing"

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

func TestWildcard(t *testing.T) {
	w, err := newWildcard("http.*")
	assert.NoError(t, err)
	assert.True(t, w.match("http.SuperEvent"))
	assert.False(t, w.match("https.SuperEvent"))
	assert.False(t, w.match(""))
	assert.False(t, w.match("*"))
	assert.False(t, w.match("****"))
	assert.True(t, w.match("http.****"))

	// *.* -> *
	w, err = newWildcard("*")
	assert.NoError(t, err)
	assert.True(t, w.match("http.SuperEvent"))
	assert.True(t, w.match("https.SuperEvent"))
	assert.True(t, w.match(""))
	assert.True(t, w.match("*"))
	assert.True(t, w.match("****"))
	assert.True(t, w.match("http.****"))

	w, err = newWildcard("*.WorkerError")
	assert.NoError(t, err)
	assert.False(t, w.match("http.SuperEvent"))
	assert.False(t, w.match("https.SuperEvent"))
	assert.False(t, w.match(""))
	assert.False(t, w.match("*"))
	assert.False(t, w.match("****"))
	assert.False(t, w.match("http.****"))
	assert.True(t, w.match("http.WorkerError"))

	w, err = newWildcard("http.WorkerError")
	assert.NoError(t, err)
	assert.False(t, w.match("http.SuperEvent"))
	assert.False(t, w.match("https.SuperEvent"))
	assert.False(t, w.match(""))
	assert.False(t, w.match("*"))
	assert.False(t, w.match("****"))
	assert.False(t, w.match("http.****"))
	assert.True(t, w.match("http.WorkerError"))

	w, err = newWildcard("http.Worker*")
	assert.NoError(t, err)
	assert.True(t, w.match("http.WorkerFoo"))
	assert.False(t, w.match("h*.SuperEvent"))
	assert.False(t, w.match("h*.Worker"))
}