Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
fffw committed Mar 10, 2015
1 parent 7b9109c commit db56c8c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/github.com/getlantern/flashlight/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (w logglyErrorWriter) Write(b []byte) (int, error) {
}
fullMessage := string(b)
message := fullMessage
// Loggly can't index fields with more than 100 characters
// Loggly doesn't group fields with more than 100 characters
if len(fullMessage) > 100 {
message = fullMessage[0:100]
}
Expand Down
36 changes: 36 additions & 0 deletions src/github.com/getlantern/flashlight/logging/logging_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package logging

import (
"bytes"
"encoding/json"
"strings"
"testing"

"github.com/getlantern/go-loggly"
"github.com/getlantern/golog"
"github.com/getlantern/testify/assert"
)

func TestLoggly(t *testing.T) {
var buf bytes.Buffer
var result map[string]interface{}
loggly := loggly.New("token not required")
loggly.Writer = &buf
lw := logglyErrorWriter{client: loggly}
golog.SetOutputs(lw, nil)
log := golog.LoggerFor("test")

log.Error("short message")
if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
assert.Equal(t, "test", result["locationInfo"])
assert.Equal(t, "test: short message\n", result["message"])
}

buf.Reset()
longMsg := "really l" + strings.Repeat("o", 100) + "ng message"
log.Error(longMsg)
if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
assert.Equal(t, "test", result["locationInfo"])
assert.Equal(t, ("test: " + longMsg)[0:100], result["message"], "message should be truncated to 100 characters")
}
}

0 comments on commit db56c8c

Please sign in to comment.