2013-09-08 19:37:41 +02:00
|
|
|
package main
|
|
|
|
|
2014-12-22 16:46:36 +01:00
|
|
|
import (
|
|
|
|
"net/url"
|
|
|
|
"testing"
|
|
|
|
)
|
2013-09-08 19:37:41 +02:00
|
|
|
|
2014-12-22 00:19:29 +01:00
|
|
|
func TestIsCLI(t *testing.T) {
|
2014-11-01 14:36:57 +01:00
|
|
|
userAgents := []string{"curl/7.26.0", "Wget/1.13.4 (linux-gnu)",
|
|
|
|
"fetch libfetch/2.0"}
|
2013-09-08 19:37:41 +02:00
|
|
|
|
2014-11-01 14:36:57 +01:00
|
|
|
for _, userAgent := range userAgents {
|
2014-12-22 00:19:29 +01:00
|
|
|
if !isCLI(userAgent) {
|
2014-11-01 14:36:57 +01:00
|
|
|
t.Errorf("Expected true for %s", userAgent)
|
|
|
|
}
|
|
|
|
}
|
2013-09-08 19:37:41 +02:00
|
|
|
|
2014-11-01 14:36:57 +01:00
|
|
|
browserUserAgent := "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) " +
|
|
|
|
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.28 " +
|
|
|
|
"Safari/537.36"
|
2014-12-22 00:19:29 +01:00
|
|
|
if isCLI(browserUserAgent) {
|
2014-11-01 14:36:57 +01:00
|
|
|
t.Errorf("Expected false for %s", browserUserAgent)
|
|
|
|
}
|
2013-09-08 19:37:41 +02:00
|
|
|
}
|
2014-12-22 00:55:56 +01:00
|
|
|
|
|
|
|
func TestPathToKey(t *testing.T) {
|
|
|
|
if key := pathToKey("/ip"); key != "ip" {
|
|
|
|
t.Fatalf("Expected 'ip', got '%s'", key)
|
|
|
|
}
|
|
|
|
if key := pathToKey("/User-Agent"); key != "user-agent" {
|
|
|
|
t.Fatalf("Expected 'user-agent', got '%s'", key)
|
|
|
|
}
|
|
|
|
if key := pathToKey("/all.json"); key != "all" {
|
|
|
|
t.Fatalf("Expected 'all', got '%s'", key)
|
|
|
|
}
|
|
|
|
}
|
2014-12-22 16:46:36 +01:00
|
|
|
|
|
|
|
func TestLookupCmd(t *testing.T) {
|
|
|
|
values := url.Values{"cmd": []string{"curl"}}
|
|
|
|
if v := lookupCmd(values); v.Name != "curl" {
|
|
|
|
t.Fatalf("Expected 'curl', got '%s'", v)
|
|
|
|
}
|
|
|
|
values = url.Values{"cmd": []string{"foo"}}
|
|
|
|
if v := lookupCmd(values); v.Name != "curl" {
|
|
|
|
t.Fatalf("Expected 'curl', got '%s'", v)
|
|
|
|
}
|
|
|
|
values = url.Values{}
|
|
|
|
if v := lookupCmd(values); v.Name != "curl" {
|
|
|
|
t.Fatalf("Expected 'curl', got '%s'", v)
|
|
|
|
}
|
|
|
|
values = url.Values{"cmd": []string{"wget"}}
|
|
|
|
if v := lookupCmd(values); v.Name != "wget" {
|
|
|
|
t.Fatalf("Expected 'wget', got '%s'", v)
|
|
|
|
}
|
|
|
|
values = url.Values{"cmd": []string{"fetch"}}
|
|
|
|
if v := lookupCmd(values); v.Name != "fetch" {
|
|
|
|
t.Fatalf("Expected 'fetch', got '%s'", v)
|
|
|
|
}
|
|
|
|
}
|