Skip to content

Commit

Permalink
use uuidutil
Browse files Browse the repository at this point in the history
  • Loading branch information
hasan-kanjee committed Nov 9, 2023
1 parent 1da6935 commit a304f2e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
16 changes: 4 additions & 12 deletions adapters/flipp/flipp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (
"strings"

"github.com/buger/jsonparser"
"github.com/gofrs/uuid"
"github.com/prebid/go-gdpr/consentconstants"
"github.com/prebid/go-gdpr/vendorconsent"
"github.com/prebid/openrtb/v19/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/uuidutil"
)

const (
Expand All @@ -25,7 +25,7 @@ const (
defaultCurrency = "USD"
)

var uuidGenerator UUIDGenerator
var uuidGenerator uuidutil.UUIDGenerator

var (
count int64 = 1
Expand All @@ -37,17 +37,9 @@ type adapter struct {
endpoint string
}

type UUIDGenerator struct {
Generate func() (uuid.UUID, error)
}

func Generate() (uuid.UUID, error) {
return uuid.NewV4()
}

// Builder builds a new instance of the Flipp adapter for the given bidder with the given config.
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) {
uuidGenerator.Generate = Generate
uuidGenerator = uuidutil.UUIDRandomGenerator{}
bidder := &adapter{
endpoint: config.Endpoint,
}
Expand Down Expand Up @@ -145,7 +137,7 @@ func (a *adapter) processImp(request *openrtb2.BidRequest, imp openrtb2.Imp) (*a
if err != nil {
return nil, fmt.Errorf("unable to generate user uuid. %v", err)
}
userKey = uid.String()
userKey = uid
}

keywordsArray := strings.Split(request.Site.Keywords, ",")
Expand Down
9 changes: 5 additions & 4 deletions adapters/flipp/flipp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"testing"

"github.com/gofrs/uuid"
"github.com/prebid/openrtb/v19/openrtb2"
"github.com/prebid/prebid-server/v2/adapters/adapterstest"
"github.com/prebid/prebid-server/v2/config"
Expand All @@ -14,15 +13,17 @@ import (

const fakeUuid = "30470a14-2949-4110-abce-b62d57304ad5"

func GenerateFakeUUID() (uuid.UUID, error) {
return uuid.FromStringOrNil(fakeUuid), nil
type TestUUIDGenerator struct{}

func (TestUUIDGenerator) Generate() (string, error) {
return fakeUuid, nil
}

func TestJsonSamples(t *testing.T) {
bidder, buildErr := Builder(openrtb_ext.BidderFlipp, config.Adapter{
Endpoint: "http://example.com/pserver"},
config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"})
uuidGenerator.Generate = GenerateFakeUUID
uuidGenerator = TestUUIDGenerator{}

if buildErr != nil {
t.Fatalf("Builder returned unexpected error %v", buildErr)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ require (
github.com/go-sql-driver/mysql v1.6.0
github.com/gofrs/uuid v4.2.0+incompatible
github.com/golang/glog v1.0.0
github.com/json-iterator/go v1.1.12
github.com/julienschmidt/httprouter v1.3.0
github.com/lib/pq v1.10.4
github.com/mitchellh/copystructure v1.2.0
Expand Down Expand Up @@ -47,6 +46,7 @@ require (
github.com/golang/protobuf v1.5.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
Expand Down

0 comments on commit a304f2e

Please sign in to comment.