github.com/smithx10/nomad@v0.9.1-rc1/client/logmon/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  	"testing"
     8  
     9  	syslog "github.com/RackSec/srslog"
    10  	"github.com/hashicorp/nomad/helper/testlog"
    11  )
    12  
    13  func TestLogParser_Priority(t *testing.T) {
    14  	t.Parallel()
    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(testlog.HCLogger(t))
    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 severity: %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  	t.Parallel()
    34  	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")
    35  	d := NewDockerLogParser(testlog.HCLogger(t))
    36  	p, _, err := d.parsePriority(line)
    37  	if err != nil {
    38  		t.Fatalf("got an err: %v", err)
    39  	}
    40  	if p.Severity != syslog.LOG_INFO {
    41  		t.Fatalf("expected severity: %v, got: %v", syslog.LOG_INFO, p.Severity)
    42  	}
    43  
    44  	idx := d.logContentIndex(line)
    45  	expected := bytes.Index(line, []byte("1:C 10 Feb 18:16:43.391"))
    46  	if idx != expected {
    47  		t.Fatalf("expected idx: %v, got: %v", expected, idx)
    48  	}
    49  }