github.com/dolthub/go-mysql-server@v0.18.0/sql/types/session_test.go (about) 1 // Copyright 2022 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 types 16 17 import ( 18 "testing" 19 20 "github.com/stretchr/testify/require" 21 22 "github.com/dolthub/go-mysql-server/sql" 23 ) 24 25 func TestSessionConfig(t *testing.T) { 26 require := require.New(t) 27 ctx := sql.NewEmptyContext() 28 29 sess := sql.NewBaseSessionWithClientServer("foo", sql.Client{Address: "baz", User: "bar"}, 1) 30 typ, v, err := sess.GetUserVariable(ctx, "foo") 31 require.NoError(err) 32 require.Nil(typ) 33 require.Equal(nil, v) 34 35 err = sess.SetUserVariable(ctx, "foo", int64(1), Int64) 36 require.NoError(err) 37 38 typ, v, err = sess.GetUserVariable(ctx, "foo") 39 require.NoError(err) 40 require.Equal(Int64, typ) 41 require.Equal(int64(1), v) 42 43 err = sess.SetUserVariable(ctx, "foo", nil, Int64) 44 require.NoError(err) 45 46 typ, v, err = sess.GetUserVariable(ctx, "foo") 47 require.NoError(err) 48 require.Equal(Int64, typ) 49 require.Equal(nil, v) 50 51 require.Equal(uint16(0), sess.WarningCount()) 52 53 sess.Warn(&sql.Warning{Code: 1}) 54 sess.Warn(&sql.Warning{Code: 2}) 55 sess.Warn(&sql.Warning{Code: 3}) 56 57 require.Equal(uint16(3), sess.WarningCount()) 58 59 require.Equal(3, sess.Warnings()[0].Code) 60 require.Equal(2, sess.Warnings()[1].Code) 61 require.Equal(1, sess.Warnings()[2].Code) 62 }