-
Notifications
You must be signed in to change notification settings - Fork 27
/
extension_test.go
79 lines (65 loc) · 2.26 KB
/
extension_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
package vast
import (
"encoding/xml"
"testing"
"github.com/stretchr/testify/assert"
)
var (
extensionCustomTracking = []byte(`<Extension type="testCustomTracking"><CustomTracking><Tracking event="event.1"><![CDATA[http://event.1]]></Tracking><Tracking event="event.2"><![CDATA[http://event.2]]></Tracking></CustomTracking></Extension>`)
extensionData = []byte(`<Extension type="testCustomTracking"><SkippableAdType>Generic</SkippableAdType></Extension>`)
)
func TestExtensionCustomTrackingMarshal(t *testing.T) {
e := Extension{
Type: "testCustomTracking",
CustomTracking: []Tracking{
{
Event: "event.1",
URI: "http://event.1",
},
{
Event: "event.2",
URI: "http://event.2",
},
},
}
// marshal the extension
xmlExtensionOutput, err := xml.Marshal(e)
assert.NoError(t, err)
// assert the resulting marshaled extension
assert.Equal(t, string(extensionCustomTracking), string(xmlExtensionOutput))
}
func TestExtensionCustomTracking(t *testing.T) {
// unmarshal the Extension
var e Extension
assert.NoError(t, xml.Unmarshal(extensionCustomTracking, &e))
// assert the resulting extension
assert.Equal(t, "testCustomTracking", e.Type)
assert.Empty(t, string(e.Data))
if assert.Len(t, e.CustomTracking, 2) {
// first event
assert.Equal(t, "event.1", e.CustomTracking[0].Event)
assert.Equal(t, "http://event.1", e.CustomTracking[0].URI)
// second event
assert.Equal(t, "event.2", e.CustomTracking[1].Event)
assert.Equal(t, "http://event.2", e.CustomTracking[1].URI)
}
// marshal the extension
xmlExtensionOutput, err := xml.Marshal(e)
assert.NoError(t, err)
// assert the resulting marshaled extension
assert.Equal(t, string(extensionCustomTracking), string(xmlExtensionOutput))
}
func TestExtensionGeneric(t *testing.T) {
// unmarshal the Extension
var e Extension
assert.NoError(t, xml.Unmarshal(extensionData, &e))
// assert the resulting extension
assert.Equal(t, "testCustomTracking", e.Type)
assert.Equal(t, "<SkippableAdType>Generic</SkippableAdType>", string(e.Data))
assert.Empty(t, e.CustomTracking)
// marshal the extension
xmlExtensionOutput, err := xml.Marshal(e)
assert.NoError(t, err)
// assert the resulting marshaled extension
assert.Equal(t, string(extensionData), string(xmlExtensionOutput))
}