loginsrv

Unnamed repository; edit this file 'description' to name the repository.
git clone git@jamesshield.xyz:repos/loginsrv.git
Log | Files | Refs | README | LICENSE

commit b3c9c9352e1ab823e9cd9456c7f7a474634aa528
parent 8c99657f77f73d2d5b784e673eb4cd6694e3664f
Author: magikstm <myskina@gmail.com>
Date:   Fri, 10 Nov 2017 00:25:35 -0500

add comments, minor correction and a test case

Diffstat:
Mcaddy/handler_test.go | 2++
Mlogging/logger_test.go | 25++++++++++++++++++++++++-
Mlogging/logstash_formatter.go | 2+-
3 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/caddy/handler_test.go b/caddy/handler_test.go @@ -11,6 +11,7 @@ import ( "time" ) +//Tests a page while being logged in as a user (doesn't test that the {user} replacer changes) func Test_ServeHTTP_200(t *testing.T) { //Set the ServeHTTP *http.Request r, err := http.NewRequest("GET", "/", nil) @@ -70,6 +71,7 @@ func Test_ServeHTTP_200(t *testing.T) { } } +//Tests the login page without being logged as a user (doesn't test that the {user} replacer stays as-is) func Test_ServeHTTP_login(t *testing.T) { //Set the ServeHTTP *http.Request r, err := http.NewRequest("GET", "/login", nil) diff --git a/logging/logger_test.go b/logging/logger_test.go @@ -244,7 +244,7 @@ func Test_Logger_LifecycleStart(t *testing.T) { a.Equal("b666", data["build_number"]) } -func Test_Logger_LifecycleStop(t *testing.T) { +func Test_Logger_LifecycleStop_ByInterrupt(t *testing.T) { a := assert.New(t) // given a logger @@ -267,6 +267,29 @@ func Test_Logger_LifecycleStop(t *testing.T) { a.Equal("b666", data["build_number"]) } +func Test_Logger_LifecycleStop_ByError(t *testing.T) { + a := assert.New(t) + + // given a logger + b := bytes.NewBuffer(nil) + Logger.Out = b + + // and an Environment Variable with the Build Number is set + os.Setenv("BUILD_NUMBER", "b666") + + // when a LifecycleStart is logged + LifecycleStop("my-app", nil, errors.New("error")) + + // then: it is logged + data := mapFromBuffer(b) + a.Equal("error", data["level"]) + a.Equal("stopping application: my-app (error)", data["message"]) + a.Equal("lifecycle", data["type"]) + a.Equal("stop", data["event"]) + a.Equal(nil, data["signal"]) + a.Equal("b666", data["build_number"]) +} + func Test_Logger_ServerClosed(t *testing.T) { a := assert.New(t) diff --git a/logging/logstash_formatter.go b/logging/logstash_formatter.go @@ -28,7 +28,7 @@ func (f *LogstashFormatter) Format(entry *logrus.Entry) ([]byte, error) { func (f *LogstashFormatter) FormatWithPrefix(entry *logrus.Entry, prefix string) ([]byte, error) { fields := make(logrus.Fields) for k, v := range entry.Data { - //remvove the prefix when sending the fields to logstash + //remove the prefix when sending the fields to logstash if prefix != "" && strings.HasPrefix(k, prefix) { k = strings.TrimPrefix(k, prefix) }