105 lines
2.1 KiB
Go
Executable File
105 lines
2.1 KiB
Go
Executable File
package _go
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/dolthub/go-mysql-server/sql"
|
|
)
|
|
|
|
func TestDiscard(t *testing.T) {
|
|
RunScripts(t, []ScriptTest{
|
|
{
|
|
Name: "Test discard",
|
|
SetUpScript: []string{
|
|
`CREATE temporary TABLE test (a INT)`,
|
|
`insert into test values (1)`,
|
|
},
|
|
Assertions: []ScriptTestAssertion{
|
|
{
|
|
Query: "select * from test",
|
|
Expected: []sql.Row{
|
|
{1},
|
|
},
|
|
},
|
|
{
|
|
Query: "DISCARD ALL",
|
|
Expected: []sql.Row{},
|
|
},
|
|
{
|
|
Query: "select * from test",
|
|
ExpectedErr: "table not found",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
Name: "Test discard errors",
|
|
SetUpScript: []string{
|
|
`CREATE temporary TABLE test (a INT)`,
|
|
`insert into test values (1)`,
|
|
},
|
|
Assertions: []ScriptTestAssertion{
|
|
{
|
|
Query: "DISCARD SEQUENCES",
|
|
ExpectedErr: "unimplemented",
|
|
},
|
|
{
|
|
Query: "select * from test",
|
|
Expected: []sql.Row{
|
|
{1},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
Name: "Test discard in transaction",
|
|
SetUpScript: []string{
|
|
`CREATE temporary TABLE test (a INT)`,
|
|
`insert into test values (1)`,
|
|
},
|
|
Assertions: []ScriptTestAssertion{
|
|
{
|
|
Query: "BEGIN",
|
|
},
|
|
{
|
|
Query: "DISCARD ALL",
|
|
ExpectedErr: "DISCARD ALL cannot run inside a transaction block",
|
|
Skip: true, // not yet implemented
|
|
},
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestRollback(t *testing.T) {
|
|
RunScripts(t, []ScriptTest{
|
|
{
|
|
Name: "Test rollback transaction",
|
|
SetUpScript: []string{
|
|
`BEGIN`,
|
|
`CREATE temporary TABLE test (a INT)`,
|
|
`insert into test values (1)`,
|
|
},
|
|
Assertions: []ScriptTestAssertion{
|
|
{
|
|
Query: "select * from test",
|
|
Expected: []sql.Row{{1}},
|
|
},
|
|
{
|
|
Query: "ROLLBACK",
|
|
Expected: []sql.Row{},
|
|
},
|
|
{
|
|
Query: "select * from test",
|
|
ExpectedErr: "table not found",
|
|
Skip: true, // temp table should be dropped after ROLLBACK
|
|
},
|
|
{
|
|
Query: "create temp table test (b int)",
|
|
Expected: []sql.Row{},
|
|
Skip: true, // temp table should be dropped after ROLLBACK
|
|
},
|
|
},
|
|
},
|
|
})
|
|
}
|