-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_xml_test.go
90 lines (85 loc) · 2.86 KB
/
parse_xml_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
85
86
87
88
89
90
package main
import (
"fmt"
"os"
"strings"
"testing"
)
const (
xml01 string = `<?xml version="1.0" encoding="utf-8"?>
<resources date="2020-09-03 06:32:22">
<resource id="1">
<ip>10.1.1.1</ip>
<dns>example.tld</dns>
<url>http://www.example.tld</url>
<dateoff>2011-01-01</dateoff>
<info>Тест 1</info>
</resource>
<resource id="2">
<ip>-</ip>
<dns>-</dns>
<url>http://test.tld</url>
<dateoff>2018-04-16</dateoff>
<info>Тест 2</info>
</resource>
<resource id="3">
<ip>10.3.3.3</ip>
<dns>testik.tld</dns>
<url>-</url>
<dateoff>2020-07-16</dateoff>
<info>Тест 3</info>
</resource>
</resources>`
xml02 string = `<?xml version="1.0" encoding="utf-8"?>
<resources date="2020-09-03 12:32:22">
<resource id="1">
<ip>10.1.1.1</ip>
<dns>example.tld</dns>
<url>http://www.example.tld</url>
<dateoff>2011-01-01</dateoff>
<info>Тест 1</info>
</resource>
<resource id="3">
<ip>-</ip>
<dns>testik.tld</dns>
<url>-</url>
<dateoff>2020-07-16</dateoff>
<info>Тест 3</info>
</resource>
</resources>`
)
func Test_Parse(t *testing.T) {
logInit(os.Stderr, os.Stdout, os.Stderr, os.Stderr)
dumpFile := strings.NewReader(xml01)
err := Parse(dumpFile)
if err != nil {
t.Errorf(err.Error())
}
if Stats.MaxArrayIntSet != 1 ||
Stats.Cnt != 3 ||
Stats.CntAdd != 3 ||
Stats.CntUpdate != 0 ||
Stats.CntRemove != 0 {
t.Errorf("Stat error")
}
if len(DumpSnap.ip) != 2 ||
len(DumpSnap.url) != 2 ||
len(DumpSnap.domain) != 2 {
t.Errorf("Count error")
}
if len(DumpSnap.Content) != 3 ||
len(DumpSnap.Content) != Stats.Cnt {
t.Errorf("DumpSnap integrity error")
}
fmt.Println()
dumpFile = strings.NewReader(xml02)
err = Parse(dumpFile)
if err != nil {
t.Errorf(err.Error())
}
fmt.Printf("IP4:\n%v\n", DumpSnap.ip)
for k := range DumpSnap.Content {
fmt.Printf("%d ", k)
}
fmt.Println()
}