-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prefix url parameter with https only if match type parameter is exact.
Other match types results in the scheme being stripped anyway so no need to search twice with the same key.
- Loading branch information
Showing
2 changed files
with
56 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package api | ||
|
||
import ( | ||
"net/http" | ||
"net/url" | ||
"testing" | ||
|
||
"github.com/nlnwa/gowarcserver/surt" | ||
) | ||
|
||
func TestParse(t *testing.T) { | ||
domains := []string{ | ||
"no", | ||
"kommune.no", | ||
"nb.no", | ||
} | ||
|
||
for _, domain := range domains { | ||
u, _ := url.Parse("http://example.test/") | ||
values := u.Query() | ||
values.Set("url", domain) | ||
values.Set("matchType", "domain") | ||
u.RawQuery = values.Encode() | ||
|
||
r := &http.Request{URL: u} | ||
|
||
a, err := Parse(r) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
got := SearchAPI{a}.Key() | ||
want := MatchType(surt.UrlToSsurt(a.Urls[0]), MatchTypeDomain) | ||
if got != want { | ||
t.Errorf("Got: '%s', Want: '%s'", got, want) | ||
} | ||
} | ||
|
||
} |