github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/create_table_test.go (about) 1 // Copyright 2020 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 sql 12 13 import ( 14 "fmt" 15 "testing" 16 17 "github.com/cockroachdb/cockroach/pkg/clusterversion" 18 "github.com/cockroachdb/cockroach/pkg/sql/types" 19 "github.com/cockroachdb/cockroach/pkg/util/leaktest" 20 "github.com/stretchr/testify/require" 21 ) 22 23 func TestIsTypeSupportedInVersion(t *testing.T) { 24 defer leaktest.AfterTest(t)() 25 26 testCases := []struct { 27 v clusterversion.VersionKey 28 t *types.T 29 30 ok bool 31 }{ 32 {clusterversion.Version19_2, types.Time, true}, 33 {clusterversion.Version19_2, types.Timestamp, true}, 34 {clusterversion.Version19_2, types.Interval, true}, 35 36 {clusterversion.Version19_2, types.TimeTZ, false}, 37 {clusterversion.VersionTimeTZType, types.TimeTZ, true}, 38 39 {clusterversion.Version19_2, types.MakeTime(0), false}, 40 {clusterversion.Version19_2, types.MakeTimeTZ(0), false}, 41 {clusterversion.VersionTimeTZType, types.MakeTimeTZ(0), false}, 42 {clusterversion.Version19_2, types.MakeTimestamp(0), false}, 43 {clusterversion.Version19_2, types.MakeTimestampTZ(0), false}, 44 { 45 clusterversion.Version19_2, 46 types.MakeInterval(types.IntervalTypeMetadata{Precision: 3, PrecisionIsSet: true}), 47 false, 48 }, 49 { 50 clusterversion.Version19_2, 51 types.MakeInterval( 52 types.IntervalTypeMetadata{ 53 DurationField: types.IntervalDurationField{DurationType: types.IntervalDurationType_SECOND}, 54 }, 55 ), 56 false, 57 }, 58 {clusterversion.VersionTimePrecision, types.MakeTime(0), true}, 59 {clusterversion.VersionTimePrecision, types.MakeTimeTZ(0), true}, 60 {clusterversion.VersionTimePrecision, types.MakeTimestamp(0), true}, 61 {clusterversion.VersionTimePrecision, types.MakeTimestampTZ(0), true}, 62 { 63 clusterversion.VersionTimePrecision, 64 types.MakeInterval(types.IntervalTypeMetadata{Precision: 3, PrecisionIsSet: true}), 65 true, 66 }, 67 { 68 clusterversion.VersionTimePrecision, 69 types.MakeInterval( 70 types.IntervalTypeMetadata{ 71 DurationField: types.IntervalDurationField{DurationType: types.IntervalDurationType_SECOND}, 72 }, 73 ), 74 true, 75 }, 76 } 77 78 for _, tc := range testCases { 79 t.Run(fmt.Sprintf("%s:%s", tc.v, tc.t.SQLString()), func(t *testing.T) { 80 ok, err := isTypeSupportedInVersion( 81 clusterversion.ClusterVersion{Version: clusterversion.VersionByKey(tc.v)}, 82 tc.t, 83 ) 84 require.NoError(t, err) 85 require.Equal(t, tc.ok, ok) 86 }) 87 } 88 }