github.com/hasnat/dolt/go@v0.0.0-20210628190320-9eb5d843fbb7/libraries/doltcore/sqle/views_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 sqle 16 17 import ( 18 "context" 19 "testing" 20 21 "github.com/dolthub/go-mysql-server/sql" 22 "github.com/stretchr/testify/assert" 23 "github.com/stretchr/testify/require" 24 25 "github.com/dolthub/dolt/go/libraries/doltcore/dtestutils" 26 ) 27 28 // Not an exhaustive test of views -- we rely on bats tests for end-to-end verification. 29 func TestViews(t *testing.T) { 30 dEnv := dtestutils.CreateTestEnv() 31 32 ctx := context.Background() 33 root, _ := dEnv.WorkingRoot(ctx) 34 35 var err error 36 root, err = ExecuteSql(dEnv, root, "create table test (a int primary key)") 37 require.NoError(t, err) 38 39 root, err = ExecuteSql(dEnv, root, "insert into test values (1), (2), (3)") 40 require.NoError(t, err) 41 42 root, err = ExecuteSql(dEnv, root, "create view plus1 as select a + 1 from test") 43 require.NoError(t, err) 44 45 expectedRows := []sql.Row{ 46 {int64(2)}, 47 {int64(3)}, 48 {int64(4)}, 49 } 50 rows, _, err := executeSelect(context.Background(), dEnv, root, "select * from plus1") 51 require.NoError(t, err) 52 assert.Equal(t, expectedRows, rows) 53 54 root, err = ExecuteSql(dEnv, root, "drop view plus1") 55 require.NoError(t, err) 56 }