github.com/prebid/prebid-server@v0.275.0/gdpr/purpose_config_test.go (about)

     1  package gdpr
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/prebid/prebid-server/openrtb_ext"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestPurposeConfigBasicEnforcementVendor(t *testing.T) {
    12  	tests := []struct {
    13  		description      string
    14  		giveBasicVendors map[string]struct{}
    15  		giveBidder       openrtb_ext.BidderName
    16  		wantFound        bool
    17  	}{
    18  		{
    19  			description:      "vendor map is nil",
    20  			giveBasicVendors: nil,
    21  			giveBidder:       openrtb_ext.BidderAppnexus,
    22  			wantFound:        false,
    23  		},
    24  		{
    25  			description:      "vendor map is empty",
    26  			giveBasicVendors: map[string]struct{}{},
    27  			giveBidder:       openrtb_ext.BidderAppnexus,
    28  			wantFound:        false,
    29  		},
    30  		{
    31  			description: "vendor map has one bidders - bidder not found",
    32  			giveBasicVendors: map[string]struct{}{
    33  				string(openrtb_ext.BidderPubmatic): {},
    34  			},
    35  			giveBidder: openrtb_ext.BidderAppnexus,
    36  			wantFound:  false,
    37  		},
    38  		{
    39  			description: "vendor map has one bidders - bidder found",
    40  			giveBasicVendors: map[string]struct{}{
    41  				string(openrtb_ext.BidderAppnexus): {},
    42  			},
    43  			giveBidder: openrtb_ext.BidderAppnexus,
    44  			wantFound:  true,
    45  		},
    46  		{
    47  			description: "vendor map has many bidderss - bidder not found",
    48  			giveBasicVendors: map[string]struct{}{
    49  				string(openrtb_ext.BidderIx):       {},
    50  				string(openrtb_ext.BidderPubmatic): {},
    51  				string(openrtb_ext.BidderRubicon):  {},
    52  			},
    53  			giveBidder: openrtb_ext.BidderAppnexus,
    54  			wantFound:  false,
    55  		},
    56  		{
    57  			description: "vendor map has many bidderss - bidder found",
    58  			giveBasicVendors: map[string]struct{}{
    59  				string(openrtb_ext.BidderIx):       {},
    60  				string(openrtb_ext.BidderPubmatic): {},
    61  				string(openrtb_ext.BidderAppnexus): {},
    62  				string(openrtb_ext.BidderRubicon):  {},
    63  			},
    64  			giveBidder: openrtb_ext.BidderAppnexus,
    65  			wantFound:  true,
    66  		},
    67  	}
    68  
    69  	for _, tt := range tests {
    70  		cfg := purposeConfig{
    71  			BasicEnforcementVendorsMap: tt.giveBasicVendors,
    72  		}
    73  		found := cfg.basicEnforcementVendor(tt.giveBidder)
    74  
    75  		assert.Equal(t, tt.wantFound, found, tt.description)
    76  	}
    77  }
    78  
    79  func TestPurposeConfigVendorException(t *testing.T) {
    80  	tests := []struct {
    81  		description    string
    82  		giveExceptions map[openrtb_ext.BidderName]struct{}
    83  		giveBidder     openrtb_ext.BidderName
    84  		wantFound      bool
    85  	}{
    86  		{
    87  			description:    "vendor exception map is nil",
    88  			giveExceptions: nil,
    89  			giveBidder:     openrtb_ext.BidderAppnexus,
    90  			wantFound:      false,
    91  		},
    92  		{
    93  			description:    "vendor exception map is empty",
    94  			giveExceptions: map[openrtb_ext.BidderName]struct{}{},
    95  			giveBidder:     openrtb_ext.BidderAppnexus,
    96  			wantFound:      false,
    97  		},
    98  		{
    99  			description: "vendor exception map has one bidders - bidder not found",
   100  			giveExceptions: map[openrtb_ext.BidderName]struct{}{
   101  				openrtb_ext.BidderPubmatic: {},
   102  			},
   103  			giveBidder: openrtb_ext.BidderAppnexus,
   104  			wantFound:  false,
   105  		},
   106  		{
   107  			description: "vendor exception map has one bidders - bidder found",
   108  			giveExceptions: map[openrtb_ext.BidderName]struct{}{
   109  				openrtb_ext.BidderAppnexus: {},
   110  			},
   111  			giveBidder: openrtb_ext.BidderAppnexus,
   112  			wantFound:  true,
   113  		},
   114  		{
   115  			description: "vendor exception map has many bidderss - bidder not found",
   116  			giveExceptions: map[openrtb_ext.BidderName]struct{}{
   117  				openrtb_ext.BidderIx:       {},
   118  				openrtb_ext.BidderPubmatic: {},
   119  				openrtb_ext.BidderRubicon:  {},
   120  			},
   121  			giveBidder: openrtb_ext.BidderAppnexus,
   122  			wantFound:  false,
   123  		},
   124  		{
   125  			description: "vendor exception map has many bidderss - bidder found",
   126  			giveExceptions: map[openrtb_ext.BidderName]struct{}{
   127  				openrtb_ext.BidderIx:       {},
   128  				openrtb_ext.BidderPubmatic: {},
   129  				openrtb_ext.BidderAppnexus: {},
   130  				openrtb_ext.BidderRubicon:  {},
   131  			},
   132  			giveBidder: openrtb_ext.BidderAppnexus,
   133  			wantFound:  true,
   134  		},
   135  	}
   136  
   137  	for _, tt := range tests {
   138  		cfg := purposeConfig{
   139  			VendorExceptionMap: tt.giveExceptions,
   140  		}
   141  		found := cfg.vendorException(tt.giveBidder)
   142  
   143  		assert.Equal(t, tt.wantFound, found, tt.description)
   144  	}
   145  }