11package serdes_test
22
33import (
4+ _ "embed"
45 "errors"
56 "io"
67 "net/http"
@@ -11,7 +12,30 @@ import (
1112 "github.com/ncruces/go-sqlite3/ext/serdes"
1213)
1314
14- func TestDeserialize (t * testing.T ) {
15+ //go:embed testdata/wal.db
16+ var walDB []byte
17+
18+ func Test_wal (t * testing.T ) {
19+ db , err := sqlite3 .Open ("testdata/wal.db" )
20+ if err != nil {
21+ t .Fatal (err )
22+ }
23+ defer db .Close ()
24+
25+ data , err := serdes .Serialize (db , "main" )
26+ if err != nil {
27+ t .Fatal (err )
28+ }
29+
30+ compareDBs (t , data , walDB )
31+
32+ err = serdes .Deserialize (db , "main" , walDB )
33+ if err != nil {
34+ t .Fatal (err )
35+ }
36+ }
37+
38+ func Test_northwind (t * testing.T ) {
1539 if testing .Short () {
1640 t .Skip ("skipping in short mode" )
1741 }
@@ -37,10 +61,14 @@ func TestDeserialize(t *testing.T) {
3761 t .Fatal (err )
3862 }
3963
40- if len (input ) != len (output ) {
64+ compareDBs (t , input , output )
65+ }
66+
67+ func compareDBs (t * testing.T , a , b []byte ) {
68+ if len (a ) != len (b ) {
4169 t .Fatal ("lengths are different" )
4270 }
43- for i := range input {
71+ for i := range a {
4472 // These may be different.
4573 switch {
4674 case 24 <= i && i < 28 :
@@ -53,14 +81,14 @@ func TestDeserialize(t *testing.T) {
5381 // SQLite version that wrote the file.
5482 continue
5583 }
56- if input [i ] != output [i ] {
57- t .Errorf ("difference at %d: %d %d" , i , input [i ], output [i ])
84+ if a [i ] != b [i ] {
85+ t .Errorf ("difference at %d: %d %d" , i , a [i ], b [i ])
5886 }
5987 }
6088}
6189
6290func httpGet () ([]byte , error ) {
63- res , err := http .Get ("https://raw.githubusercontent. com/jpwhite3/northwind-SQLite3/refs/heads/main/dist/northwind.db" )
91+ res , err := http .Get ("https://github. com/jpwhite3/northwind-SQLite3/raw /refs/heads/main/dist/northwind.db" )
6492 if err != nil {
6593 return nil , err
6694 }
0 commit comments