File: matcher_test.go

package info (click to toggle)
snowflake 2.10.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,104 kB
  • sloc: makefile: 5
file content (55 lines) | stat: -rw-r--r-- 2,185 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
44
45
46
47
48
49
50
51
52
53
54
55
package namematcher

import "testing"

import . "github.com/smartystreets/goconvey/convey"

func TestMatchMember(t *testing.T) {
	testingVector := []struct {
		matcher string
		target  string
		expects bool
	}{
		{matcher: "", target: "", expects: true},
		{matcher: "^snowflake.torproject.net$", target: "snowflake.torproject.net", expects: true},
		{matcher: "^snowflake.torproject.net$", target: "faketorproject.net", expects: false},
		{matcher: "snowflake.torproject.net$", target: "faketorproject.net", expects: false},
		{matcher: "snowflake.torproject.net$", target: "snowflake.torproject.net", expects: true},
		{matcher: "snowflake.torproject.net$", target: "imaginary-01-snowflake.torproject.net", expects: true},
		{matcher: "snowflake.torproject.net$", target: "imaginary-aaa-snowflake.torproject.net", expects: true},
		{matcher: "snowflake.torproject.net$", target: "imaginary-aaa-snowflake.faketorproject.net", expects: false},
	}
	for _, v := range testingVector {
		t.Run(v.matcher+"<>"+v.target, func(t *testing.T) {
			Convey("test", t, func() {
				matcher := NewNameMatcher(v.matcher)
				So(matcher.IsMember(v.target), ShouldEqual, v.expects)
			})
		})
	}
}

func TestMatchSubset(t *testing.T) {
	testingVector := []struct {
		matcher string
		target  string
		expects bool
	}{
		{matcher: "", target: "", expects: true},
		{matcher: "^snowflake.torproject.net$", target: "^snowflake.torproject.net$", expects: true},
		{matcher: "snowflake.torproject.net$", target: "^snowflake.torproject.net$", expects: true},
		{matcher: "snowflake.torproject.net$", target: "snowflake.torproject.net$", expects: true},
		{matcher: "snowflake.torproject.net$", target: "testing-snowflake.torproject.net$", expects: true},
		{matcher: "snowflake.torproject.net$", target: "^testing-snowflake.torproject.net$", expects: true},
		{matcher: "snowflake.torproject.net$", target: "", expects: false},
	}
	for _, v := range testingVector {
		t.Run(v.matcher+"<>"+v.target, func(t *testing.T) {
			Convey("test", t, func() {
				matcher := NewNameMatcher(v.matcher)
				target := NewNameMatcher(v.target)
				So(matcher.IsSupersetOf(target), ShouldEqual, v.expects)
			})
		})
	}
}