github.com/prebid/prebid-server/v2@v2.18.0/openrtb_ext/regs_test.go (about)

     1  package openrtb_ext
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/prebid/prebid-server/v2/util/ptrutil"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestExtRegsDSAClone(t *testing.T) {
    11  	tests := []struct {
    12  		name       string
    13  		extRegsDSA *ExtRegsDSA
    14  	}{
    15  		{
    16  			name:       "nil",
    17  			extRegsDSA: nil,
    18  		},
    19  		{
    20  			name: "required_not_nil",
    21  			extRegsDSA: &ExtRegsDSA{
    22  				Required: ptrutil.ToPtr[int8](1),
    23  			},
    24  		},
    25  		{
    26  			name: "pubrender_not_nil",
    27  			extRegsDSA: &ExtRegsDSA{
    28  				PubRender: ptrutil.ToPtr[int8](1),
    29  			},
    30  		},
    31  		{
    32  			name: "datatopub_not_nil",
    33  			extRegsDSA: &ExtRegsDSA{
    34  				DataToPub: ptrutil.ToPtr[int8](1),
    35  			},
    36  		},
    37  		{
    38  			name: "transparency_empty",
    39  			extRegsDSA: &ExtRegsDSA{
    40  				Transparency: []ExtBidDSATransparency{},
    41  			},
    42  		},
    43  		{
    44  			name: "transparency_with_nil_params",
    45  			extRegsDSA: &ExtRegsDSA{
    46  				Transparency: []ExtBidDSATransparency{
    47  					{
    48  						Domain: "domain1",
    49  						Params: nil,
    50  					},
    51  				},
    52  			},
    53  		},
    54  		{
    55  			name: "transparency_with_params",
    56  			extRegsDSA: &ExtRegsDSA{
    57  				Required:  ptrutil.ToPtr[int8](1),
    58  				PubRender: ptrutil.ToPtr[int8](1),
    59  				DataToPub: ptrutil.ToPtr[int8](1),
    60  				Transparency: []ExtBidDSATransparency{
    61  					{
    62  						Domain: "domain1",
    63  						Params: []int{1, 2, 3},
    64  					},
    65  					{
    66  						Domain: "domain2",
    67  						Params: []int{4, 5, 6},
    68  					},
    69  				},
    70  			},
    71  		},
    72  	}
    73  
    74  	for _, tt := range tests {
    75  		t.Run(tt.name, func(t *testing.T) {
    76  			clone := tt.extRegsDSA.Clone()
    77  			if tt.extRegsDSA == nil {
    78  				assert.Nil(t, clone)
    79  			} else {
    80  				assert.Equal(t, tt.extRegsDSA, clone)
    81  
    82  				if tt.extRegsDSA.Required != nil {
    83  					assert.NotSame(t, tt.extRegsDSA.Required, clone.Required)
    84  				}
    85  				if tt.extRegsDSA.PubRender != nil {
    86  					assert.NotSame(t, tt.extRegsDSA.PubRender, clone.PubRender)
    87  				}
    88  				if tt.extRegsDSA.DataToPub != nil {
    89  					assert.NotSame(t, tt.extRegsDSA.DataToPub, clone.DataToPub)
    90  				}
    91  				if tt.extRegsDSA.Transparency != nil {
    92  					assert.NotSame(t, tt.extRegsDSA.Transparency, clone.Transparency)
    93  				}
    94  			}
    95  		})
    96  	}
    97  }