forked from patrickxb/fgosqlite
-
Notifications
You must be signed in to change notification settings - Fork 12
/
backup_test.go
55 lines (45 loc) · 1.21 KB
/
backup_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package sqlite_test
import (
"testing"
"github.com/bmizerany/assert"
. "github.com/gwenn/gosqlite"
)
func TestBackup(t *testing.T) {
dst := open(t)
defer checkClose(dst, t)
src := open(t)
defer checkClose(src, t)
fill(nil, src, 1000)
bck, err := NewBackup(dst, "main", src, "main")
checkNoError(t, err, "couldn't init backup: %#v")
cbs := make(chan BackupStatus)
defer close(cbs)
go func() {
for {
s := <-cbs
t.Logf("Backup progress %#v\n", s)
if s.Remaining == 0 {
break
}
}
}()
err = bck.Run(10, 0, cbs)
checkNoError(t, err, "couldn't do backup: %#v")
err = bck.Close()
checkNoError(t, err, "couldn't close backup twice: %#v")
}
func TestBackupMisuse(t *testing.T) {
db := open(t)
defer checkClose(db, t)
bck, err := NewBackup(db, "", db, "")
assert.T(t, bck == nil && err != nil, "source and destination must be distinct")
err = bck.Run(10, 0, nil)
assert.T(t, err != nil, "misuse expected")
//println(err.Error())
_, err = NewBackup(db, "", nil, "")
assert.T(t, err != nil, "error expected")
//println(err.Error())
}