mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-28 06:29:59 +00:00
TUN-813: Clean up cloudflared dependencies
This commit is contained in:
49
vendor/github.com/rifflock/lfshook/lfshook_test.go
generated
vendored
49
vendor/github.com/rifflock/lfshook/lfshook_test.go
generated
vendored
@@ -1,49 +0,0 @@
|
||||
package lfshook
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/sirupsen/logrus"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const expectedMsg = "This is the expected test message."
|
||||
const unexpectedMsg = "This message should not be logged."
|
||||
|
||||
// Tests that writing to a tempfile log works.
|
||||
// Matches the 'msg' of the output and deletes the tempfile.
|
||||
func TestLogEntryWritten(t *testing.T) {
|
||||
log := logrus.New()
|
||||
// The colors were messing with the regexp so I turned them off.
|
||||
tmpfile, err := ioutil.TempFile("", "test_lfshook")
|
||||
if err != nil {
|
||||
t.Errorf("Unable to generate logfile due to err: %s", err)
|
||||
}
|
||||
fname := tmpfile.Name()
|
||||
defer func() {
|
||||
tmpfile.Close()
|
||||
os.Remove(fname)
|
||||
}()
|
||||
hook := NewHook(PathMap{
|
||||
logrus.InfoLevel: fname,
|
||||
}, nil)
|
||||
log.Hooks.Add(hook)
|
||||
|
||||
log.Info(expectedMsg)
|
||||
log.Warn(unexpectedMsg)
|
||||
|
||||
contents, err := ioutil.ReadAll(tmpfile)
|
||||
if err != nil {
|
||||
t.Errorf("Error while reading from tmpfile: %s", err)
|
||||
}
|
||||
|
||||
if !bytes.Contains(contents, []byte("msg=\""+expectedMsg+"\"")) {
|
||||
t.Errorf("Message read (%s) doesnt match message written (%s) for file: %s", contents, expectedMsg, fname)
|
||||
}
|
||||
|
||||
if bytes.Contains(contents, []byte("msg=\""+unexpectedMsg+"\"")) {
|
||||
t.Errorf("Message read (%s) contains message written (%s) for file: %s", contents, unexpectedMsg, fname)
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user