-
Notifications
You must be signed in to change notification settings - Fork 27
/
chunkindex_test.go
125 lines (105 loc) · 2.59 KB
/
chunkindex_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* knoxite
* Copyright (c) 2017-2018, Christian Muehlhaeuser <[email protected]>
*
* For license see LICENSE
*/
package knoxite
import (
"io/ioutil"
"os"
"testing"
)
func TestChunkIndexReindex(t *testing.T) {
testPassword := "this_is_a_password"
dir, err := ioutil.TempDir("", "knoxite")
if err != nil {
t.Errorf("Failed creating temporary dir for repository: %s", err)
return
}
defer os.RemoveAll(dir)
r, _ := NewRepository(dir, testPassword)
vol, _ := NewVolume("test", "")
_ = r.AddVolume(vol)
snapshot, _ := NewSnapshot("test_snapshot")
index, _ := OpenChunkIndex(&r)
wd, _ := os.Getwd()
opts := StoreOptions{
CWD: wd,
Paths: []string{"snapshot_test.go", "snapshot.go"},
Excludes: []string{},
Compress: CompressionNone,
Encrypt: EncryptionAES,
Pedantic: false,
DataParts: 1,
ParityParts: 0,
}
progress := snapshot.Add(r, &index, opts)
for p := range progress {
if p.Error != nil {
t.Errorf("Failed adding to snapshot: %s", p.Error)
}
}
_ = snapshot.Save(&r)
_ = vol.AddSnapshot(snapshot.ID)
_ = index.Save(&r)
_ = r.Save()
newindex, err := OpenChunkIndex(&r)
if err != nil {
t.Errorf("Failed reopening chunk-index: %s", err)
}
err = newindex.reindex(&r)
if err != nil {
t.Errorf("Failed reindexing chunk-index: %s", err)
}
}
func TestChunkIndexPack(t *testing.T) {
testPassword := "this_is_a_password"
dir, err := ioutil.TempDir("", "knoxite")
if err != nil {
t.Errorf("Failed creating temporary dir for repository: %s", err)
return
}
defer os.RemoveAll(dir)
r, _ := NewRepository(dir, testPassword)
vol, _ := NewVolume("test", "")
_ = r.AddVolume(vol)
snapshot, _ := NewSnapshot("test_snapshot")
index, err := OpenChunkIndex(&r)
if err != nil {
t.Errorf("Failed opening chunk-index: %s", err)
return
}
wd, err := os.Getwd()
if err != nil {
t.Errorf("Failed getting working dir: %s", err)
return
}
opts := StoreOptions{
CWD: wd,
Paths: []string{"snapshot_test.go", "snapshot.go"},
Excludes: []string{},
Compress: CompressionNone,
Encrypt: EncryptionAES,
Pedantic: false,
DataParts: 1,
ParityParts: 0,
}
progress := snapshot.Add(r, &index, opts)
for p := range progress {
if p.Error != nil {
t.Errorf("Failed adding to snapshot: %s", p.Error)
}
}
_ = snapshot.Save(&r)
_ = vol.AddSnapshot(snapshot.ID)
err = vol.RemoveSnapshot(snapshot.ID)
if err != nil {
t.Errorf("Failed removing snapshot: %s", err)
}
index.RemoveSnapshot(snapshot.ID)
_, err = index.Pack(&r)
if err != nil {
t.Errorf("Packing chunk index failed: %s", err)
}
}