-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurl_filter_test.go
More file actions
56 lines (44 loc) · 1.34 KB
/
url_filter_test.go
File metadata and controls
56 lines (44 loc) · 1.34 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
// Copyright 2019 Hyperscale. All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.
package filter
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestURLFilter(t *testing.T) {
f := NewURLFilter(URLStripUTMParameters())
assertions := []struct {
value string
expected string
}{
{
value: "https://www.google.fr/?utm_source=test&utm_medium=test1&utm_campaign=test2&utm_term=test3&utm_content=test4",
expected: "https://www.google.fr/",
},
{
value: "https://www.google.fr/?foo=bar&utm_source=test&utm_medium=test1&utm_campaign=test2&utm_term=test3&utm_content=test4",
expected: "https://www.google.fr/?foo=bar",
},
}
for _, assertion := range assertions {
u, err := f.Filter(assertion.value)
assert.NoError(t, err)
assert.Equal(t, assertion.expected, u)
}
}
func TestURLFilterWithBadValue(t *testing.T) {
f := NewURLFilter()
u, err := f.Filter(1235)
assert.Equal(t, 1235, u)
assert.Error(t, err)
u, err = f.Filter("134://foo")
assert.Equal(t, "134://foo", u)
assert.Error(t, err)
}
func BenchmarkURLFilter(b *testing.B) {
f := NewURLFilter(URLStripUTMParameters())
for i := 0; i < b.N; i++ {
f.Filter("https://www.google.fr/?foo=bar&utm_source=test&utm_medium=test1&utm_campaign=test2&utm_term=test3&utm_content=test4")
}
}