github.com/dolthub/go-mysql-server@v0.18.0/memory/regression_test.go (about) 1 // Copyright 2020-2021 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 memory_test 16 17 import ( 18 "context" 19 "testing" 20 21 "github.com/dolthub/go-mysql-server/memory" 22 "github.com/dolthub/go-mysql-server/sql" 23 "github.com/dolthub/go-mysql-server/sql/types" 24 ) 25 26 func TestIssue361(t *testing.T) { 27 name := t.Name() 28 db := memory.NewDatabase("db") 29 pro := memory.NewDBProvider(db) 30 ctx := newContext(pro) 31 32 t.Run("Update", func(*testing.T) { 33 table := memory.NewTable(db, name, sql.NewPrimaryKeySchema(sql.Schema{ 34 {Name: "json", Type: types.JSON, Nullable: false, Source: name}, 35 }), nil) 36 37 old := sql.NewRow(types.JSONDocument{Val: []string{"foo", "bar"}}) 38 new := sql.NewRow(types.JSONDocument{Val: []string{"foo"}}) 39 40 table.Insert(ctx, old) 41 42 up := table.Updater(ctx) 43 up.Update(ctx, old, new) // does not panic 44 }) 45 46 t.Run("Delete", func(*testing.T) { 47 table := memory.NewTable(db, name, sql.NewPrimaryKeySchema(sql.Schema{ 48 {Name: "json", Type: types.JSON, Nullable: false, Source: name}, 49 }), nil) 50 51 row := sql.NewRow(types.JSONDocument{Val: []string{"foo", "bar"}}) 52 53 table.Insert(ctx, row) 54 55 up := table.Deleter(ctx) 56 up.Delete(ctx, row) // does not panic 57 }) 58 } 59 60 func newContext(provider *memory.DbProvider) *sql.Context { 61 return sql.NewContext(context.Background(), sql.WithSession(memory.NewSession(sql.NewBaseSession(), provider))) 62 }