-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsnapshot_test.go
More file actions
61 lines (51 loc) · 1.32 KB
/
snapshot_test.go
File metadata and controls
61 lines (51 loc) · 1.32 KB
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
56
57
58
59
60
61
package backpack_test
import (
"path/filepath"
"regexp"
"testing"
bp "github.com/easyselfhost/backpack"
bt "github.com/easyselfhost/backpack/testing"
_ "github.com/mattn/go-sqlite3"
)
var snapshotFiles = map[string]string{
"dir1/a.txt": "file1",
"dir2/b.conf": "file 2",
"dir3/.c": ".c",
".d": "another file",
}
const snapshotDbFiles = "dir1/path/db.sqlite3"
func TestSnaphost(t *testing.T) {
srcDir, destDir, err := bt.GenTestDirs()
if err != nil {
t.Fatal(err)
}
err = bt.GenTextFiles(srcDir, snapshotFiles)
if err != nil {
t.Fatal(err)
}
err = bt.GenDbFile(filepath.Join(srcDir, snapshotDbFiles))
if err != nil {
t.Fatal(err)
}
err = bp.SnapshotDir(bp.DirRule{
SrcDir: srcDir,
FileRules: []bp.FileRule{
{
Regex: regexp.MustCompile(".*\\.sqlite3"),
Command: bp.Sqlite,
},
{
Regex: regexp.MustCompile("dir3/.*"),
Command: bp.Ignore,
},
},
}, destDir)
if err != nil {
t.Fatal(err)
}
bt.VerifyTextFile(t, filepath.Join(destDir, "dir1/a.txt"), snapshotFiles["dir1/a.txt"])
bt.VerifyTextFile(t, filepath.Join(destDir, "dir2/b.conf"), snapshotFiles["dir2/b.conf"])
bt.VerifyTextFile(t, filepath.Join(destDir, ".d"), snapshotFiles[".d"])
bt.VerifyIgnoredFile(t, filepath.Join(destDir, "dir3/.c"))
bt.VerifyDbFile(t, filepath.Join(destDir, snapshotDbFiles))
}