github.com/hasnat/dolt/go@v0.0.0-20210628190320-9eb5d843fbb7/libraries/doltcore/schema/integration_test.go (about) 1 // Copyright 2020 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package schema_test 16 17 import ( 18 "context" 19 "testing" 20 21 "github.com/stretchr/testify/assert" 22 "github.com/stretchr/testify/require" 23 24 "github.com/dolthub/dolt/go/cmd/dolt/commands" 25 "github.com/dolthub/dolt/go/libraries/doltcore/dtestutils" 26 "github.com/dolthub/dolt/go/libraries/doltcore/schema" 27 ) 28 29 func TestSqlIntegration(t *testing.T) { 30 31 const tblName = "test" 32 tests := []struct { 33 name string 34 setup []string 35 isKeyless bool 36 }{ 37 { 38 name: "primary key", 39 setup: []string{"CREATE TABLE test (pk int PRIMARY KEY);"}, 40 isKeyless: false, 41 }, 42 { 43 name: "keyless", 44 setup: []string{"CREATE TABLE test (pk int);"}, 45 isKeyless: true, 46 }, 47 } 48 49 for _, test := range tests { 50 t.Run(test.name, func(t *testing.T) { 51 ctx := context.Background() 52 dEnv := dtestutils.CreateTestEnv() 53 cmd := commands.SqlCmd{} 54 55 for _, query := range test.setup { 56 code := cmd.Exec(ctx, cmd.Name(), []string{"-q", query}, dEnv) 57 require.Equal(t, 0, code) 58 } 59 60 root, err := dEnv.WorkingRoot(ctx) 61 require.NoError(t, err) 62 tbl, ok, err := root.GetTable(ctx, tblName) 63 require.NoError(t, err) 64 require.True(t, ok) 65 sch, err := tbl.GetSchema(ctx) 66 require.NoError(t, err) 67 68 ok = schema.IsKeyless(sch) 69 assert.Equal(t, test.isKeyless, ok) 70 }) 71 } 72 }