forked from ctrlrsf/logdna
-
Notifications
You must be signed in to change notification settings - Fork 1
/
logdna_test.go
61 lines (49 loc) · 1.17 KB
/
logdna_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package logdna
import (
"encoding/json"
"testing"
"time"
)
var testConfig = Config{
APIKey: "secret",
LogFile: "test1.log",
Hostname: "testhost.com",
}
func TestPayloadJSONMarshaling(t *testing.T) {
logLine1 := logLineJSON{
Timestamp: 1469047048,
Line: "Test line 1",
File: "test.log",
}
logLine2 := logLineJSON{
Timestamp: 1469146012,
Line: "Test line 2",
File: "test.log",
}
logLines := []logLineJSON{logLine1, logLine2}
payload := payloadJSON{
Lines: logLines,
}
t.Logf("PayloadJSON value: %+v", payload)
jsonPayload, err := json.Marshal(payload)
if err != nil {
t.Fatalf("unable marshal payload to JSON: %v", err)
}
t.Logf("PayloadJSON as JSON string: %s", jsonPayload)
}
func TestClient_Log(t *testing.T) {
client := NewClient(testConfig)
logMsg := "Test log message"
client.Log(time.Time{}, logMsg)
if client.payload.Lines[0].Line != logMsg {
t.Fatalf("did not add expected log line")
}
}
func TestClient_Size(t *testing.T) {
client := NewClient(testConfig)
logMsg := "Test log message"
client.Log(time.Time{}, logMsg)
if client.Size() != 1 {
t.Fatalf("size is wrong: expected 1 got %d", client.Size())
}
}