aboutsummaryrefslogtreecommitdiff
path: root/sqlite3_opt_serialize_test.go
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-08-12 15:42:56 -0300
committerEuAndreh <eu@euandre.org>2024-08-12 15:52:16 -0300
commit6bbc33b9e998af7ee45cca86e1290474603dff48 (patch)
tree5d0aff47783bc20dcf3f7862afdba0445e4c2fae /sqlite3_opt_serialize_test.go
parentAdd Makefile and build skeleton (diff)
downloadgolite-6bbc33b9e998af7ee45cca86e1290474603dff48.tar.gz
golite-6bbc33b9e998af7ee45cca86e1290474603dff48.tar.xz
Build with "go tool" and hackishly bundle code from same package into one file each
Diffstat (limited to 'sqlite3_opt_serialize_test.go')
-rw-r--r--sqlite3_opt_serialize_test.go100
1 files changed, 0 insertions, 100 deletions
diff --git a/sqlite3_opt_serialize_test.go b/sqlite3_opt_serialize_test.go
deleted file mode 100644
index 5c7efec..0000000
--- a/sqlite3_opt_serialize_test.go
+++ /dev/null
@@ -1,100 +0,0 @@
-//go:build !libsqlite3 || sqlite_serialize
-// +build !libsqlite3 sqlite_serialize
-
-package sqlite3
-
-import (
- "context"
- "database/sql"
- "os"
- "testing"
-)
-
-func TestSerializeDeserialize(t *testing.T) {
- // Connect to the source database.
- srcTempFilename := TempFilename(t)
- defer os.Remove(srcTempFilename)
- srcDb, err := sql.Open(driverName, srcTempFilename)
- if err != nil {
- t.Fatal("Failed to open the source database:", err)
- }
- defer srcDb.Close()
- err = srcDb.Ping()
- if err != nil {
- t.Fatal("Failed to connect to the source database:", err)
- }
-
- // Connect to the destination database.
- destTempFilename := TempFilename(t)
- defer os.Remove(destTempFilename)
- destDb, err := sql.Open(driverName, destTempFilename)
- if err != nil {
- t.Fatal("Failed to open the destination database:", err)
- }
- defer destDb.Close()
- err = destDb.Ping()
- if err != nil {
- t.Fatal("Failed to connect to the destination database:", err)
- }
-
- // Write data to source database.
- _, err = srcDb.Exec(`CREATE TABLE foo (name string)`)
- if err != nil {
- t.Fatal("Failed to create table in source database:", err)
- }
- _, err = srcDb.Exec(`INSERT INTO foo(name) VALUES("alice")`)
- if err != nil {
- t.Fatal("Failed to insert data into source database", err)
- }
-
- // Serialize the source database
- srcConn, err := srcDb.Conn(context.Background())
- if err != nil {
- t.Fatal("Failed to get connection to source database:", err)
- }
- defer srcConn.Close()
-
- var serialized []byte
- if err := srcConn.Raw(func(raw any) error {
- var err error
- serialized, err = raw.(*SQLiteConn).Serialize("")
- return err
- }); err != nil {
- t.Fatal("Failed to serialize source database:", err)
- }
- srcConn.Close()
-
- // Confirm that the destination database is initially empty.
- var destTableCount int
- err = destDb.QueryRow("SELECT COUNT(*) FROM sqlite_master WHERE type = 'table'").Scan(&destTableCount)
- if err != nil {
- t.Fatal("Failed to check the destination table count:", err)
- }
- if destTableCount != 0 {
- t.Fatalf("The destination database is not empty; %v table(s) found.", destTableCount)
- }
-
- // Deserialize to destination database
- destConn, err := destDb.Conn(context.Background())
- if err != nil {
- t.Fatal("Failed to get connection to destination database:", err)
- }
- defer destConn.Close()
-
- if err := destConn.Raw(func(raw any) error {
- return raw.(*SQLiteConn).Deserialize(serialized, "")
- }); err != nil {
- t.Fatal("Failed to deserialize source database:", err)
- }
- destConn.Close()
-
- // Confirm that destination database has been loaded correctly.
- var destRowCount int
- err = destDb.QueryRow(`SELECT COUNT(*) FROM foo`).Scan(&destRowCount)
- if err != nil {
- t.Fatal("Failed to count rows in destination database table", err)
- }
- if destRowCount != 1 {
- t.Fatalf("Destination table does not have the expected records")
- }
-}