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
/
embedder_test.go
93 lines (76 loc) · 2.2 KB
/
embedder_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
package parcello_test
import (
"fmt"
"sync"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/phogolabs/parcello"
"github.com/phogolabs/parcello/fake"
)
var _ = Describe("Embedder", func() {
var (
embedder *parcello.Embedder
composer *fake.Composer
compressor *fake.Compressor
fileSystem *fake.FileSystem
resource *parcello.ResourceFile
bundle *parcello.Bundle
)
BeforeEach(func() {
data := []byte("data")
node := &parcello.Node{
Name: "resource",
Content: &data,
Mutex: &sync.RWMutex{},
}
resource = parcello.NewResourceFile(node)
bundle = &parcello.Bundle{
Name: "resource",
Count: 20,
Body: []byte("resource"),
}
compressor = &fake.Compressor{}
compressor.CompressStub = func(ctx *parcello.CompressorContext) (*parcello.Bundle, error) {
return bundle, nil
}
composer = &fake.Composer{}
fileSystem = &fake.FileSystem{}
fileSystem.OpenFileReturns(resource, nil)
embedder = &parcello.Embedder{
Logger: GinkgoWriter,
Compressor: compressor,
Composer: composer,
FileSystem: fileSystem,
}
})
It("embeds the provided source successfully", func() {
Expect(embedder.Embed()).To(Succeed())
Expect(compressor.CompressCallCount()).To(Equal(1))
ctx := compressor.CompressArgsForCall(0)
Expect(ctx.FileSystem).To(Equal(fileSystem))
Expect(composer.ComposeCallCount()).To(Equal(1))
Expect(composer.ComposeArgsForCall(0)).To(Equal(bundle))
})
Context("when the bundle is nil", func() {
It("does not compose it", func() {
compressor.CompressReturns(nil, nil)
Expect(embedder.Embed()).To(Succeed())
Expect(compressor.CompressCallCount()).To(Equal(1))
ctx := compressor.CompressArgsForCall(0)
Expect(ctx.FileSystem).To(Equal(fileSystem))
Expect(composer.ComposeCallCount()).To(BeZero())
})
})
Context("when the compressor fails", func() {
It("returns the error", func() {
compressor.CompressReturns(nil, fmt.Errorf("Oh no!"))
Expect(embedder.Embed()).To(MatchError("Oh no!"))
})
})
Context("when the composer fails", func() {
It("returns the error", func() {
composer.ComposeReturns(fmt.Errorf("Oh no!"))
Expect(embedder.Embed()).To(MatchError("Oh no!"))
})
})
})