-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser_test.go
84 lines (72 loc) · 2.29 KB
/
parser_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
81
82
83
84
package usage_parser
import (
"net"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestUsageParser(t *testing.T) {
t.Run("Parse", func(t *testing.T) {
t.Run("Given a single string", func(t *testing.T) {
t.Run("Given an ID that does not end with 4 or 6", func(t *testing.T) {
var input []string = []string{
"7291,293451",
}
var expected []*UsageResult = []*UsageResult{
NewBasicUsage(7291, 293451),
}
t.Run("Then it will return basic string data", func(t *testing.T) {
result := NewParser().Parse(input)
if diff := cmp.Diff(expected, result); diff != "" {
t.Errorf("-expected +received:\n%s", diff)
}
})
})
t.Run("Given an ID that ends with 4", func(t *testing.T) {
var input []string = []string{
"7194,b33,394,495593,192",
}
var expected []*UsageResult = []*UsageResult{
NewExtendedUsage(7194, 495593, 192, "b33", 394),
}
t.Run("Then it will return extended string data", func(t *testing.T) {
result := NewParser().Parse(input)
if diff := cmp.Diff(expected, result); diff != "" {
t.Errorf("-expected +received:\n%s", diff)
}
})
})
t.Run("Given an ID that ends with 6", func(t *testing.T) {
var input []string = []string{
"316,0e893279227712cac0014aff",
}
var expected []*UsageResult = []*UsageResult{
NewHexUsage(316, 12921, 578228938, net.ParseIP("192.1.74.255"), 3721),
}
t.Run("Then it will return hex string data", func(t *testing.T) {
result := NewParser().Parse(input)
if diff := cmp.Diff(expected, result); diff != "" {
t.Errorf("-expected +received:\n%s", diff)
}
})
})
})
t.Run("Given an array of strings", func(t *testing.T) {
var input []string = []string{
"4,0d39f,0,495594,214",
"16,be833279000000c063e5e63d",
"9991,2935",
}
var expected []*UsageResult = []*UsageResult{
NewExtendedUsage(4, 495594, 214, "0d39f", 0),
NewHexUsage(16, 12921, 192, net.ParseIP("99.229.230.61"), 48771),
NewBasicUsage(9991, 2935),
}
t.Run("Then it will parse each string according to its ID and return an array of data", func(t *testing.T) {
result := NewParser().Parse(input)
if diff := cmp.Diff(expected, result); diff != "" {
t.Errorf("-expected +received:\n%s", diff)
}
})
})
})
}