forked from vmware-archive/yaml-patch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
placeholder_wrapper_test.go
93 lines (81 loc) · 2.99 KB
/
placeholder_wrapper_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 yamlpatch_test
import (
yamlpatch "github.com/EngineerBetter/yaml-patch"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("PlaceholderWrapper", func() {
var placeholderWrapper *yamlpatch.PlaceholderWrapper
BeforeEach(func() {
placeholderWrapper = yamlpatch.NewPlaceholderWrapper("{{", "}}")
})
Describe("Wrap", func() {
It("returns the original content", func() {
input := []byte(`content without any placeholders`)
actual := placeholderWrapper.Wrap(input)
Expect(actual).To(Equal(input))
})
It("returns the content with the placeholder wrapped when the content contains a placeholder", func() {
input := []byte(`content with a {{placeholder}}`)
expected := []byte(`content with a '{{placeholder}}'`)
actual := placeholderWrapper.Wrap(input)
Expect(actual).To(Equal(expected))
})
It("returns the content with the placeholder wrapped when the content contains a line with only a placeholder", func() {
input := []byte(`
content: |
{{placeholder}}
`)
expected := []byte(`
content: |
'{{placeholder}}'
`)
actual := placeholderWrapper.Wrap(input)
Expect(actual).To(Equal(expected))
})
It("returns the original content when the content contains an already-wrapped placeholder", func() {
input := []byte(`content with a wrapped '{{placeholder}}'`)
actual := placeholderWrapper.Wrap(input)
Expect(string(actual)).To(Equal(string(input)))
})
It("supports alternate placeholders", func() {
placeholderWrapper = yamlpatch.NewPlaceholderWrapper("((", "))")
input := []byte(`content with an ((alternate-placeholder))`)
expected := []byte(`content with an '((alternate-placeholder))'`)
actual := placeholderWrapper.Wrap(input)
Expect(actual).To(Equal(expected))
})
})
Describe("Unwrap", func() {
It("returns the original content", func() {
input := []byte(`content without any placeholders`)
actual := placeholderWrapper.Unwrap(input)
Expect(string(actual)).To(Equal(string(input)))
})
It("returns the content with the placeholder unwrapped when the content contains a wrapped placeholder", func() {
input := []byte(`content with a '{{placeholder}}'`)
expected := []byte(`content with a {{placeholder}}`)
actual := placeholderWrapper.Unwrap(input)
Expect(string(actual)).To(Equal(string(expected)))
})
It("returns the content with the placeholder unwrapped when the content contains a line with only a wrapped placeholder", func() {
input := []byte(`
content: |
'{{placeholder}}'
`)
expected := []byte(`
content: |
{{placeholder}}
`)
actual := placeholderWrapper.Unwrap(input)
Expect(string(actual)).To(Equal(string(expected)))
})
It("supports alternate placeholders", func() {
placeholderWrapper = yamlpatch.NewPlaceholderWrapper("((", "))")
input := []byte(`content with an '((alternate-placeholder))'`)
expected := []byte(`content with an ((alternate-placeholder))`)
actual := placeholderWrapper.Unwrap(input)
Expect(actual).To(Equal(expected))
})
})
})