This repository has been archived by the owner on Apr 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbundler_test.go
128 lines (105 loc) · 2.87 KB
/
bundler_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
126
127
128
package parcello_test
import (
"fmt"
"os"
"sync"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/phogolabs/parcello"
"github.com/phogolabs/parcello/fake"
)
var _ = Describe("Bundler", func() {
var (
bundler *parcello.Bundler
compressor *fake.Compressor
source *fake.FileSystem
target *fake.FileSystem
binary *fake.File
binaryInfo *parcello.ResourceFileInfo
ctx *parcello.BundlerContext
)
BeforeEach(func() {
content := []byte("file")
binaryInfo = &parcello.ResourceFileInfo{
Node: &parcello.Node{
Mutex: &sync.RWMutex{},
IsDir: false,
Content: &content,
},
}
binary = &fake.File{}
binary.StatReturns(binaryInfo, nil)
source = &fake.FileSystem{}
target = &fake.FileSystem{}
target.OpenFileReturns(binary, nil)
bundle := &parcello.Bundle{
Name: "app",
Count: 1,
Body: []byte("content"),
}
compressor = &fake.Compressor{}
compressor.CompressReturns(bundle, nil)
bundler = &parcello.Bundler{
Logger: GinkgoWriter,
Compressor: compressor,
FileSystem: source,
}
ctx = &parcello.BundlerContext{
Name: "app",
FileSystem: target,
}
})
It("bunles the binary successfully", func() {
Expect(bundler.Bundle(ctx)).To(Succeed())
Expect(target.OpenFileCallCount()).To(Equal(1))
name, opts, perm := target.OpenFileArgsForCall(0)
Expect(name).To(Equal(ctx.Name))
Expect(opts).To(Equal(os.O_WRONLY | os.O_APPEND))
Expect(perm).To(Equal(os.FileMode(0600)))
Expect(compressor.CompressCallCount()).To(Equal(1))
cctx := compressor.CompressArgsForCall(0)
Expect(cctx.FileSystem).To(Equal(source))
Expect(cctx.Offset).To(Equal(binaryInfo.Size()))
})
Context("when writing to the fail fails", func() {
BeforeEach(func() {
f := &fake.File{}
f.StatReturns(binaryInfo, nil)
f.WriteReturns(0, fmt.Errorf("Oh no!"))
target.OpenFileReturns(f, nil)
})
It("returns an error", func() {
Expect(bundler.Bundle(ctx)).To(MatchError("Oh no!"))
})
})
Context("when opening the binary fails", func() {
BeforeEach(func() {
target.OpenFileReturns(nil, fmt.Errorf("Oh no!"))
})
It("returns an error", func() {
Expect(bundler.Bundle(ctx)).To(MatchError("Oh no!"))
})
})
Context("when getting the binary information fails", func() {
BeforeEach(func() {
binary.StatReturns(nil, fmt.Errorf("Oh no!"))
})
It("returns an error", func() {
Expect(bundler.Bundle(ctx)).To(MatchError("Oh no!"))
})
})
Context("when the target is directory", func() {
BeforeEach(func() {
binaryInfo.Node.IsDir = true
})
It("returns an error", func() {
Expect(bundler.Bundle(ctx)).To(MatchError("'app' is not a regular file"))
})
})
Context("when the compressor fails", func() {
It("returns an error", func() {
compressor.CompressReturns(nil, fmt.Errorf("Oh no!"))
Expect(bundler.Bundle(ctx)).To(MatchError("Oh no!"))
})
})
})