github.com/mattyr/nomad@v0.3.3-0.20160919021406-3485a065154a/client/driver/logging/syslog_parser_unix_test.go (about)

     1  // +build darwin dragonfly freebsd linux netbsd openbsd solaris
     2  
     3  package logging
     4  
     5  import (
     6  	"bytes"
     7  	"log"
     8  	"os"
     9  	"testing"
    10  
    11  	syslog "github.com/RackSec/srslog"
    12  )
    13  
    14  func TestLogParser_Priority(t *testing.T) {
    15  	line := []byte("<30>2016-02-10T10:16:43-08:00 d-thinkpad docker/e2a1e3ebd3a3[22950]: 1:C 10 Feb 18:16:43.391 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf")
    16  	d := NewDockerLogParser(log.New(os.Stdout, "", log.LstdFlags))
    17  	p, _, err := d.parsePriority(line)
    18  	if err != nil {
    19  		t.Fatalf("got an err: %v", err)
    20  	}
    21  	if p.Severity != syslog.LOG_INFO {
    22  		t.Fatalf("expected serverity: %v, got: %v", syslog.LOG_INFO, p.Severity)
    23  	}
    24  
    25  	idx := d.logContentIndex(line)
    26  	expected := bytes.Index(line, []byte("1:C 10 Feb 18:16:43.391"))
    27  	if idx != expected {
    28  		t.Fatalf("expected idx: %v, got: %v", expected, idx)
    29  	}
    30  }
    31  
    32  func TestLogParser_Priority_UnixFormatter(t *testing.T) {
    33  	line := []byte("<30>Feb  6, 10:16:43 docker/e2a1e3ebd3a3[22950]: 1:C 10 Feb 18:16:43.391 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf")
    34  	d := NewDockerLogParser(log.New(os.Stdout, "", log.LstdFlags))
    35  	p, _, err := d.parsePriority(line)
    36  	if err != nil {
    37  		t.Fatalf("got an err: %v", err)
    38  	}
    39  	if p.Severity != syslog.LOG_INFO {
    40  		t.Fatalf("expected serverity: %v, got: %v", syslog.LOG_INFO, p.Severity)
    41  	}
    42  
    43  	idx := d.logContentIndex(line)
    44  	expected := bytes.Index(line, []byte("1:C 10 Feb 18:16:43.391"))
    45  	if idx != expected {
    46  		t.Fatalf("expected idx: %v, got: %v", expected, idx)
    47  	}
    48  }