-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathobject_test.go
54 lines (42 loc) · 1.22 KB
/
object_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
package bfs_test
import (
"context"
"io"
"github.com/bsm/bfs"
. "github.com/bsm/ginkgo/v2"
. "github.com/bsm/gomega"
)
var _ = Describe("Object", func() {
var subject *bfs.Object
var ctx = context.Background()
BeforeEach(func() {
var err error
subject, err = bfs.NewObject(ctx, "mem:///path/to/file.txt")
Expect(err).NotTo(HaveOccurred())
})
It("should have a name", func() {
Expect(subject.Name()).To(Equal("path/to/file.txt"))
})
It("should head/read/write", func() {
_, err := subject.Head(ctx)
Expect(err).To(Equal(bfs.ErrNotFound))
_, err = subject.Open(ctx)
Expect(err).To(Equal(bfs.ErrNotFound))
w, err := subject.Create(ctx, nil)
Expect(err).ToNot(HaveOccurred())
defer w.Discard()
Expect(w.Write([]byte("TESTDATA"))).To(Equal(8))
Expect(w.Commit()).To(Succeed())
i, err := subject.Head(ctx)
Expect(err).ToNot(HaveOccurred())
Expect(i.Size).To(Equal(int64(8)))
Expect(i.Name).To(Equal("path/to/file.txt"))
r, err := subject.Open(ctx)
Expect(err).ToNot(HaveOccurred())
Expect(io.ReadAll(r)).To(Equal([]byte("TESTDATA")))
Expect(r.Close()).To(Succeed())
Expect(subject.Remove(ctx)).To(Succeed())
_, err = subject.Head(ctx)
Expect(err).To(Equal(bfs.ErrNotFound))
})
})