forked from mirror/go-sqlite3
Rewrite TestBackupError for Golang:1.8
This commit is contained in:
parent
c5e0c421d6
commit
d6c4423838
|
@ -253,7 +253,7 @@ func TestBackupAllRemainingPages(t *testing.T) {
|
||||||
|
|
||||||
// Test the error reporting when preparing to perform a backup.
|
// Test the error reporting when preparing to perform a backup.
|
||||||
func TestBackupError(t *testing.T) {
|
func TestBackupError(t *testing.T) {
|
||||||
const driverName = "sqlite3_TestBackupError"
|
driverName := "sqlite3_TestBackupError"
|
||||||
|
|
||||||
// The driver's connection will be needed in order to perform the backup.
|
// The driver's connection will be needed in order to perform the backup.
|
||||||
var dbDriverConn []*SQLiteConn
|
var dbDriverConn []*SQLiteConn
|
||||||
|
@ -325,27 +325,41 @@ func TestBackupError(t *testing.T) {
|
||||||
destTempFilename := TempFilename(t)
|
destTempFilename := TempFilename(t)
|
||||||
defer os.Remove(destTempFilename)
|
defer os.Remove(destTempFilename)
|
||||||
|
|
||||||
// TODO: Rewrite for Golang:1.8
|
// Create Database
|
||||||
// Current part of test uses golang:1.10
|
destDb, err := sql.Open(driverName, fmt.Sprintf("file:%s", destTempFilename))
|
||||||
destCfg := NewConfig()
|
if err != nil {
|
||||||
destCfg.Database = destTempFilename
|
t.Fatal("Failed to open the database:", err)
|
||||||
destDB := sql.OpenDB(destCfg) // Needs to be rewritten
|
}
|
||||||
destDB.Close()
|
destDb.Ping()
|
||||||
|
_, err = destDb.Exec("SELECT 1;") // Create Database
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
destDb.Close()
|
||||||
|
|
||||||
// Reconfigure to open READ-ONLY
|
var destDriverConn *SQLiteConn
|
||||||
destCfg.Mode = ModeReadOnly
|
driverName = "sqlite3_dest_readonly"
|
||||||
var destConn *SQLiteConn
|
sql.Register(driverName, &SQLiteDriver{
|
||||||
destCfg.ConnectHook = func(conn *SQLiteConn) error {
|
ConnectHook: func(conn *SQLiteConn) error {
|
||||||
destConn = conn
|
destDriverConn = conn
|
||||||
return nil
|
return nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// Re-Open as ReadOnly
|
||||||
|
destDb, err = sql.Open(driverName, fmt.Sprintf("file:%s?mode=ro", destTempFilename))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal("Failed to open the database:", err)
|
||||||
|
}
|
||||||
|
destDb.Ping()
|
||||||
|
defer destDb.Close()
|
||||||
|
|
||||||
|
// Need the driver connection in order to perform the backup.
|
||||||
|
if destDriverConn == nil {
|
||||||
|
t.Fatal("Failed to get the driver connection.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenDB with Config
|
backup, err = destDriverConn.Backup("main", srcDriverConn, "main")
|
||||||
destDB = sql.OpenDB(destCfg)
|
|
||||||
destDB.Ping()
|
|
||||||
defer destDB.Close()
|
|
||||||
|
|
||||||
backup, err = destConn.Backup("main", srcDriverConn, "main")
|
|
||||||
_, err = backup.Step(0)
|
_, err = backup.Step(0)
|
||||||
if err == nil || err.(Error).Code != ErrReadonly {
|
if err == nil || err.(Error).Code != ErrReadonly {
|
||||||
t.Fatalf("Expected read-only error; received: (%d) %s", err.(Error).Code, err.(Error).Error())
|
t.Fatalf("Expected read-only error; received: (%d) %s", err.(Error).Code, err.(Error).Error())
|
||||||
|
|
Loading…
Reference in New Issue