-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassert_test.go
More file actions
96 lines (89 loc) · 2.04 KB
/
assert_test.go
File metadata and controls
96 lines (89 loc) · 2.04 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package w3pilot
import (
"testing"
)
func TestMatchURLPattern(t *testing.T) {
tests := []struct {
name string
url string
pattern string
want bool
}{
// Exact match
{
name: "exact match",
url: "https://example.com/page",
pattern: "https://example.com/page",
want: true,
},
{
name: "exact match fail",
url: "https://example.com/page",
pattern: "https://example.com/other",
want: false,
},
// Glob patterns
{
name: "glob single wildcard",
url: "https://example.com/users/123",
pattern: "https://example.com/users/*",
want: true,
},
{
name: "glob double wildcard",
url: "https://example.com/api/v1/users/123",
pattern: "https://example.com/**/users/*",
want: true,
},
{
name: "glob wildcard in middle",
url: "https://example.com/users/123/profile",
pattern: "https://example.com/users/*/profile",
want: true,
},
{
name: "glob no match",
url: "https://example.com/admin/page",
pattern: "https://example.com/users/*",
want: false,
},
// Regex patterns
{
name: "regex match",
url: "https://example.com/users/12345",
pattern: "/https://example\\.com/users/\\d+/",
want: true,
},
{
name: "regex no match",
url: "https://example.com/users/abc",
pattern: "/https://example\\.com/users/\\d+/",
want: false,
},
{
name: "regex partial match",
url: "https://example.com/dashboard",
pattern: "/dashboard/",
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := matchURLPattern(tt.url, tt.pattern)
if got != tt.want {
t.Errorf("matchURLPattern(%q, %q) = %v, want %v", tt.url, tt.pattern, got, tt.want)
}
})
}
}
func TestAssertionError(t *testing.T) {
err := &AssertionError{
Type: "TestError",
Message: "test message",
Expected: "expected",
Actual: "actual",
}
if err.Error() != "test message" {
t.Errorf("Error() = %q, want %q", err.Error(), "test message")
}
}