Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GVL parser tests to ensure GVL spec v3 support #36

Merged
merged 1 commit into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 54 additions & 23 deletions vendorlist2/eager-parsing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,64 @@ package vendorlist2
import (
"testing"

"github.com/prebid/go-gdpr/api"
"github.com/stretchr/testify/assert"
)

func TestEagerlyParsedVendorList(t *testing.T) {
AssertVendorlistCorrectness(t, func(data []byte) api.VendorList {
vendorList, err := ParseEagerly(data)
if err != nil {
t.Errorf("ParseEagerly returned an unexpected error: %v", err)
}
return vendorList
})
}
func TestParseEagerlyVendorList(t *testing.T) {
tests := []struct{
name string
vendorList string
vendorListVersion uint16
}{
{
name: "vendor list spec 2",
vendorList: testDataSpecVersion2,
vendorListVersion: 28,
},
{
name: "vendor list spec 3",
vendorList: testDataSpecVersion3,
vendorListVersion: 1,
},
}

func TestParseEagerlyVendorsEmpty(t *testing.T) {
vendorListJSON := `
{
"gvlSpecificationVersion": 2,
"vendorListVersion": 28,
"tcfPolicyVersion": 2,
"lastUpdated": "2020-03-05T16:05:29Z",
"vendors": { }
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
parsedGVL, err := ParseEagerly([]byte(tt.vendorList))
assert.NoError(t, err)
assert.Equal(t, tt.vendorListVersion, parsedGVL.Version())
assert.NotNil(t, parsedGVL.Vendor(8))
assert.NotNil(t, parsedGVL.Vendor(80))
AssertVendorListCorrectness(t, parsedGVL)
})
}
}
`
vendorList, err := ParseEagerly([]byte(vendorListJSON))

assert.NoError(t, err)
assert.Equal(t, vendorList.Version(), uint16(28))
assert.Nil(t, vendorList.Vendor(0))
func TestParseEagerlyEmptyVendorList(t *testing.T) {
tests := []struct{
name string
vendorList string
vendorListVersion uint16
}{
{
name: "vendor list spec 2",
vendorList: testDataSpecVersion2Empty,
vendorListVersion: 28,
},
{
name: "vendor list spec 3",
vendorList: testDataSpecVersion3Empty,
vendorListVersion: 1,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
parsedGVL, err := ParseEagerly([]byte(tt.vendorList))
assert.NoError(t, err)
assert.Equal(t, tt.vendorListVersion, parsedGVL.Version())
assert.Nil(t, parsedGVL.Vendor(8))
assert.Nil(t, parsedGVL.Vendor(80))
})
}
}
59 changes: 57 additions & 2 deletions vendorlist2/lazy-parsing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,63 @@ package vendorlist2

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestLazyParsedVendorList(t *testing.T) {
AssertVendorlistCorrectness(t, ParseLazily)
func TestParseLazilyVendorList(t *testing.T) {
tests := []struct{
name string
vendorList string
vendorListVersion uint16
}{
{
name: "vendor list spec 2",
vendorList: testDataSpecVersion2,
vendorListVersion: 28,
},
{
name: "vendor list spec 3",
vendorList: testDataSpecVersion3,
vendorListVersion: 1,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
parsedGVL := ParseLazily([]byte(tt.vendorList))
assert.Equal(t, tt.vendorListVersion, parsedGVL.Version())
assert.NotNil(t, parsedGVL.Vendor(8))
assert.NotNil(t, parsedGVL.Vendor(80))
AssertVendorListCorrectness(t, parsedGVL)
})
}
}

func TestParseLazilyEmptyVendorList(t *testing.T) {
tests := []struct{
name string
vendorList string
vendorListVersion uint16
}{
{
name: "vendor list spec 2",
vendorList: testDataSpecVersion2Empty,
vendorListVersion: 28,
},
{
name: "vendor list spec 3",
vendorList: testDataSpecVersion3Empty,
vendorListVersion: 1,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
parsedGVL := ParseLazily([]byte(tt.vendorList))
assert.Equal(t, tt.vendorListVersion, parsedGVL.Version())
assert.Nil(t, parsedGVL.Vendor(8))
assert.Nil(t, parsedGVL.Vendor(80))
})
}
}
Loading