mirror of
https://github.com/mpolden/echoip.git
synced 2024-11-10 15:37:24 +01:00
34 lines
857 B
Go
34 lines
857 B
Go
package main
|
|
|
|
import "testing"
|
|
|
|
func TestIsCLI(t *testing.T) {
|
|
userAgents := []string{"curl/7.26.0", "Wget/1.13.4 (linux-gnu)",
|
|
"fetch libfetch/2.0"}
|
|
|
|
for _, userAgent := range userAgents {
|
|
if !isCLI(userAgent) {
|
|
t.Errorf("Expected true for %s", userAgent)
|
|
}
|
|
}
|
|
|
|
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"
|
|
if isCLI(browserUserAgent) {
|
|
t.Errorf("Expected false for %s", browserUserAgent)
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|