-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser_test.go
More file actions
85 lines (79 loc) · 2.02 KB
/
Copy pathparser_test.go
File metadata and controls
85 lines (79 loc) · 2.02 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
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
81
82
83
84
85
package smdr
import (
"reflect"
"testing"
)
// Failed parse result test
func TestParserFailed(t *testing.T) {
b := []byte{22, 49, 48, 48, 48, 48}
p := New()
err := p.Parser(b)
if err != nil && err.Error() != `can't parse responded data` {
t.Errorf("can't parse responded data: %#v", err)
}
b = []byte{22, 49, 48, 48, 48, 48, 50, 48, 48, 1, 1, 252, 12}
p = New()
err = p.Parser(b)
if err != nil && err.Error() != `can't parse responded call data` {
t.Errorf("can't parse responded data: %#v", err)
}
}
// Parse result test
func TestParser(t *testing.T) {
//some test data
b := []byte{22, 49, 48, 48, 48, 48, 50, 48, 48, 1,
1, 252, 1, 2, 55, 55, 55, 65, 55, 55,
50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
53, 53, 53, 53, 53, 53, 53, 53, 53, 53,
54, 54, 54, 54, 54, 54, 54, 54, 54, 54,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 47, 47, 47, 47, 47, 47,
59, 59, 59, 59, 59, 59, 59, 59, 59, 59,
51, 60, 60, 60, 60, 60, 49, 48, 54, 53,
52, 59, 59, 59, 59, 59, 59, 59, 59, 59,
53, 60, 60, 55, 57, 48, 57, 53, 49, 57,
52, 55, 53, 54, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32}
p := New()
_ = p.Parser(b)
testData := &CDR{
Length: "00002",
Sequence: 0,
Tp: "7",
TrunkOut: "77A",
TrunkInc: "772",
Id: "2",
Tenant: "22",
Called: "222222",
CvsStart: Conversation{
Year: "10",
Month: "33",
Day: "33",
Hour: "33",
Minute: "33",
Second: "33",
},
CvsEnd: Conversation{
Year: "65",
Month: "44",
Day: "44",
Hour: "44",
Minute: "44",
Second: "44",
},
TenantTwo: "666",
Condition: "666",
Route1: "666",
Route2: "6 ",
Phone: "79095194756 ",
CallMetering: "////",
}
if !reflect.DeepEqual(testData, p) {
t.Error("Expected data, got", p)
}
}