File: utils_test.go

package info (click to toggle)
golang-github-neowaylabs-wabbit 0.0~git20180530.0.d089945-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, buster-backports
  • size: 268 kB
  • sloc: sh: 24; makefile: 4
file content (43 lines) | stat: -rw-r--r-- 936 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package server

import "testing"

func matchSuccess(t *testing.T, b, r string, expected bool) {
	res := topicMatch(b, r)

	if res != expected {
		t.Errorf("Route '%s' and bind '%s' returns %v", b, r, res)
	}
}

func TestTopicMatch(t *testing.T) {
	for _, pair := range []struct {
		b, r string
		ok   bool
	}{
		// OK
		{"a", "a", true},
		{"ab", "ab", true},
		{"#", "a", true},
		{"#", "aa", true},
		{"#", "aaaaaaaaaaaaaaaaaaaaaaaaa", true},
		{"#.a", "bbbb.a", true},
		{"teste#", "testeb", true},
		{"teste#", "testebbbbbbbbbbb", true},
		{"*.*", "a.b", true},
		{"*a", "aa", true},
		{"*aa", "baa", true},
		{"a*.b*", "ab.ba", true},
		{"maps.layer.stored", "maps.layer.stored", true},
		{"maps.layer.#", "maps.layer.bleh", true},

		// FAIL
		{"", "a", false},
		{"a", "b", false},
		{"*", "aa", false},
		{"a*", "aaa", false},
		{"maps.layer.*", "maps.layer.stored", false},
	} {
		matchSuccess(t, pair.b, pair.r, pair.ok)
	}
}