-
Notifications
You must be signed in to change notification settings - Fork 0
/
fs-create_test.go
89 lines (75 loc) · 2.03 KB
/
fs-create_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
package nef_test
import (
"os"
. "github.com/onsi/ginkgo/v2" //nolint:revive // ok
. "github.com/onsi/gomega" //nolint:revive // ok
nef "github.com/snivilised/nefilim"
lab "github.com/snivilised/nefilim/internal/laboratory"
"github.com/snivilised/nefilim/test/luna"
)
var _ = Describe("op: create", Ordered, func() {
var root string
BeforeAll(func() {
root = luna.Repo("test")
})
Context("fs: WriteFileFS", func() {
BeforeEach(func() {
scratch(root)
})
Context("overwrite", func() {
var fS nef.WriteFileFS
BeforeEach(func() {
fS = nef.NewWriteFileFS(nef.Rel{
Root: root,
Overwrite: true,
})
Expect(fS.IsRelative()).To(BeTrue())
})
Context("op: Create", func() {
When("given: file does not already exist", func() {
It("🧪 should: create successfully", func() {
Expect(require(root, lab.Static.FS.Scratch)).To(Succeed())
name := lab.Static.FS.Create.Destination
file, err := fS.Create(name)
Expect(err).To(Succeed())
defer file.Close()
Expect(luna.AsFile(name)).To(luna.ExistInFS(fS))
})
})
When("given: file exists", func() {
It("🧪 should: create successfully", func() {
Expect(require(
root, lab.Static.FS.Scratch, lab.Static.FS.Create.Destination,
)).To(Succeed())
name := lab.Static.FS.Create.Destination
file, err := fS.Create(name)
Expect(err).To(Succeed())
defer file.Close()
Expect(luna.AsFile(name)).To(luna.ExistInFS(fS))
})
})
})
})
Context("tentative", func() {
var fS nef.WriteFileFS
BeforeEach(func() {
fS = nef.NewWriteFileFS(nef.Rel{
Root: root,
Overwrite: false,
})
})
Context("op: Create", func() {
When("given: file exists", func() {
It("🧪 should: fail", func() {
file := lab.Static.FS.Create.Destination
Expect(require(
root, lab.Static.FS.Scratch, file,
)).To(Succeed())
_, err := fS.Create(file)
Expect(err).To(MatchError(os.ErrExist))
})
})
})
})
})
})