38 lines
825 B
Go
38 lines
825 B
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/kr/pretty"
|
|
)
|
|
|
|
func TestParseLogLine(t *testing.T) {
|
|
const line = `2016-05-07T09:07:00.001490+00:00 heroku[router]: at=info method=GET path="/blog" host="brs.org" request_id=fc693802-8851-484e-aab4-1d013714b68b fwd="10.29.10.29" dyno=web.3 connect=2ms service=994ms status=200 bytes=552`
|
|
|
|
ll, err := ParseLogLine([]byte(line))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
ms := (ll.TimeTook.Nanoseconds() / 1000000) // ns -> ms == div 1e6
|
|
if ms != 996 {
|
|
t.Fatalf("invalid time took for this line")
|
|
}
|
|
|
|
if ll.Host != "brs.org" {
|
|
pretty.Println(ll)
|
|
|
|
t.Fatal("invalid host")
|
|
}
|
|
}
|
|
|
|
func TestCmpTime(t *testing.T) {
|
|
now := time.Date(2016, time.January, 1, 13, 37, 0, 0, time.UTC)
|
|
then := now.Add(5 * time.Minute)
|
|
|
|
if cmpTime(then, now) {
|
|
t.Fatal("cmpTime error")
|
|
}
|
|
}
|