Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/integrations/v2/app_agent_receiver/utils_test.go
5341 views
1
package app_agent_receiver
2
3
import (
4
"testing"
5
6
"github.com/stretchr/testify/require"
7
)
8
9
func testCase(t *testing.T, URL string, origins []string, expected bool) {
10
result := urlMatchesOrigins(URL, origins)
11
require.Equal(t, expected, result)
12
}
13
14
func Test_Origin_WildcardAlwaysMatches(t *testing.T) {
15
testCase(t, "http://example.com/static/foo.js", []string{"https://foo.com/", "*"}, true)
16
}
17
18
func Test_Origin_Matches(t *testing.T) {
19
testCase(t, "http://example.com/static/foo.js", []string{"https://foo.com/", "http://example.com/"}, true)
20
}
21
22
func Test_Origin_MatchesWithWildcard(t *testing.T) {
23
testCase(t, "http://foo.bar.com/static/foo.js", []string{"https://foo.com/", "http://*.bar.com/"}, true)
24
}
25
26
func Test_Origin_DoesNotMatch(t *testing.T) {
27
testCase(t, "http://example.com/static/foo.js", []string{"https://foo.com/", "http://test.com/"}, false)
28
}
29
30
func Test_Origin_DoesNotMatchWithWildcard(t *testing.T) {
31
testCase(t, "http://foo.bar.com/static/foo.js", []string{"https://foo.com/", "http://*.baz.com/"}, false)
32
}
33
34
func Test_Origin_MatchesWithWildcardNoProtocol(t *testing.T) {
35
testCase(t, "http://foo.bar.com/static/foo.js", []string{"https://foo.com/", "*.bar.com/"}, true)
36
}
37
38