-
Notifications
You must be signed in to change notification settings - Fork 0
/
serial_test.go
39 lines (33 loc) · 4.28 KB
/
serial_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
package psxserialnumber
import (
"testing"
)
func TestFindSerial(t *testing.T) {
value := []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 244, 36, 3, 255, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 5, 0, 245, 0, 0, 0, 0, 239, 0, 245, 0, 0, 247, 0, 0, 0, 30, 60, 0, 245, 120, 126, 243, 0, 0, 0, 0, 26, 0, 245, 120, 126, 147, 126, 6, 0, 0, 0, 0, 16, 0, 2, 96, 131, 126, 116, 141, 0, 2, 0, 0, 0, 0, 231, 0, 2, 98, 96, 151, 0, 6, 0, 0, 0, 0, 229, 0, 2, 98, 147, 126, 122, 140, 108, 5, 28, 0, 0, 0, 0, 0, 0, 140, 0, 0, 0, 140, 0, 244, 0, 0, 0, 0, 249, 0, 244, 0, 0, 245, 0, 0, 0, 15, 30, 0, 244, 60, 63, 247, 0, 0, 0, 0, 13, 0, 244, 60, 63, 199, 63, 3, 0, 0, 0, 0, 8, 0, 1, 48, 207, 63, 58, 200, 0, 1, 0, 0, 0, 0, 253, 0, 1, 49, 48, 197, 0, 3, 0, 0, 0, 0, 252, 0, 1, 49, 199, 63, 61, 61, 72, 6, 227, 19, 66, 0, 239, 203, 193, 119, 187, 122, 198, 216, 74, 30, 11, 5, 3, 99, 251, 63, 184, 39, 51, 37, 9, 63, 76, 238, 73, 69, 64, 185, 8, 0, 109, 247, 159, 155, 43, 53, 108, 93, 245, 42, 75, 242, 0, 66, 40, 250, 178, 1, 246, 67, 31, 0, 228, 205, 217, 231, 197, 192, 135, 176, 193, 90, 164, 6, 240, 97, 212, 58, 73, 92, 203, 103, 46, 64, 209, 91, 219, 176, 191, 189, 228, 148, 118, 85, 7, 13, 15, 151, 218, 208, 11, 164, 81, 242, 0, 126, 92, 224, 11, 112, 117, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 2, 34, 2, 0, 0, 137, 0, 0, 0, 137, 0, 48, 0, 22, 0, 0, 0, 0, 0, 0, 22, 0, 8, 0, 0, 0, 0, 8, 0, 2, 8, 1, 19, 5, 0, 0, 2, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 141, 85, 88, 65, 0, 0, 0, 0, 0, 0, 48, 0, 22, 0, 0, 0, 0, 0, 0, 22, 0, 8, 0, 0, 0, 0, 8, 0, 2, 8, 1, 19, 5, 0, 0, 2, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 141, 85, 88, 65, 0, 0, 0, 0, 0, 0, 50, 0, 34, 17, 0, 0, 0, 0, 17, 34, 0, 8, 0, 0, 0, 0, 8, 0, 2, 8, 1, 19, 5, 0, 0, 2, 0, 0, 1, 0, 0, 1, 2, 68, 65, 0, 0, 0, 0, 0, 141, 85, 88, 65, 0, 0, 0, 0, 0, 0, 52, 0, 23, 0, 0, 0, 0, 0, 0, 23, 0, 8, 0, 0, 0, 0, 8, 0, 2, 8, 1, 19, 5, 0, 0, 2, 0, 0, 1, 0, 0, 1, 4, 68, 65, 84, 65, 0, 0, 0, 0, 0, 141, 85, 88, 65, 0, 0, 0, 0, 0, 0, 58, 0, 165, 6, 0, 0, 0, 0, 6, 165, 0, 64, 71, 0, 0, 71, 64, 0, 102, 6, 14, 20, 30, 2, 36, 0, 0, 0, 1, 0, 0, 1, 10, 76, 79, 71, 79, 46, 83, 84, 82, 59, 49, 0, 0, 0, 0, 0, 61, 85, 88, 65, 1, 0, 0, 0, 0, 0, 60, 0, 142, 15, 0, 0, 0, 0, 15, 142, 0, 160, 12, 0, 0, 12, 160, 0, 102, 8, 1, 19, 3, 34, 36, 0, 0, 0, 1, 0, 0, 1, 13, 83, 76, 85, 83, 95, 48, 49, 52, 46, 55, 48, 59, 49, 0, 0, 0, 0, 13, 85, 88, 65, 0, 0, 0, 0, 0, 0, 60, 0, 141, 15, 0, 0, 0, 0, 15, 141, 68, 0, 0, 0, 0, 0, 0, 68, 102, 7, 25, 18, 17, 44, 36, 0, 0, 0, 1, 0, 0, 1, 12, 83, 89, 83, 84, 69, 77, 46, 67, 78, 70, 59, 49, 0, 0, 0, 0, 0, 13, 85, 88, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
want := "SLUS_014.70"
serial := findSerial(string(value))
if serial != want {
t.Errorf("Serial is incorrect, got: %s, want: %s.", serial, want)
}
}
func TestNormalizeSerial(t *testing.T) {
testCases := map[string]string{
"LSP_9071.27": "907127",
"LSP_0101.50": "LSP-010150-",
"LSP_9031.74": "LSP90317401",
"SCUS_941.02": "SCUS-94102",
"SCUS_941.56": "SCUS_94156",
"SCUS_943.00": "SCUS-943.00",
"SCUS_941.03": "SCUS_941.03",
"SLUS_014.44": "SLUS-014.44",
"SLUS_012.06": "SLUSP012.06",
"SLUS_002.20": "SLUS_00.220",
"SLUS_000.17": "SLUS_000176",
}
for expected, value := range testCases {
normalized := normalizeSerial(value)
if normalized != expected {
t.Errorf("Serial is incorrect, got: %s, want: %s.", normalized, expected)
}
}
}