mirror of https://github.com/mpolden/echoip
Add some tests
This commit is contained in:
parent
f3ce17ff32
commit
cd49f9dc52
5
Makefile
5
Makefile
|
@ -6,7 +6,10 @@ clean:
|
|||
rm -f -- $(TARGET)
|
||||
|
||||
fmt:
|
||||
gofmt -tabs=false -tabwidth=4 -w=true $(TARGET).go
|
||||
gofmt -tabs=false -tabwidth=4 -w=true *.go
|
||||
|
||||
install:
|
||||
go build $(TARGET).go
|
||||
|
||||
test:
|
||||
go test
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue