-
Notifications
You must be signed in to change notification settings - Fork 1
/
vast_integration_test.go
137 lines (113 loc) · 2.87 KB
/
vast_integration_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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package vast_test
import (
"aqwari.net/xml/xmltree"
"bytes"
"errors"
"github.com/google/go-cmp/cmp"
"go.eigsys.de/go-vast"
"io"
"log"
"os"
"path"
"testing"
)
func TestNumericBool_MarshalText_false(t *testing.T) {
var numericBool vast.NumericBool
result, err := numericBool.MarshalText()
if err != nil {
t.Error("unexpected error")
}
if !bytes.Equal(result, []byte("0")) {
t.Error("unexpected result")
}
}
func TestNumericBool_MarshalText_true(t *testing.T) {
numericBool := vast.NumericBool(true)
result, err := numericBool.MarshalText()
if err != nil {
t.Error("unexpected error")
}
if !bytes.Equal(result, []byte("1")) {
t.Error("unexpected result")
}
}
func mustOpenFixture(fixture string) io.ReadCloser {
handle, err := os.Open(path.Join("testdata", fixture))
if err != nil {
log.Fatalf("%v", err)
}
return handle
}
func TestNew(t *testing.T) {
testVAST := vast.New()
wantVAST := &vast.VAST{
Version: "4.2",
XMLNS: "http://www.iab.com/VAST",
}
if diff := cmp.Diff(testVAST, wantVAST); diff != "" {
t.Errorf("wrong VAST: %s", diff)
}
}
type NopReadCloser struct{}
func (r NopReadCloser) Read(_ []byte) (n int, err error) {
return 0, errors.New("error")
}
func (r NopReadCloser) Close() error {
return nil
}
func TestRead_ErrReadVAST(t *testing.T) {
reader := NopReadCloser{}
if _, err := vast.Read(reader); !errors.Is(err, vast.ErrReadVAST) {
t.Error("unexpected error")
}
}
func TestRoundTrip(t *testing.T) {
testCases := []string{
"iab/Ad_Verification-test.xml",
"iab/Category-test.xml",
"iab/Closed_Caption_Test.xml",
"iab/Event_Tracking-test.xml",
"iab/IconClickFallbacks.xml",
"iab/Inline_Companion_Tag-test.xml",
"iab/Inline_Linear_Tag-test.xml",
"iab/Inline_Non-Linear_Tag-test.xml",
"iab/Inline_Simple.xml",
"iab/No_Wrapper_Tag-test.xml",
"iab/Ready_to_serve_Media_Files_check-test.xml",
"iab/Universal_Ad_ID-multi-test.xml",
"iab/Video_Clicks_and_click_tracking-Inline-test.xml",
"iab/Viewable_Impression-test.xml",
"iab/Wrapper_Tag-test.xml",
}
for _, testCase := range testCases {
t.Run(testCase, func(t *testing.T) {
reader := mustOpenFixture(testCase)
testVAST, err := vast.Read(reader)
if err != nil {
t.Error("unexpected error")
}
output, err := testVAST.Bytes()
if err != nil {
t.Error("unexpected error")
}
outputDoc, err := xmltree.Parse(output)
if err != nil {
t.Error("unexpected error")
}
input, err := io.ReadAll(mustOpenFixture(testCase))
if err != nil {
t.Error("unexpected error")
}
inputDoc, err := xmltree.Parse(input)
if err != nil {
t.Error("unexpected error")
}
if !xmltree.Equal(inputDoc, outputDoc) {
inputStr := xmltree.MarshalIndent(inputDoc, "", " ")
outputStr := xmltree.MarshalIndent(outputDoc, "", " ")
diff := cmp.Diff(inputStr, outputStr)
t.Errorf("wrong VAST: %s", diff)
}
})
}
}