Skip to content

Commit b106b7e

Browse files
authored
Modernise, remove deps (bsm#93)
1 parent 12c76e8 commit b106b7e

25 files changed

+710
-696
lines changed

.github/workflows/test.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Test
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
branches:
8+
- main
9+
jobs:
10+
go:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
go-version: [1.18.x, 1.19.x]
15+
steps:
16+
- uses: actions/checkout@v3
17+
- uses: actions/setup-go@v3
18+
with:
19+
go-version: ${{ matrix.go-version }}
20+
cache: true
21+
- run: make test
22+
golangci:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v3
26+
- uses: actions/setup-go@v3
27+
with:
28+
go-version: 1.x
29+
cache: true
30+
- uses: golangci/golangci-lint-action@v3
31+
with:
32+
version: latest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.makefile

.travis.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.

Makefile

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
default: vet test
1+
default: test
22

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

6-
bench:
7-
go test ./... -bench=. -run=NONE
8-
9-
vet:
10-
go vet ./...
6+
include .minimal.makefile

audio_test.go

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,62 @@
1-
package openrtb
1+
package openrtb_test
22

33
import (
4-
. "github.com/onsi/ginkgo"
5-
. "github.com/onsi/gomega"
4+
"errors"
5+
"reflect"
6+
"testing"
7+
8+
. "github.com/bsm/openrtb/v3"
69
)
710

8-
var _ = Describe("Audio", func() {
11+
func TestAudio(t *testing.T) {
912
var subject *Audio
13+
if err := fixture("audio", &subject); err != nil {
14+
t.Fatalf("expected no error, got %v", err)
15+
}
1016

11-
BeforeEach(func() {
12-
Expect(fixture("audio", &subject)).To(Succeed())
13-
})
14-
15-
It("should parse correctly", func() {
16-
Expect(subject).To(Equal(&Audio{
17-
MIMEs: []string{
18-
"audio/mp4",
19-
},
20-
MinDuration: 5,
21-
MaxDuration: 30,
22-
Protocols: []Protocol{ProtocolDAAST1, ProtocolDAAST1Wrapper},
23-
Sequence: 1,
24-
BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert},
25-
MaxExtended: 30,
26-
MinBitrate: 300,
27-
MaxBitrate: 1500,
28-
Delivery: []ContentDelivery{ContentDeliveryProgressive},
29-
CompanionAds: []Banner{
30-
{Width: 300, Height: 250, ID: "1234567893-1", Position: AdPositionAboveFold, BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}, ExpDirs: []ExpDir{ExpDirRight, ExpDirDown}},
31-
{Width: 728, Height: 90, ID: "1234567893-2", Position: AdPositionAboveFold, BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}},
32-
},
33-
APIs: []APIFramework{APIFrameworkVPAID1, APIFrameworkVPAID2},
34-
CompanionTypes: []CompanionType{CompanionTypeStatic, CompanionTypeHTML},
35-
}))
36-
})
37-
38-
It("should validate", func() {
39-
Expect((&Audio{
40-
MinDuration: 5,
41-
MaxDuration: 30,
42-
Protocols: []Protocol{ProtocolDAAST1, ProtocolDAAST1Wrapper},
43-
Sequence: 1,
44-
BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert},
45-
MaxExtended: 30,
46-
MinBitrate: 300,
47-
MaxBitrate: 1500,
48-
Delivery: []ContentDelivery{ContentDeliveryProgressive},
49-
CompanionAds: []Banner{
50-
{Width: 300, Height: 250, ID: "1234567893-1", Position: AdPositionAboveFold, BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}, ExpDirs: []ExpDir{ExpDirRight, ExpDirDown}},
51-
{Width: 728, Height: 90, ID: "1234567893-2", Position: AdPositionAboveFold, BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}},
52-
},
53-
CompanionTypes: []CompanionType{CompanionTypeStatic, CompanionTypeHTML},
54-
}).Validate()).To(Equal(ErrInvalidAudioNoMIMEs))
55-
})
17+
exp := &Audio{
18+
MIMEs: []string{
19+
"audio/mp4",
20+
},
21+
MinDuration: 5,
22+
MaxDuration: 30,
23+
Protocols: []Protocol{ProtocolDAAST1, ProtocolDAAST1Wrapper},
24+
Sequence: 1,
25+
BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert},
26+
MaxExtended: 30,
27+
MinBitrate: 300,
28+
MaxBitrate: 1500,
29+
Delivery: []ContentDelivery{ContentDeliveryProgressive},
30+
CompanionAds: []Banner{
31+
{Width: 300, Height: 250, ID: "1234567893-1", Position: AdPositionAboveFold, BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}, ExpDirs: []ExpDir{ExpDirRight, ExpDirDown}},
32+
{Width: 728, Height: 90, ID: "1234567893-2", Position: AdPositionAboveFold, BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}},
33+
},
34+
APIs: []APIFramework{APIFrameworkVPAID1, APIFrameworkVPAID2},
35+
CompanionTypes: []CompanionType{CompanionTypeStatic, CompanionTypeHTML},
36+
}
37+
if got := subject; !reflect.DeepEqual(exp, got) {
38+
t.Errorf("expected %+v, got %+v", exp, got)
39+
}
40+
}
5641

57-
})
42+
func TestAudio_Validate(t *testing.T) {
43+
subject := &Audio{
44+
MinDuration: 5,
45+
MaxDuration: 30,
46+
Protocols: []Protocol{ProtocolDAAST1, ProtocolDAAST1Wrapper},
47+
Sequence: 1,
48+
BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert},
49+
MaxExtended: 30,
50+
MinBitrate: 300,
51+
MaxBitrate: 1500,
52+
Delivery: []ContentDelivery{ContentDeliveryProgressive},
53+
CompanionAds: []Banner{
54+
{Width: 300, Height: 250, ID: "1234567893-1", Position: AdPositionAboveFold, BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}, ExpDirs: []ExpDir{ExpDirRight, ExpDirDown}},
55+
{Width: 728, Height: 90, ID: "1234567893-2", Position: AdPositionAboveFold, BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated, CreativeAttributeWindowsDialogOrAlert}},
56+
},
57+
CompanionTypes: []CompanionType{CompanionTypeStatic, CompanionTypeHTML},
58+
}
59+
if exp, got := ErrInvalidAudioNoMIMEs, subject.Validate(); !errors.Is(exp, got) {
60+
t.Fatalf("expected %v, got %v", exp, got)
61+
}
62+
}

banner_test.go

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
package openrtb
1+
package openrtb_test
22

33
import (
4-
. "github.com/onsi/ginkgo"
5-
. "github.com/onsi/gomega"
4+
"reflect"
5+
"testing"
6+
7+
. "github.com/bsm/openrtb/v3"
68
)
79

8-
var _ = Describe("Banner", func() {
10+
func TestBanner(t *testing.T) {
911
var subject *Banner
12+
if err := fixture("banner", &subject); err != nil {
13+
t.Fatalf("expected no error, got %v", err)
14+
}
1015

11-
BeforeEach(func() {
12-
Expect(fixture("banner", &subject)).To(Succeed())
13-
})
14-
15-
It("should parse correctly", func() {
16-
Expect(subject).To(Equal(&Banner{
17-
Width: 728,
18-
Height: 90,
19-
Position: AdPositionAboveFold,
20-
BlockedTypes: []BannerType{BannerTypeFrame},
21-
BlockedAttrs: []CreativeAttribute{CreativeAttributeWindowsDialogOrAlert},
22-
APIs: []APIFramework{APIFrameworkMRAID1},
23-
VCM: 1,
24-
}))
25-
})
26-
27-
})
16+
exp := &Banner{
17+
Width: 728,
18+
Height: 90,
19+
Position: AdPositionAboveFold,
20+
BlockedTypes: []BannerType{BannerTypeFrame},
21+
BlockedAttrs: []CreativeAttribute{CreativeAttributeWindowsDialogOrAlert},
22+
APIs: []APIFramework{APIFrameworkMRAID1},
23+
VCM: 1,
24+
}
25+
if got := subject; !reflect.DeepEqual(exp, got) {
26+
t.Errorf("expected %+v, got %+v", exp, got)
27+
}
28+
}

bench_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package openrtb
22

33
import (
44
"encoding/json"
5-
"io/ioutil"
5+
"os"
66
"path/filepath"
77
"testing"
88
)
99

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

2525
func BenchmarkBidRequest_Marshal(b *testing.B) {
26-
data, err := ioutil.ReadFile(filepath.Join("testdata", "breq.video.json"))
26+
data, err := os.ReadFile(filepath.Join("testdata", "breq.video.json"))
2727
if err != nil {
2828
b.Fatal(err.Error())
2929
}

bid_test.go

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,45 @@
1-
package openrtb
1+
package openrtb_test
22

33
import (
4-
. "github.com/onsi/ginkgo"
5-
. "github.com/onsi/gomega"
4+
"errors"
5+
"reflect"
6+
"testing"
7+
8+
. "github.com/bsm/openrtb/v3"
69
)
710

8-
var _ = Describe("Bid", func() {
11+
func TestBid(t *testing.T) {
912
var subject *Bid
13+
if err := fixture("bid", &subject); err != nil {
14+
t.Fatalf("expected no error, got %v", err)
15+
}
1016

11-
BeforeEach(func() {
12-
Expect(fixture("bid", &subject)).To(Succeed())
13-
})
14-
15-
It("should parse correctly", func() {
16-
Expect(subject).To(Equal(&Bid{
17-
ID: "1",
18-
ImpID: "1",
19-
Price: 0.751371,
20-
AdID: "52a5516d29e435137c6f6e74",
21-
NoticeURL: "http://ads.com/win/112770_1386565997?won=${AUCTION_PRICE}",
22-
AdMarkup: "<html/>",
23-
AdvDomains: []string{"ads.com"},
24-
ImageURL: "http://ads.com/112770_1386565997.jpeg",
25-
CampaignID: "52a5516d29e435137c6f6e74",
26-
CreativeID: "52a5516d29e435137c6f6e74_1386565997",
27-
DealID: "example_deal",
28-
Attrs: []CreativeAttribute{},
29-
}))
30-
})
31-
32-
It("should validate", func() {
33-
Expect((&Bid{}).Validate()).To(Equal(ErrInvalidBidNoID))
34-
Expect((&Bid{ID: "BIDID"}).Validate()).To(Equal(ErrInvalidBidNoImpID))
35-
Expect(subject.Validate()).NotTo(HaveOccurred())
36-
})
17+
exp := &Bid{
18+
ID: "1",
19+
ImpID: "1",
20+
Price: 0.751371,
21+
AdID: "52a5516d29e435137c6f6e74",
22+
NoticeURL: "http://ads.com/win/112770_1386565997?won=${AUCTION_PRICE}",
23+
AdMarkup: "<html/>",
24+
AdvDomains: []string{"ads.com"},
25+
ImageURL: "http://ads.com/112770_1386565997.jpeg",
26+
CampaignID: "52a5516d29e435137c6f6e74",
27+
CreativeID: "52a5516d29e435137c6f6e74_1386565997",
28+
DealID: "example_deal",
29+
Attrs: []CreativeAttribute{},
30+
}
31+
if got := subject; !reflect.DeepEqual(exp, got) {
32+
t.Errorf("expected %+v, got %+v", exp, got)
33+
}
34+
}
3735

38-
})
36+
func TestBid_Validate(t *testing.T) {
37+
subject := &Bid{}
38+
if exp, got := ErrInvalidBidNoID, subject.Validate(); !errors.Is(exp, got) {
39+
t.Fatalf("expected %v, got %v", exp, got)
40+
}
41+
subject = &Bid{ID: "BIDID"}
42+
if exp, got := ErrInvalidBidNoImpID, subject.Validate(); !errors.Is(exp, got) {
43+
t.Fatalf("expected %v, got %v", exp, got)
44+
}
45+
}

0 commit comments

Comments
 (0)