github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/internal/analytics/client/sync/client_test.go (about)

     1  package sync
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  
     7  	"github.com/ActiveState/cli/internal/analytics/dimensions"
     8  	"github.com/ActiveState/cli/internal/rtutils/ptr"
     9  )
    10  
    11  func Test_mergeDimensions(t *testing.T) {
    12  	type args struct {
    13  		target *dimensions.Values
    14  		dims   []*dimensions.Values
    15  	}
    16  	tests := []struct {
    17  		name string
    18  		args args
    19  		want *dimensions.Values
    20  	}{
    21  		{
    22  			"Sequence favours source",
    23  			args{
    24  				&dimensions.Values{
    25  					Sequence: ptr.To(10),
    26  				},
    27  				[]*dimensions.Values{
    28  					{
    29  						Sequence: ptr.To(100),
    30  					},
    31  				},
    32  			},
    33  			&dimensions.Values{Sequence: ptr.To(100)},
    34  		},
    35  		{
    36  			"Sequence favours source and accepts 0 value",
    37  			args{
    38  				&dimensions.Values{
    39  					Sequence: ptr.To(10),
    40  				},
    41  				[]*dimensions.Values{
    42  					{
    43  						Sequence: ptr.To(0),
    44  					},
    45  				},
    46  			},
    47  			&dimensions.Values{Sequence: ptr.To(0)},
    48  		},
    49  	}
    50  	for _, tt := range tests {
    51  		t.Run(tt.name, func(t *testing.T) {
    52  			before := *tt.args.target.Sequence
    53  			if got := mergeDimensions(tt.args.target, tt.args.dims...); !reflect.DeepEqual(got, tt.want) {
    54  				t.Errorf("mergeDimensions() = %#v, want %#v", got, tt.want)
    55  			}
    56  			if *tt.args.target.Sequence != before {
    57  				t.Errorf("Target struct should not have been modified")
    58  			}
    59  		})
    60  	}
    61  }