-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimporter_test.go
80 lines (62 loc) · 1.83 KB
/
importer_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package appmetrica
import (
"bytes"
"strings"
"testing"
"time"
)
func TestImporter(t *testing.T) {
t.Run("Common", func(t *testing.T) {
imp := NewEventImporter(DeviceID, "mcc", "mnc", "unexisted-col")
if length := len(imp.header); length != 2 {
t.Errorf("too many header elements: %d", length)
}
imp.Reset()
if length := len(imp.buffer); length != 0 {
t.Errorf("buffer wasn't reset: %d", length)
}
if length := len(imp.events); length != 0 {
t.Errorf("events cache wasn't reset: %d", length)
}
})
t.Run("Read", func(t *testing.T) {
const expectedHeader = `appmetrica_device_id,application_id,event_name,event_timestamp,mcc,mnc`
imp := NewEventImporter(DeviceID, "mcc", "mnc")
imp.Import(&ImportEvent{
ApplicationID: 84126,
DeviceID: 998,
EventName: "SSETestEvent",
EventTimestamp: time.Now().UTC().Unix(),
MCC: 250,
MNC: 25000,
})
buffer := new(bytes.Buffer)
buffer.ReadFrom(imp)
// Check final state of event importer.
if imp.state != EndOfEvents {
t.Errorf("wrong state of importer: %+v", imp.state)
}
// Check assertion on read content.
lines := strings.Split(string(buffer.Bytes()), "\n")
if length := len(lines); length != 3 && lines[3] == "" {
t.Fatalf("wrong number of lines were read: %d", length)
}
if lines[0] != expectedHeader {
t.Errorf("wrong header: `%s`", lines[0])
}
// Some assertions on record values in columns.
columns := strings.Split(lines[1], ",")
if length := len(columns); length != 6 {
t.Fatalf("worng number of columns in line: %d", length)
}
if columns[0] != "998" {
t.Errorf("wrong device id: %s", columns[0])
}
if columns[2] != "SSETestEvent" {
t.Errorf("wrong event name: %s", columns[2])
}
if columns[5] != "25000" {
t.Errorf("wrong mnc value: %s", columns[5])
}
})
}