github.com/hhrutter/nomad@v0.6.0-rc2.0.20170723054333-80c4b03f0705/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  	t.Parallel()
    16  	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")
    17  	d := NewDockerLogParser(log.New(os.Stdout, "", log.LstdFlags))
    18  	p, _, err := d.parsePriority(line)
    19  	if err != nil {
    20  		t.Fatalf("got an err: %v", err)
    21  	}
    22  	if p.Severity != syslog.LOG_INFO {
    23  		t.Fatalf("expected serverity: %v, got: %v", syslog.LOG_INFO, p.Severity)
    24  	}
    25  
    26  	idx := d.logContentIndex(line)
    27  	expected := bytes.Index(line, []byte("1:C 10 Feb 18:16:43.391"))
    28  	if idx != expected {
    29  		t.Fatalf("expected idx: %v, got: %v", expected, idx)
    30  	}
    31  }
    32  
    33  func TestLogParser_Priority_UnixFormatter(t *testing.T) {
    34  	t.Parallel()
    35  	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")
    36  	d := NewDockerLogParser(log.New(os.Stdout, "", log.LstdFlags))
    37  	p, _, err := d.parsePriority(line)
    38  	if err != nil {
    39  		t.Fatalf("got an err: %v", err)
    40  	}
    41  	if p.Severity != syslog.LOG_INFO {
    42  		t.Fatalf("expected serverity: %v, got: %v", syslog.LOG_INFO, p.Severity)
    43  	}
    44  
    45  	idx := d.logContentIndex(line)
    46  	expected := bytes.Index(line, []byte("1:C 10 Feb 18:16:43.391"))
    47  	if idx != expected {
    48  		t.Fatalf("expected idx: %v, got: %v", expected, idx)
    49  	}
    50  }