-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
43 lines (36 loc) · 1015 Bytes
/
main_test.go
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
// main_test.go
package main
import (
"testing"
)
func TestApplyRules(t *testing.T) {
ruleSet := &RuleSet{
Rules: []Rule{
{
Path: "/search",
Locations: map[string]string{
"United States": "https://duckduckgo.com/?q=news",
"Luxembourg": "https://www.bing.com/search?q=news",
"Default": "https://www.google.com/search?q=news",
},
},
},
}
// Test when a matching rule is found
result, found := applyRules(ruleSet, "/search", "United States")
// result, found := applyRules(ruleSet, "/search")
if !found {
t.Errorf("Expected rule to be found, but not found")
}
if result != "https://duckduckgo.com/?q=news" {
t.Errorf("Expected redirection URL: https://duckduckgo.com/?q=news, got: %s", result)
}
// Test when no matching rule is found
result, found = applyRules(ruleSet, "/unknown/url", "US")
if found {
t.Errorf("Expected rule not to be found, but found")
}
if result != "" {
t.Errorf("Expected empty redirection URL, got: %s", result)
}
}