-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathzap_appinsights_test.go
More file actions
47 lines (41 loc) · 1.44 KB
/
Copy pathzap_appinsights_test.go
File metadata and controls
47 lines (41 loc) · 1.44 KB
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
package zapappinsigths
import (
"encoding/json"
"testing"
"github.com/Microsoft/ApplicationInsights-Go/appinsights"
"github.com/Microsoft/ApplicationInsights-Go/appinsights/contracts"
)
func TestWriteIntegration(t *testing.T) {
appInsightsConfig := AppInsightsConfig{
client: appinsights.NewTelemetryClient("00000000-0000-0000-0000-000000000000"),
filters: make(map[string]func(interface{}) interface{}),
}
message := "hello world"
msg := "{\"source\": \"test\", \"msg\": \"" + message + "\", \"level\":\"Information\"}"
n, err := appInsightsConfig.Write([]byte(msg))
if n != len(message) {
t.Errorf("Expected for n value %v but got value %v", len(msg), n)
}
if err != nil {
t.Errorf("Expected no error but got %v", err)
}
}
func TestBuildTrace(t *testing.T) {
message := "hello world"
level := contracts.Information
source := "test"
msg := "{\"source\": \"" + source + "\", \"msg\": \"" + message + "\", \"level\":\"" + level.String() + "\"}"
msgbyte := []byte(msg)
var data map[string]interface{}
json.Unmarshal(msgbyte, &data)
trace := BuildTrace(data)
if trace.Message != message {
t.Errorf("Expected for value %v but got value %v", message, trace.Message)
}
if trace.SeverityLevel != level {
t.Errorf("Expected for value %v but got value %v", level, trace.SeverityLevel)
}
if trace.BaseTelemetry.Properties["source"] != source {
t.Errorf("Expected for value %v but got value %v", source, trace.Properties["source"])
}
}