Skip to content
This repository has been archived by the owner on Oct 6, 2022. It is now read-only.

Commit

Permalink
Added simple tests (JSON marshalling); deprecated User.BuyerID proper…
Browse files Browse the repository at this point in the history
…ty (in favor of User.BuyerUID)
  • Loading branch information
mxmCherry committed Jul 30, 2016
1 parent 9c5f1bf commit 0e64a5f
Show file tree
Hide file tree
Showing 14 changed files with 477 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![GoDoc](https://godoc.org/gopkg.in/mxmCherry/openrtb.v2?status.svg)](https://godoc.org/gopkg.in/mxmCherry/openrtb.v2)

[OpenRTB](//github.com/openrtb/OpenRTB) [v2.3](//github.com/openrtb/OpenRTB/blob/master/OpenRTB-API-Specification-Version-2-3-FINAL.pdf) types for Go programming language (golang)
[OpenRTB](//github.com/openrtb/OpenRTB) [v2.3.1](//github.com/openrtb/OpenRTB/blob/master/OpenRTB-API-Specification-Version-2-3-1-FINAL.pdf) types for Go programming language (golang)

**Warning!** Using [glide](https://github.com/Masterminds/glide) is recommended to vendor specific commit hash.

Expand Down Expand Up @@ -31,7 +31,7 @@ Provide base for OpenRTB-related projects, focusing on:
- Capitalized ID keys

## Types
- Key types should be chosen according to OpenRTB v2.3 specification (attribute types)
- Key types should be chosen according to OpenRTB v2.3.1 specification (attribute types)
- Numeric types:
- architecture-independent, e.g., ```int32``` instead of ```int```
- signed integral types should be used only when absolutely needed (value may contain negative numbers), unsigned integral types are preferred
Expand Down
78 changes: 78 additions & 0 deletions openrtb_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package openrtb_test

import (
"encoding/json"
"io/ioutil"
"path/filepath"
"testing"

"github.com/mxmCherry/openrtb"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
)

func TestOpenRTB(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "OpenRTB")
}

// ----------------------------------------------------------------------------

var _ = DescribeTable(
"Marshalling",
func(filename string, subject interface{}) {

expected, err := ioutil.ReadFile(filepath.Join("testdata", filename))
Expect(err).NotTo(HaveOccurred())

Expect(json.Unmarshal(expected, subject)).To(Succeed())

actual, err := json.Marshal(subject)
Expect(err).NotTo(HaveOccurred())

Expect(actual).To(MatchJSON(expected))
},
Entry(
"Bid Request - Simple Banner",
"bid-request-simple-banner.json",
new(openrtb.BidRequest)),
Entry(
"Bid Request - Expandable Creative",
"bid-request-expandable-creative.json",
new(openrtb.BidRequest)),
Entry(
"Bid Request - Mobile",
"bid-request-mobile.json",
new(openrtb.BidRequest)),
Entry(
"Bid Request - Video",
"bid-request-video.json",
new(openrtb.BidRequest)),
Entry(
"Bid Request - PMP with Direct Deal",
"bid-request-pmp-with-direct-deal.json",
new(openrtb.BidRequest)),
Entry(
"Bid Request - Native Ad",
"bid-request-native-ad.json",
new(openrtb.BidRequest)),

Entry(
"Bid Response - Ad Served on Win Notice",
"bid-response-ad-served-on-win-notice.json",
new(openrtb.BidResponse)),
Entry(
"Bid Response - VAST XML Document Returned Inline",
"bid-response-vast-xml-document-returned-inline.json",
new(openrtb.BidResponse)),
Entry(
"Bid Response - Direct Deal Ad Served on Win Notice",
"bid-response-direct-deal-ad-served-on-win-notice.json",
new(openrtb.BidResponse)),
Entry(
"Bid Response - Native Markup Returned Inline",
"bid-response-native-markup-returned-inline.json",
new(openrtb.BidResponse)),
)
5 changes: 5 additions & 0 deletions testdata/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Testdata

JSON examples copied from [OpenRTB](//github.com/openrtb/OpenRTB) [v2.3.1](//github.com/openrtb/OpenRTB/blob/master/OpenRTB-API-Specification-Version-2-3-1-FINAL.pdf) spec - section 6. Bid Request/Response Samples.

Some empty/zero attributes (like `imp[i].banner.pos == 0`) were omited because of [encoding/json](//golang.org/pkg/encoding/json/) `omitempty` and [gomega.MatchJSON(...)](//onsi.github.io/gomega/#matchjsonjson-interface).
51 changes: 51 additions & 0 deletions testdata/bid-request-expandable-creative.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"id": "123456789316e6ede735f123ef6e32361bfc7b22",
"at": 2,
"cur": ["USD"],
"imp": [{
"id": "1",
"bidfloor": 0.03,
"iframebuster": ["vendor1.com", "vendor2.com"],
"banner": {
"h": 250,
"w": 300,
"battr": [13],
"expdir": [2, 4]
}
}],
"site": {
"id": "102855",
"cat": ["IAB3-1"],
"domain": "www.foobar.com",
"page": "http://www.foobar.com/1234.html",
"publisher": {
"id": "8953",
"name": "foobar.com",
"cat": ["IAB3-1"],
"domain": "foobar.com"
}
},
"device": {
"ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.13 (KHTML, like Gecko) Version / 5.1 .7 Safari / 534.57 .2 ",
"ip": "123.145.167.10"
},
"user": {
"id": "55816b39711f9b5acf3b90e313ed29e51665623f",
"buyeruid": "545678765467876567898765678987654",
"data": [{
"id": "6",
"name": "Data Provider 1",
"segment": [{
"id": "12341318394918",
"name": "auto intenders"
}, {
"id": "1234131839491234",
"name": "auto enthusiasts"
}, {
"id": "23423424",
"name": "data-provider1-age",
"value": "30-40"
}]
}]
}
}
60 changes: 60 additions & 0 deletions testdata/bid-request-mobile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"id": "IxexyLDIIk",
"at": 2,
"bcat": ["IAB25", "IAB7-39", "IAB8-18", "IAB8-5", "IAB9-9"],
"badv": ["apple.com", "go-text.me", "heywire.com"],
"imp": [{
"id": "1",
"bidfloor": 0.5,
"tagid": "agltb3B1Yi1pbmNyDQsSBFNpdGUY7fD0FAw",
"banner": {
"w": 728,
"h": 90,
"pos": 1,
"btype": [4],
"battr": [14],
"api": [3]
}
}],
"app": {
"id": "agltb3B1Yi1pbmNyDAsSA0FwcBiJkfIUDA",
"name": "Yahoo Weather",
"cat": ["IAB15", "IAB15-10"],
"ver": "1.0.2",
"bundle": "com.yahoo.wxapp",
"storeurl": "https://itunes.apple.com/id628677149",
"publisher": {
"id": "agltb3B1Yi1pbmNyDAsSA0FwcBiJkfTUCV",
"name": "yahoo",
"domain": "www.yahoo.com"
}
},
"device": {
"ua": "Mozilla/5.0 (iPhone; CPU iPhone OS 6_1 like Mac OS X) AppleWebKit / 534.46(KHTML, like Gecko) Version / 5.1 Mobile / 9 A334 Safari / 7534.48 .3 ",
"ip": "123.145.167.189",
"ifa": "AA000DFE74168477C70D291f574D344790E0BB11",
"carrier": "VERIZON",
"language": "en",
"make": "Apple",
"model": "iPhone",
"os": "iOS",
"osv": "6.1",
"js": 1,
"connectiontype": 3,
"devicetype": 1,
"geo": {
"lat": 35.012345,
"lon": -115.12345,
"country": "USA",
"metro": "803",
"region": "CA",
"city": "Los Angeles",
"zip": "90049"
}
},
"user": {
"id": "ffffffd5135596709273b3a1a07e466ea2bf4fff",
"yob": 1984,
"gender": "M"
}
}
34 changes: 34 additions & 0 deletions testdata/bid-request-native-ad.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"id": "80ce30c53c16e6ede735f123ef6e32361bfc7b22",
"at": 1,
"cur": ["USD"],
"imp": [{
"id": "1",
"bidfloor": 0.03,
"native": {
"request": "...Native Spec request as an encoded string...",
"ver": "1.0",
"api": [3],
"battr": [13, 14]
}
}],
"site": {
"id": "102855",
"cat": ["IAB3-1"],
"domain": "www.foobar.com",
"page": "http://www.foobar.com/1234.html ",
"publisher": {
"id": "8953",
"name": "foobar.com",
"cat": ["IAB3-1"],
"domain": "foobar.com"
}
},
"device": {
"ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.13 (KHTML, like Gecko) Version / 5.1 .7 Safari / 534.57 .2 ",
"ip": "123.145.167.10"
},
"user": {
"id": "55816b39711f9b5acf3b90e313ed29e51665623f"
}
}
46 changes: 46 additions & 0 deletions testdata/bid-request-pmp-with-direct-deal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"id": "80ce30c53c16e6ede735f123ef6e32361bfc7b22",
"at": 1,
"cur": ["USD"],
"imp": [{
"id": "1",
"bidfloor": 0.03,
"banner": {
"h": 250,
"w": 300
},
"pmp": {
"private_auction": 1,
"deals": [{
"id": "AB-Agency1-0001",
"at": 1,
"bidfloor": 2.5,
"wseat": ["Agency1"]
}, {
"id": "XY-Agency2-0001",
"at": 2,
"bidfloor": 2,
"wseat": ["Agency2"]
}]
}
}],
"site": {
"id": "102855",
"domain": "www.foobar.com",
"cat": ["IAB3-1"],
"page": "http://www.foobar.com/1234.html",
"publisher": {
"id": "8953",
"name": "foobar.com",
"cat": ["IAB3-1"],
"domain": "foobar.com"
}
},
"device": {
"ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.13 (KHTML, like Gecko) Version / 5.1 .7 Safari / 534.57 .2 ",
"ip": "123.145.167.10"
},
"user": {
"id": "55816b39711f9b5acf3b90e313ed29e51665623f"
}
}
32 changes: 32 additions & 0 deletions testdata/bid-request-simple-banner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"id": "80ce30c53c16e6ede735f123ef6e32361bfc7b22",
"at": 1,
"cur": ["USD"],
"imp": [{
"id": "1",
"bidfloor": 0.03,
"banner": {
"h": 250,
"w": 300
}
}],
"site": {
"id": "102855",
"cat": ["IAB3-1"],
"domain": "www.foobar.com",
"page": "http://www.foobar.com/1234.html ",
"publisher": {
"id": "8953",
"name": "foobar.com",
"cat": ["IAB3-1"],
"domain": "foobar.com"
}
},
"device": {
"ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.13 (KHTML, like Gecko) Version / 5.1 .7 Safari / 534.57 .2 ",
"ip": "123.145.167.10"
},
"user": {
"id": "55816b39711f9b5acf3b90e313ed29e51665623f"
}
}
Loading

0 comments on commit 0e64a5f

Please sign in to comment.