forked from mpolden/echoip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ifconfig_test.go
59 lines (53 loc) · 1.55 KB
/
ifconfig_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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"net/url"
"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)
}
}
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)
}
}