github.com/vescale/zgraph@v0.0.0-20230410094002-959c02d50f95/executor/simple_test.go (about) 1 // Copyright 2022 zGraph Authors. All rights reserved. 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 executor_test 16 17 import ( 18 "context" 19 "testing" 20 21 "github.com/stretchr/testify/assert" 22 "github.com/vescale/zgraph" 23 "github.com/vescale/zgraph/compiler" 24 "github.com/vescale/zgraph/parser" 25 "github.com/vescale/zgraph/session" 26 ) 27 28 func TestSimpleExec(t *testing.T) { 29 assert := assert.New(t) 30 db, err := zgraph.Open(t.TempDir(), nil) 31 assert.Nil(err) 32 33 catalog := db.Catalog() 34 35 cases := []struct { 36 query string 37 check func(session *session.Session) 38 }{ 39 { 40 query: "create graph g1", 41 check: func(_ *session.Session) { 42 assert.NotNil(catalog.Graph("g1")) 43 }, 44 }, 45 { 46 query: "use g1", 47 check: func(s *session.Session) { 48 assert.Equal("g1", s.StmtContext().CurrentGraphName()) 49 }, 50 }, 51 } 52 53 ctx := context.Background() 54 for _, c := range cases { 55 parser := parser.New() 56 stmt, err := parser.ParseOneStmt(c.query) 57 assert.Nil(err) 58 59 s := db.NewSession() 60 sc := s.StmtContext() 61 exec, err := compiler.Compile(sc, stmt) 62 assert.Nil(err) 63 64 err = exec.Open(ctx) 65 assert.Nil(err) 66 _, err = exec.Next(ctx) 67 assert.Nil(err) 68 69 if c.check != nil { 70 c.check(s) 71 } 72 } 73 }