aboutsummaryrefslogtreecommitdiff
path: root/backup_test.go
diff options
context:
space:
mode:
authora-p- <ap+github@fastmail.com>2016-09-23 08:41:32 -0400
committera-p- <ap+github@fastmail.com>2016-09-23 08:41:32 -0400
commit0e686cadf6f510e7a0de1de67882a6075a388a99 (patch)
tree0911f2be4d5c52a36b5d52b62698e668d12542ad /backup_test.go
parentTestAggregatorRegistration may fail if trace feature is not implemented (diff)
downloadgolite-0e686cadf6f510e7a0de1de67882a6075a388a99.tar.gz
golite-0e686cadf6f510e7a0de1de67882a6075a388a99.tar.xz
Test the error reporting when preparing to perform a backup.
Diffstat (limited to 'backup_test.go')
-rw-r--r--backup_test.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/backup_test.go b/backup_test.go
index d14cd06..73c0a4b 100644
--- a/backup_test.go
+++ b/backup_test.go
@@ -245,3 +245,46 @@ func TestBackupStepByStep(t *testing.T) {
func TestBackupAllRemainingPages(t *testing.T) {
testBackup(t, testRowCount, false)
}
+
+// Test the error reporting when preparing to perform a backup.
+func TestBackupError(t *testing.T) {
+ const driverName = "sqlite3_TestBackupError"
+
+ // The driver's connection will be needed in order to perform the backup.
+ var dbDriverConn *SQLiteConn
+ sql.Register(driverName, &SQLiteDriver{
+ ConnectHook: func(conn *SQLiteConn) error {
+ dbDriverConn = conn
+ return nil
+ },
+ })
+
+ // Connect to the database.
+ dbTempFilename := TempFilename(t)
+ defer os.Remove(dbTempFilename)
+ db, err := sql.Open(driverName, dbTempFilename)
+ if err != nil {
+ t.Fatal("Failed to open the database:", err)
+ }
+ defer db.Close()
+ db.Ping()
+
+ // Need the driver connection in order to perform the backup.
+ if dbDriverConn == nil {
+ t.Fatal("Failed to get the driver connection.")
+ }
+
+ // Prepare to perform the backup.
+ // Intentionally using the same connection for both the source and destination databases, to trigger an error result.
+ backup, err := dbDriverConn.Backup("main", dbDriverConn, "main")
+ if err == nil {
+ t.Fatal("Failed to get the expected error result.")
+ }
+ const expectedError = "source and destination must be distinct"
+ if err.Error() != expectedError {
+ t.Fatalf("Unexpected error message; expected value: \"%v\"; actual value: \"%v\"", expectedError, err.Error())
+ }
+ if backup != nil {
+ t.Fatal("Failed to get the expected nil backup result.")
+ }
+}