github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/sqlbase/result_columns_test.go (about)

     1  // Copyright 2017 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package sqlbase
    12  
    13  import (
    14  	"fmt"
    15  	"testing"
    16  
    17  	"github.com/cockroachdb/cockroach/pkg/sql/types"
    18  )
    19  
    20  func TestResultColumnsTypesEqual(t *testing.T) {
    21  	tests := []struct {
    22  		r, o  ResultColumns
    23  		equal bool
    24  	}{
    25  		{
    26  			r:     ResultColumns{{Typ: types.Int}},
    27  			o:     ResultColumns{{Typ: types.Int}},
    28  			equal: true,
    29  		},
    30  		{
    31  			r:     ResultColumns{{Typ: types.Int}},
    32  			o:     ResultColumns{{Typ: types.String}},
    33  			equal: false,
    34  		},
    35  		{
    36  			r:     ResultColumns{{Typ: types.Unknown}},
    37  			o:     ResultColumns{{Typ: types.Int}},
    38  			equal: false,
    39  		},
    40  		{
    41  			r:     ResultColumns{{Typ: types.Int}},
    42  			o:     ResultColumns{{Typ: types.Unknown}},
    43  			equal: true,
    44  		},
    45  		{
    46  			r:     ResultColumns{{Typ: types.Unknown}},
    47  			o:     ResultColumns{{Typ: types.Unknown}},
    48  			equal: true,
    49  		},
    50  		{
    51  			r:     ResultColumns{{Typ: types.Int}, {Typ: types.Int}},
    52  			o:     ResultColumns{{Typ: types.Int}},
    53  			equal: false,
    54  		},
    55  		{
    56  			r:     ResultColumns{},
    57  			o:     ResultColumns{{Typ: types.Unknown}},
    58  			equal: false,
    59  		},
    60  	}
    61  	for _, tc := range tests {
    62  		t.Run(fmt.Sprintf("%v-%v", tc.r, tc.o), func(t *testing.T) {
    63  			eq := tc.r.TypesEqual(tc.o)
    64  			if eq != tc.equal {
    65  				t.Fatalf("expected %v, got %v", tc.equal, eq)
    66  			}
    67  		})
    68  	}
    69  }