-
Notifications
You must be signed in to change notification settings - Fork 4
/
parse_test.go
101 lines (91 loc) · 1.73 KB
/
parse_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
package ccpa_test
import (
"github.com/go-check/check"
"github.com/LiveRamp/ccpa"
)
type ParseTestSuite struct{}
func (p *ParseTestSuite) TestErrorCases(c *check.C) {
var tcs = []struct {
s string
exp string
}{
{
s: "1YY",
exp: "consent string should be exactly 4 characters in length",
},
{
s: "A---",
exp: "error parsing Specification Version number: .*",
},
{
s: "1XYY",
exp: "unexpected value for Explicit Notice field",
},
{
s: "1YXY",
exp: "unexpected value for Opt-Out Sale field",
},
{
s: "1YYX",
exp: "unexpected value for LSPA field",
},
}
for _, tc := range tcs {
c.Log(tc)
var con, err = ccpa.Parse(tc.s)
c.Check(con, check.IsNil)
c.Check(err, check.ErrorMatches, tc.exp)
}
}
func (p *ParseTestSuite) TestParse(c *check.C) {
var tcs = []struct {
s string
exp *ccpa.Consent
}{
// First 3 are the example strings from the IAB spec.
// The last test is added for sanity.
{
s: "1YYN",
exp: &ccpa.Consent{
Version: 1,
Explicit: ccpa.Yes,
OptOut: ccpa.Yes,
LSPA: ccpa.No,
},
},
{
s: "1NYY",
exp: &ccpa.Consent{
Version: 1,
Explicit: ccpa.No,
OptOut: ccpa.Yes,
LSPA: ccpa.Yes,
},
},
{
s: "1---",
exp: &ccpa.Consent{
Version: 1,
Explicit: ccpa.NotApplicable,
OptOut: ccpa.NotApplicable,
LSPA: ccpa.NotApplicable,
},
},
{
s: "2YN-",
exp: &ccpa.Consent{
Version: 2,
Explicit: ccpa.Yes,
OptOut: ccpa.No,
LSPA: ccpa.NotApplicable,
},
},
}
for _, tc := range tcs {
c.Log(tc)
var con, err = ccpa.Parse(tc.s)
c.Check(err, check.IsNil)
c.Check(con, check.DeepEquals, tc.exp)
}
}
var _ = check.Suite(&ParseTestSuite{})