1
1
package serdes_test
2
2
3
3
import (
4
+ _ "embed"
4
5
"errors"
5
6
"io"
6
7
"net/http"
@@ -11,7 +12,30 @@ import (
11
12
"github.com/ncruces/go-sqlite3/ext/serdes"
12
13
)
13
14
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 ) {
15
39
if testing .Short () {
16
40
t .Skip ("skipping in short mode" )
17
41
}
@@ -37,10 +61,14 @@ func TestDeserialize(t *testing.T) {
37
61
t .Fatal (err )
38
62
}
39
63
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 ) {
41
69
t .Fatal ("lengths are different" )
42
70
}
43
- for i := range input {
71
+ for i := range a {
44
72
// These may be different.
45
73
switch {
46
74
case 24 <= i && i < 28 :
@@ -53,14 +81,14 @@ func TestDeserialize(t *testing.T) {
53
81
// SQLite version that wrote the file.
54
82
continue
55
83
}
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 ])
58
86
}
59
87
}
60
88
}
61
89
62
90
func 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" )
64
92
if err != nil {
65
93
return nil , err
66
94
}
0 commit comments