-
Notifications
You must be signed in to change notification settings - Fork 44
/
mount-index_linux_test.go
77 lines (67 loc) · 1.42 KB
/
mount-index_linux_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
package desync
import (
"bytes"
"context"
"crypto/sha256"
"io/ioutil"
"os"
"path/filepath"
"sync"
"testing"
"time"
)
func TestMountIndex(t *testing.T) {
// Create the mount point
mnt, err := ioutil.TempDir("", "mount-index-store")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(mnt)
// Define the store
s, err := NewLocalStore("testdata/blob1.store", StoreOptions{})
if err != nil {
t.Fatal(err)
}
defer s.Close()
// Read the index
f, err := os.Open("testdata/blob1.caibx")
if err != nil {
t.Fatal(err)
}
defer f.Close()
index, err := IndexFromReader(f)
if err != nil {
t.Fatal(err)
}
// Calculate the expected hash
b, err := ioutil.ReadFile("testdata/blob1")
if err != nil {
t.Fatal(err)
}
wantHash := sha256.Sum256(b)
// Make sure that the unmount happens on exit
var wg sync.WaitGroup
wg.Add(1)
ctx, cancel := context.WithCancel(context.Background())
defer func() {
cancel()
wg.Wait()
}()
// Start the Fuse mount
go func() {
ifs := NewIndexMountFS(index, "blob1", s)
MountIndex(ctx, index, ifs, mnt, s, 10)
wg.Done()
}()
time.Sleep(time.Second)
// Calculate the hash of the file in the mount point
b, err = ioutil.ReadFile(filepath.Join(mnt, "blob1"))
if err != nil {
t.Fatal(err)
}
gotHash := sha256.Sum256(b)
// Compare the checksums
if !bytes.Equal(gotHash[:], wantHash[:]) {
t.Fatalf("unexpected hash of mounted file. Want %x, got %x", gotHash, wantHash)
}
}