github.com/vescale/zgraph@v0.0.0-20230410094002-959c02d50f95/driver_test.go (about) 1 // Copyright 2023 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 zgraph_test 16 17 import ( 18 "context" 19 "database/sql" 20 "testing" 21 22 "github.com/samber/lo" 23 "github.com/stretchr/testify/require" 24 ) 25 26 func TestDriver(t *testing.T) { 27 db, err := sql.Open("zgraph", t.TempDir()) 28 require.NoError(t, err) 29 defer db.Close() 30 31 ctx, cancel := context.WithCancel(context.Background()) 32 defer cancel() 33 34 conn := lo.Must1(db.Conn(ctx)) 35 _ = lo.Must1(conn.ExecContext(ctx, "CREATE GRAPH g")) 36 _ = lo.Must1(conn.ExecContext(ctx, "USE g")) 37 _ = lo.Must1(conn.ExecContext(ctx, "INSERT VERTEX x PROPERTIES (x.a = 123)")) 38 rows := lo.Must1(conn.QueryContext(ctx, "SELECT x.a FROM MATCH (x)")) 39 40 var a int 41 require.True(t, rows.Next()) 42 require.NoError(t, rows.Scan(&a)) 43 require.Equal(t, 123, a) 44 require.False(t, rows.Next()) 45 require.NoError(t, rows.Err()) 46 }