Skip to content

Commit

Permalink
TestMain(m *testing.M)
Browse files Browse the repository at this point in the history
  • Loading branch information
guscarreon committed Feb 12, 2024
1 parent 7747b2e commit 86ee89c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
8 changes: 1 addition & 7 deletions adapters/amx/amx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import (
"fmt"
"testing"

jsoniter "github.com/json-iterator/go"
"github.com/prebid/openrtb/v20/openrtb2"
"github.com/prebid/prebid-server/v2/adapters"
"github.com/prebid/prebid-server/v2/config"
"github.com/prebid/prebid-server/v2/openrtb_ext"
"github.com/prebid/prebid-server/v2/util/jsonutil"
"github.com/stretchr/testify/assert"

"github.com/prebid/prebid-server/v2/adapters/adapterstest"
Expand Down Expand Up @@ -47,10 +45,6 @@ func TestEndpointQueryStringMalformed(t *testing.T) {
assert.Error(t, buildErr)
}

func TestMain(m *testing.M) {
jsoniter.RegisterExtension(&jsonutil.RawMessageExtension{})
m.Run()
}
func TestMakeRequestsTagID(t *testing.T) {
var w, h int = 300, 250
var width, height int64 = int64(w), int64(h)
Expand Down Expand Up @@ -109,7 +103,7 @@ func TestMakeRequestsTagID(t *testing.T) {
assert.Len(t, actualAdapterRequests, 1)
assert.Empty(t, err)
var body openrtb2.BidRequest
assert.Nil(t, jsonutil.Unmarshal(actualAdapterRequests[0].Body, &body))
assert.Nil(t, json.Unmarshal(actualAdapterRequests[0].Body, &body))
assert.Equal(t, tc.expectedTagID, body.Imp[0].TagID)
}
}
Expand Down
10 changes: 4 additions & 6 deletions endpoints/openrtb2/auction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ import (

const jsonFileExtension string = ".json"

//func TestMain(m *testing.M) {
// jsoniter.RegisterExtension(&jsonutil.RawMessageExtension{})
// m.Run()
//}
func TestMain(m *testing.M) {
jsoniter.RegisterExtension(&jsonutil.RawMessageExtension{})
m.Run()
}

func TestJsonSampleRequests(t *testing.T) {
testSuites := []struct {
Expand Down Expand Up @@ -128,7 +128,6 @@ func TestJsonSampleRequests(t *testing.T) {
},
}

//jsoniter.RegisterExtension(&jsonutil.RawMessageExtension{})
for _, tc := range testSuites {
err := filepath.WalkDir(filepath.Join("sample-requests", tc.sampleRequestsSubDir), func(path string, info fs.DirEntry, err error) error {
// According to documentation, needed to avoid panics
Expand All @@ -150,7 +149,6 @@ func TestJsonSampleRequests(t *testing.T) {
}

func TestSingleJSONTest(t *testing.T) {
jsoniter.RegisterExtension(&jsonutil.RawMessageExtension{})
runJsonBasedTest(t, "sample-requests/valid-whole/exemplary/simple.json", "")
}

Expand Down
27 changes: 27 additions & 0 deletions router/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"

jsoniter "github.com/json-iterator/go"
"github.com/prebid/prebid-server/v2/config"
"github.com/prebid/prebid-server/v2/openrtb_ext"
"github.com/prebid/prebid-server/v2/util/jsonutil"
Expand All @@ -18,6 +20,11 @@ const adapterDirectory = "../adapters"

type testValidator struct{}

func TestMain(m *testing.M) {
jsoniter.RegisterExtension(&jsonutil.RawMessageExtension{})
m.Run()
}

func (validator *testValidator) Validate(name openrtb_ext.BidderName, ext json.RawMessage) error {
return nil
}
Expand Down Expand Up @@ -275,3 +282,23 @@ func TestValidateDefaultAliases(t *testing.T) {
}
}
}

func TestBidderParamsCompactedOutput(t *testing.T) {
expectedPrefix := `{"33across":{"$schema":"http://json-schema.org/draft-04/schema#","title":"33Across Adapter Params","description":"A schema which validates params accepted by the 33Across adapter","type":"object","properties":{"productId":{"type":"string","description":"Product type"},"siteId":{"type":"string","description":"Site Id"},"zoneId":{"type":"string","description":"Zone Id"}},"required":["productId","siteId"]}`

// Setup
inSchemaDirectory := "../static/bidder-params"
paramsValidator, err := openrtb_ext.NewBidderParamsValidator(inSchemaDirectory)
assert.NoError(t, err, "Error initialing validator")
handler := newJsonDirectoryServer(inSchemaDirectory, paramsValidator, nil, nil)
recorder := httptest.NewRecorder()
request, err := http.NewRequest("GET", "/whatever", nil)
assert.NoError(t, err, "Error creating request")

// Run
handler(recorder, request, nil)

// Assertions
assert.True(t, strings.HasPrefix(recorder.Body.String(), expected))
//assert.Equal(t, expected, recorder.Body.String())
}

0 comments on commit 86ee89c

Please sign in to comment.