github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/ccl/importccl/csv_internal_test.go (about) 1 // Copyright 2017 The Cockroach Authors. 2 // 3 // Licensed as a CockroachDB Enterprise file under the Cockroach Community 4 // License (the "License"); you may not use this file except in compliance with 5 // the License. You may obtain a copy of the License at 6 // 7 // https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt 8 9 package importccl 10 11 import ( 12 "context" 13 "testing" 14 15 "github.com/cockroachdb/cockroach/pkg/settings/cluster" 16 "github.com/cockroachdb/cockroach/pkg/sql/parser" 17 "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" 18 "github.com/cockroachdb/cockroach/pkg/testutils" 19 "github.com/cockroachdb/cockroach/pkg/util/leaktest" 20 ) 21 22 func TestMakeSimpleTableDescriptorErrors(t *testing.T) { 23 defer leaktest.AfterTest(t)() 24 25 tests := []struct { 26 stmt string 27 error string 28 }{ 29 { 30 stmt: "create table if not exists a (i int)", 31 error: "unsupported IF NOT EXISTS", 32 }, 33 { 34 stmt: "create table a (i int) interleave in parent b (id)", 35 error: "interleaved not supported", 36 }, 37 { 38 stmt: "create table a as select 1", 39 error: "CREATE AS not supported", 40 }, 41 { 42 stmt: "create table a (i int references b (id))", 43 error: `this IMPORT format does not support foreign keys`, 44 }, 45 { 46 stmt: "create table a (i int, constraint a foreign key (i) references c (id))", 47 error: `this IMPORT format does not support foreign keys`, 48 }, 49 { 50 stmt: `create table a ( 51 i int check (i > 0), 52 b int default 1, 53 c serial, 54 constraint a check (i < 0), 55 primary key (i), 56 unique index (i), 57 index (i), 58 family (i) 59 )`, 60 }, 61 } 62 ctx := context.Background() 63 st := cluster.MakeTestingClusterSettings() 64 for _, tc := range tests { 65 t.Run(tc.stmt, func(t *testing.T) { 66 stmt, err := parser.ParseOne(tc.stmt) 67 if err != nil { 68 t.Fatal(err) 69 } 70 create, ok := stmt.AST.(*tree.CreateTable) 71 if !ok { 72 t.Fatal("expected CREATE TABLE statement in table file") 73 } 74 _, err = MakeSimpleTableDescriptor(ctx, st, create, defaultCSVParentID, defaultCSVTableID, NoFKs, 0) 75 if !testutils.IsError(err, tc.error) { 76 t.Fatalf("expected %v, got %+v", tc.error, err) 77 } 78 }) 79 } 80 }