-
Notifications
You must be signed in to change notification settings - Fork 0
/
subject_builder_test.go
59 lines (42 loc) · 1.68 KB
/
subject_builder_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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package natsutil_test
import (
"testing"
"github.com/41north/natsutil.go"
"github.com/stretchr/testify/assert"
)
func TestSubjectBuilder_PushPop(t *testing.T) {
sb := natsutil.SubjectBuilder{}
assert.Equal(t, "", sb.String())
assert.Nil(t, sb.Push("foo"))
assert.Equal(t, "foo", sb.String())
assert.Equal(t, &sb, sb.MustPush("bar", "baz"))
assert.Equal(t, "foo.bar.baz", sb.String())
assert.Nil(t, sb.Pop(1))
assert.Equal(t, "foo.bar", sb.String())
assert.Equal(t, &sb, sb.MustPop(1))
assert.Equal(t, "foo", sb.String())
assert.Error(t, natsutil.ErrPopInsufficientElements, sb.Pop(2))
assert.Panics(t, func() { sb.MustPop(2) })
sb.Star()
assert.Equal(t, "foo.*", sb.String())
assert.Nil(t, sb.Push("hello"))
assert.Equal(t, "foo.*.hello", sb.String())
sb.Chevron()
assert.Equal(t, "foo.*.hello.>", sb.String())
}
func TestSubjectBuilder_InvalidCharacters(t *testing.T) {
sb := natsutil.SubjectBuilder{}
assert.Nil(t, sb.Push("foo"))
assert.Nil(t, sb.Push("BAR"))
assert.Nil(t, sb.Push("hell0_wor1d"))
assert.Equal(t, "foo.BAR.hell0_wor1d", sb.String())
assert.Error(t, natsutil.ErrSubjectInvalidCharacters, sb.Push("%"))
assert.Error(t, natsutil.ErrSubjectInvalidCharacters, sb.Push("-"))
assert.Error(t, natsutil.ErrSubjectInvalidCharacters, sb.Push("*"))
assert.Error(t, natsutil.ErrSubjectInvalidCharacters, sb.Push(">"))
assert.Error(t, natsutil.ErrSubjectInvalidCharacters, sb.Push("{"))
assert.Error(t, natsutil.ErrSubjectInvalidCharacters, sb.Push("}"))
assert.Error(t, natsutil.ErrSubjectInvalidCharacters, sb.Push("("))
assert.Error(t, natsutil.ErrSubjectInvalidCharacters, sb.Push(")"))
assert.Error(t, natsutil.ErrSubjectInvalidCharacters, sb.Push("+"))
}