mirror of
https://github.com/ncruces/go-sqlite3.git
synced 2026-01-12 22:19:14 +00:00
69 lines
1.3 KiB
Go
69 lines
1.3 KiB
Go
package serdes_test
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/ncruces/go-sqlite3"
|
|
_ "github.com/ncruces/go-sqlite3/embed"
|
|
"github.com/ncruces/go-sqlite3/ext/serdes"
|
|
)
|
|
|
|
func TestDeserialize(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("skipping in short mode")
|
|
}
|
|
|
|
input, err := httpGet()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
db, err := sqlite3.Open(":memory:")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer db.Close()
|
|
|
|
err = serdes.Deserialize(db, "temp", input)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
output, err := serdes.Serialize(db, "temp")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if len(input) != len(output) {
|
|
t.Fatal("lengths are different")
|
|
}
|
|
for i := range input {
|
|
// These may be different.
|
|
switch {
|
|
case 24 <= i && i < 28:
|
|
// File change counter.
|
|
continue
|
|
case 40 <= i && i < 44:
|
|
// Schema cookie.
|
|
continue
|
|
case 92 <= i && i < 100:
|
|
// SQLite version that wrote the file.
|
|
continue
|
|
}
|
|
if input[i] != output[i] {
|
|
t.Errorf("difference at %d: %d %d", i, input[i], output[i])
|
|
}
|
|
}
|
|
}
|
|
|
|
func httpGet() ([]byte, error) {
|
|
res, err := http.Get("https://raw.githubusercontent.com/jpwhite3/northwind-SQLite3/refs/heads/main/dist/northwind.db")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer res.Body.Close()
|
|
return io.ReadAll(res.Body)
|
|
}
|