github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/schemaexpr/testutils.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 schemaexpr 12 13 import ( 14 "github.com/cockroachdb/cockroach/pkg/sql/sqlbase" 15 "github.com/cockroachdb/cockroach/pkg/sql/types" 16 ) 17 18 // testCol includes the information needed to create a column descriptor for 19 // testing purposes. 20 type testCol struct { 21 name string 22 typ *types.T 23 } 24 25 // testTableDesc is a helper functions for creating table descriptors in a 26 // less verbose way. 27 func testTableDesc( 28 name string, columns []testCol, mutationColumns []testCol, 29 ) sqlbase.MutableTableDescriptor { 30 cols := make([]sqlbase.ColumnDescriptor, len(columns)) 31 for i := range columns { 32 cols[i] = sqlbase.ColumnDescriptor{ 33 Name: columns[i].name, 34 Type: columns[i].typ, 35 ID: sqlbase.ColumnID(i), 36 } 37 } 38 39 muts := make([]sqlbase.DescriptorMutation, len(mutationColumns)) 40 for i := range mutationColumns { 41 muts[i] = sqlbase.DescriptorMutation{ 42 Descriptor_: &sqlbase.DescriptorMutation_Column{ 43 Column: &sqlbase.ColumnDescriptor{ 44 Name: mutationColumns[i].name, 45 Type: mutationColumns[i].typ, 46 ID: sqlbase.ColumnID(len(columns) + i), 47 }, 48 }, 49 Direction: sqlbase.DescriptorMutation_ADD, 50 } 51 } 52 53 return sqlbase.MutableTableDescriptor{ 54 TableDescriptor: sqlbase.TableDescriptor{ 55 Name: name, 56 ID: 1, 57 Columns: cols, 58 Mutations: muts, 59 }, 60 } 61 }