github.com/Axway/agent-sdk@v1.1.101/pkg/util/log/log_test.go (about) 1 package log 2 3 import ( 4 "testing" 5 6 "github.com/sirupsen/logrus" 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestGlobalLoggerConfig(t *testing.T) { 11 assert.Equal(t, STDOUT, GlobalLoggerConfig.output, "Expected default output to be STDOUT") 12 assert.Equal(t, ".", GlobalLoggerConfig.path, "Expected default path to be current directory '.'") 13 assert.Equal(t, logrus.InfoLevel, GlobalLoggerConfig.cfg.Level, "Expected default level to be info") 14 assert.IsType(t, &logrus.JSONFormatter{}, GlobalLoggerConfig.cfg.Formatter, "Expected default formatter to be of JSON type") 15 } 16 17 func TestLoggerConfig(t *testing.T) { 18 lc := LoggerConfig{} 19 20 // Level 21 err := lc.Level("debug1").Apply() 22 assert.NotNil(t, err, "Expected an error for an invalid level type") 23 lc.err = nil 24 25 err = lc.Level("debug").Apply() 26 assert.Nil(t, err, "Did not expect an error") 27 lc.err = nil 28 29 // Format 30 err = lc.Format("fake").Apply() 31 assert.NotNil(t, err, "Expected an error for an invalid format type") 32 lc.err = nil 33 34 err = lc.Format("line").Apply() 35 assert.Nil(t, err, "Did not expect an error") 36 lc.err = nil 37 38 err = lc.Format("json").Apply() 39 assert.Nil(t, err, "Did not expect an error") 40 lc.err = nil 41 42 // Output 43 err = lc.Output("fake").Apply() 44 assert.NotNil(t, err, "Expected an error for an invalid output type") 45 lc.err = nil 46 47 err = lc.Output("Both").Apply() 48 assert.Nil(t, err, "Did not expect an error") 49 lc.err = nil 50 51 // Filename 52 err = lc.Filename("test").Apply() 53 assert.Nil(t, err, "Did not expect an error") 54 lc.err = nil 55 56 // Path 57 err = lc.Path("test").Apply() 58 assert.Nil(t, err, "Did not expect an error") 59 lc.err = nil 60 61 // MaxSize 62 err = lc.MaxSize(0).Apply() 63 assert.NotNil(t, err, "Expected an error for an invalid max size value") 64 lc.err = nil 65 66 err = lc.MaxSize(1048576).Apply() 67 assert.Nil(t, err, "Did not expect an error") 68 lc.err = nil 69 70 // MaxBackups 71 err = lc.MaxBackups(-100).Apply() 72 assert.NotNil(t, err, "Expected an error for an invalid max backups value") 73 lc.err = nil 74 75 err = lc.MaxBackups(100).Apply() 76 assert.Nil(t, err, "Did not expect an error") 77 lc.err = nil 78 79 // MaxAge 80 err = lc.MaxAge(-100).Apply() 81 assert.NotNil(t, err, "Expected an error for an invalid max age value") 82 lc.err = nil 83 84 err = lc.MaxAge(100).Apply() 85 assert.Nil(t, err, "Did not expect an error") 86 lc.err = nil 87 }