-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvast2_test.go
78 lines (73 loc) · 1.76 KB
/
vast2_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
package vast
import (
"bytes"
"encoding/xml"
"os"
"testing"
)
func testXML(t *testing.T, fn string, v interface{}) {
b, err := os.ReadFile(fn)
if err != nil {
t.Fatal("os.ReadFile:", err)
}
if err = xml.Unmarshal(b, v); err != nil {
t.Fatal("xml.Unmarshal:", err)
}
marshaled, err := xml.MarshalIndent(v, "", " ")
if err != nil {
t.Fatal("xml.MarshalIndent:", err)
}
expected := fn[:len(fn)-4] + "-marshaled.xml"
if b, err = os.ReadFile(expected); err != nil {
t.Fatal("os.ReadFile:", err)
}
if bytes.Compare(marshaled, b) != 0 {
t.Fatal("Unexpected marshel output:", fn)
}
}
func testVAST2File(t *testing.T, fn string) {
var v VAST2
testXML(t, fn, &v)
}
func TestVAST2(t *testing.T) {
for _, fn := range []string{
"v2test/empty.xml",
"v2test/hivestack.xml",
"v2test/cf.xml",
"v2test/Inline_LinearRegular_VAST2.0.xml",
"v2test/Inline_LinearVAST2vpaid.xml",
"v2test/Inline_NonLinear_VAST2.0.xml",
"v2test/Inline_NonLinear_Verification_VAST2.0.xml",
} {
t.Log("Testing ", fn)
testVAST2File(t, fn)
}
}
func TestEmpty(t *testing.T) {
var v2 VAST2
v2.Version = "2.0"
marshaled, err := xml.MarshalIndent(v2, "", " ")
if err != nil {
t.Fatal("xml.MarshalIndent:", err)
}
fn := "v2test/empty-marshaled.xml"
b, err := os.ReadFile(fn)
if err != nil {
t.Fatal("os.ReadFile:", err)
}
if bytes.Compare(marshaled, b) != 0 {
t.Fatal("Unexpected marshel output:", string(marshaled))
}
var v3 VAST3
v3.Version = "3.0"
if marshaled, err = xml.MarshalIndent(v3, "", " "); err != nil {
t.Fatal("xml.MarshalIndent:", err)
}
fn = "v3test/empty-marshaled.xml"
if b, err = os.ReadFile(fn); err != nil {
t.Fatal("os.ReadFile:", err)
}
if bytes.Compare(marshaled, b) != 0 {
t.Fatal("Unexpected marshel output:", string(marshaled))
}
}