-
Notifications
You must be signed in to change notification settings - Fork 35
/
db_test.go
59 lines (48 loc) · 1.25 KB
/
db_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
// Copyright ©2018 The go-hep 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 rsrv
import (
"io/ioutil"
"os"
"reflect"
"testing"
"go-hep.org/x/hep/groot/riofs"
)
func TestDB(t *testing.T) {
dir, err := ioutil.TempDir("", "groot-rsrv-db-")
if err != nil {
t.Fatalf("%+v", err)
}
os.RemoveAll(dir)
db := NewDB(dir)
if got, want := len(db.Files()), 0; got != want {
t.Fatalf("invalid number of files. got=%d, want=%d", got, want)
}
f, err := riofs.Open("../testdata/simple.root")
if err != nil {
t.Fatalf("could not open ROOT file: %v", err)
}
defer f.Close()
const uri = "upload-store:///simple.root"
db.set(uri, f)
if got, want := db.Files(), []string{uri}; !reflect.DeepEqual(got, want) {
t.Fatalf("invalid list of files. got=%v, want=%v", got, want)
}
wantFname := f.Name()
err = db.Tx(uri, func(f *riofs.File) error {
got := f.Name()
if got != wantFname {
t.Fatalf("invalid filename in transaction. got=%q, want=%q", got, wantFname)
}
return nil
})
if err != nil {
t.Fatalf("%+v", err)
}
err = db.Tx("not-there", func(f *riofs.File) error { return nil })
if err == nil {
t.Fatalf("expected an error")
}
db.Close()
}