Skip to content

Commit

Permalink
Modernise, remove deps (bsm#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
dim authored Jan 9, 2023
1 parent 12c76e8 commit b106b7e
Show file tree
Hide file tree
Showing 25 changed files with 710 additions and 696 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Test
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
go:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.18.x, 1.19.x]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
cache: true
- run: make test
golangci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.x
cache: true
- uses: golangci/golangci-lint-action@v3
with:
version: latest
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.makefile
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

12 changes: 4 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
default: vet test
default: test

test:
go test -a ./...
.minimal.makefile:
curl -fsSL -o $@ https://gitlab.com/bsm/misc/raw/master/make/go/minimal.makefile

bench:
go test ./... -bench=. -run=NONE

vet:
go vet ./...
include .minimal.makefile
105 changes: 55 additions & 50 deletions audio_test.go
Original file line number Diff line number Diff line change
@@ -1,57 +1,62 @@
package openrtb
package openrtb_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"errors"
"reflect"
"testing"

. "github.com/bsm/openrtb/v3"
)

var _ = Describe("Audio", func() {
func TestAudio(t *testing.T) {
var subject *Audio
if err := fixture("audio", &subject); err != nil {
t.Fatalf("expected no error, got %v", err)
}

BeforeEach(func() {
Expect(fixture("audio", &subject)).To(Succeed())
})

It("should parse correctly", func() {
Expect(subject).To(Equal(&Audio{
MIMEs: []string{
"audio/mp4",
},
MinDuration: 5,
MaxDuration: 30,
Protocols: []Protocol{ProtocolDAAST1, ProtocolDAAST1Wrapper},
Sequence: 1,
BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert},
MaxExtended: 30,
MinBitrate: 300,
MaxBitrate: 1500,
Delivery: []ContentDelivery{ContentDeliveryProgressive},
CompanionAds: []Banner{
{Width: 300, Height: 250, ID: "1234567893-1", Position: AdPositionAboveFold, BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}, ExpDirs: []ExpDir{ExpDirRight, ExpDirDown}},
{Width: 728, Height: 90, ID: "1234567893-2", Position: AdPositionAboveFold, BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}},
},
APIs: []APIFramework{APIFrameworkVPAID1, APIFrameworkVPAID2},
CompanionTypes: []CompanionType{CompanionTypeStatic, CompanionTypeHTML},
}))
})

It("should validate", func() {
Expect((&Audio{
MinDuration: 5,
MaxDuration: 30,
Protocols: []Protocol{ProtocolDAAST1, ProtocolDAAST1Wrapper},
Sequence: 1,
BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert},
MaxExtended: 30,
MinBitrate: 300,
MaxBitrate: 1500,
Delivery: []ContentDelivery{ContentDeliveryProgressive},
CompanionAds: []Banner{
{Width: 300, Height: 250, ID: "1234567893-1", Position: AdPositionAboveFold, BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}, ExpDirs: []ExpDir{ExpDirRight, ExpDirDown}},
{Width: 728, Height: 90, ID: "1234567893-2", Position: AdPositionAboveFold, BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}},
},
CompanionTypes: []CompanionType{CompanionTypeStatic, CompanionTypeHTML},
}).Validate()).To(Equal(ErrInvalidAudioNoMIMEs))
})
exp := &Audio{
MIMEs: []string{
"audio/mp4",
},
MinDuration: 5,
MaxDuration: 30,
Protocols: []Protocol{ProtocolDAAST1, ProtocolDAAST1Wrapper},
Sequence: 1,
BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert},
MaxExtended: 30,
MinBitrate: 300,
MaxBitrate: 1500,
Delivery: []ContentDelivery{ContentDeliveryProgressive},
CompanionAds: []Banner{
{Width: 300, Height: 250, ID: "1234567893-1", Position: AdPositionAboveFold, BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}, ExpDirs: []ExpDir{ExpDirRight, ExpDirDown}},
{Width: 728, Height: 90, ID: "1234567893-2", Position: AdPositionAboveFold, BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}},
},
APIs: []APIFramework{APIFrameworkVPAID1, APIFrameworkVPAID2},
CompanionTypes: []CompanionType{CompanionTypeStatic, CompanionTypeHTML},
}
if got := subject; !reflect.DeepEqual(exp, got) {
t.Errorf("expected %+v, got %+v", exp, got)
}
}

})
func TestAudio_Validate(t *testing.T) {
subject := &Audio{
MinDuration: 5,
MaxDuration: 30,
Protocols: []Protocol{ProtocolDAAST1, ProtocolDAAST1Wrapper},
Sequence: 1,
BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert},
MaxExtended: 30,
MinBitrate: 300,
MaxBitrate: 1500,
Delivery: []ContentDelivery{ContentDeliveryProgressive},
CompanionAds: []Banner{
{Width: 300, Height: 250, ID: "1234567893-1", Position: AdPositionAboveFold, BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}, ExpDirs: []ExpDir{ExpDirRight, ExpDirDown}},
{Width: 728, Height: 90, ID: "1234567893-2", Position: AdPositionAboveFold, BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}},
},
CompanionTypes: []CompanionType{CompanionTypeStatic, CompanionTypeHTML},
}
if exp, got := ErrInvalidAudioNoMIMEs, subject.Validate(); !errors.Is(exp, got) {
t.Fatalf("expected %v, got %v", exp, got)
}
}
43 changes: 22 additions & 21 deletions banner_test.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
package openrtb
package openrtb_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"reflect"
"testing"

. "github.com/bsm/openrtb/v3"
)

var _ = Describe("Banner", func() {
func TestBanner(t *testing.T) {
var subject *Banner
if err := fixture("banner", &subject); err != nil {
t.Fatalf("expected no error, got %v", err)
}

BeforeEach(func() {
Expect(fixture("banner", &subject)).To(Succeed())
})

It("should parse correctly", func() {
Expect(subject).To(Equal(&Banner{
Width: 728,
Height: 90,
Position: AdPositionAboveFold,
BlockedTypes: []BannerType{BannerTypeFrame},
BlockedAttrs: []CreativeAttribute{CreativeAttributeWindowsDialogOrAlert},
APIs: []APIFramework{APIFrameworkMRAID1},
VCM: 1,
}))
})

})
exp := &Banner{
Width: 728,
Height: 90,
Position: AdPositionAboveFold,
BlockedTypes: []BannerType{BannerTypeFrame},
BlockedAttrs: []CreativeAttribute{CreativeAttributeWindowsDialogOrAlert},
APIs: []APIFramework{APIFrameworkMRAID1},
VCM: 1,
}
if got := subject; !reflect.DeepEqual(exp, got) {
t.Errorf("expected %+v, got %+v", exp, got)
}
}
6 changes: 3 additions & 3 deletions bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package openrtb

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

func BenchmarkBidRequest_Unmarshal(b *testing.B) {
data, err := ioutil.ReadFile(filepath.Join("testdata", "breq.video.json"))
data, err := os.ReadFile(filepath.Join("testdata", "breq.video.json"))
if err != nil {
b.Fatal(err.Error())
}
Expand All @@ -23,7 +23,7 @@ func BenchmarkBidRequest_Unmarshal(b *testing.B) {
}

func BenchmarkBidRequest_Marshal(b *testing.B) {
data, err := ioutil.ReadFile(filepath.Join("testdata", "breq.video.json"))
data, err := os.ReadFile(filepath.Join("testdata", "breq.video.json"))
if err != nil {
b.Fatal(err.Error())
}
Expand Down
69 changes: 38 additions & 31 deletions bid_test.go
Original file line number Diff line number Diff line change
@@ -1,38 +1,45 @@
package openrtb
package openrtb_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"errors"
"reflect"
"testing"

. "github.com/bsm/openrtb/v3"
)

var _ = Describe("Bid", func() {
func TestBid(t *testing.T) {
var subject *Bid
if err := fixture("bid", &subject); err != nil {
t.Fatalf("expected no error, got %v", err)
}

BeforeEach(func() {
Expect(fixture("bid", &subject)).To(Succeed())
})

It("should parse correctly", func() {
Expect(subject).To(Equal(&Bid{
ID: "1",
ImpID: "1",
Price: 0.751371,
AdID: "52a5516d29e435137c6f6e74",
NoticeURL: "http://ads.com/win/112770_1386565997?won=${AUCTION_PRICE}",
AdMarkup: "<html/>",
AdvDomains: []string{"ads.com"},
ImageURL: "http://ads.com/112770_1386565997.jpeg",
CampaignID: "52a5516d29e435137c6f6e74",
CreativeID: "52a5516d29e435137c6f6e74_1386565997",
DealID: "example_deal",
Attrs: []CreativeAttribute{},
}))
})

It("should validate", func() {
Expect((&Bid{}).Validate()).To(Equal(ErrInvalidBidNoID))
Expect((&Bid{ID: "BIDID"}).Validate()).To(Equal(ErrInvalidBidNoImpID))
Expect(subject.Validate()).NotTo(HaveOccurred())
})
exp := &Bid{
ID: "1",
ImpID: "1",
Price: 0.751371,
AdID: "52a5516d29e435137c6f6e74",
NoticeURL: "http://ads.com/win/112770_1386565997?won=${AUCTION_PRICE}",
AdMarkup: "<html/>",
AdvDomains: []string{"ads.com"},
ImageURL: "http://ads.com/112770_1386565997.jpeg",
CampaignID: "52a5516d29e435137c6f6e74",
CreativeID: "52a5516d29e435137c6f6e74_1386565997",
DealID: "example_deal",
Attrs: []CreativeAttribute{},
}
if got := subject; !reflect.DeepEqual(exp, got) {
t.Errorf("expected %+v, got %+v", exp, got)
}
}

})
func TestBid_Validate(t *testing.T) {
subject := &Bid{}
if exp, got := ErrInvalidBidNoID, subject.Validate(); !errors.Is(exp, got) {
t.Fatalf("expected %v, got %v", exp, got)
}
subject = &Bid{ID: "BIDID"}
if exp, got := ErrInvalidBidNoImpID, subject.Validate(); !errors.Is(exp, got) {
t.Fatalf("expected %v, got %v", exp, got)
}
}
Loading

0 comments on commit b106b7e

Please sign in to comment.