github.com/prebid/prebid-server/v2@v2.18.0/adapters/adapterstest/adapter_test_util.go (about)

     1  package adapterstest
     2  
     3  import (
     4  	"fmt"
     5  	"net/http/httptest"
     6  	"strings"
     7  	"testing"
     8  
     9  	"net/http"
    10  
    11  	"github.com/prebid/openrtb/v20/openrtb2"
    12  )
    13  
    14  // OrtbMockService Represents a scaffolded OpenRTB service.
    15  type OrtbMockService struct {
    16  	Server          *httptest.Server
    17  	LastBidRequest  *openrtb2.BidRequest
    18  	LastHttpRequest *http.Request
    19  }
    20  
    21  // BidOnTags Produces a map of TagIds, based on a comma separated strings. The map
    22  // contains the list of tags to bid on.
    23  func BidOnTags(tags string) map[string]bool {
    24  	values := strings.Split(tags, ",")
    25  	set := make(map[string]bool)
    26  	for _, tag := range values {
    27  		set[tag] = true
    28  	}
    29  	return set
    30  }
    31  
    32  // SampleBid Produces a sample bid based on params given.
    33  func SampleBid(width *int64, height *int64, impId string, index int) openrtb2.Bid {
    34  	return openrtb2.Bid{
    35  		ID:    "Bid-123",
    36  		ImpID: fmt.Sprintf("div-adunit-%d", index),
    37  		Price: 2.1,
    38  		AdM:   "<div>This is an Ad</div>",
    39  		CrID:  "Cr-234",
    40  		W:     *width,
    41  		H:     *height,
    42  	}
    43  }
    44  
    45  // VerifyStringValue Helper function to assert string equals.
    46  func VerifyStringValue(value string, expected string, t *testing.T) {
    47  	if value != expected {
    48  		t.Fatalf(fmt.Sprintf("%s expected, got %s", expected, value))
    49  	}
    50  }
    51  
    52  // VerifyIntValue Helper function to assert Int equals.
    53  func VerifyIntValue(value int, expected int, t *testing.T) {
    54  	if value != expected {
    55  		t.Fatalf(fmt.Sprintf("%d expected, got %d", expected, value))
    56  	}
    57  }
    58  
    59  // VerifyBoolValue Helper function to assert bool equals.
    60  func VerifyBoolValue(value bool, expected bool, t *testing.T) {
    61  	if value != expected {
    62  		t.Fatalf(fmt.Sprintf("%v expected, got %v", expected, value))
    63  	}
    64  }
    65  
    66  // VerifyBannerSize helper function to assert banner size
    67  func VerifyBannerSize(banner *openrtb2.Banner, expectedWidth int, expectedHeight int, t *testing.T) {
    68  	VerifyIntValue(int(*(banner.W)), expectedWidth, t)
    69  	VerifyIntValue(int(*(banner.H)), expectedHeight, t)
    70  }