forked from ForceCLI/force
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackagebuilder_test.go
More file actions
138 lines (119 loc) · 4.14 KB
/
packagebuilder_test.go
File metadata and controls
138 lines (119 loc) · 4.14 KB
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
129
130
131
132
133
134
135
136
137
138
package main_test
import (
. "github.com/heroku/force"
"io/ioutil"
"os"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Packagebuilder", func() {
Describe("NewPushBuilder", func() {
It("should return a Packagebuilder", func() {
pb := NewPushBuilder()
Expect(pb).To(BeAssignableToTypeOf(PackageBuilder{IsPush: true}))
})
})
Describe("AddFile", func() {
var (
pb PackageBuilder
tempDir string
)
BeforeEach(func() {
pb = NewPushBuilder()
tempDir, _ = ioutil.TempDir("", "packagebuilder-test")
})
AfterEach(func() {
os.RemoveAll(tempDir)
})
Context("when adding a metadata file", func() {
var apexClassPath string
BeforeEach(func() {
os.MkdirAll(tempDir+"/src/classes", 0755)
apexClassPath = tempDir + "/src/classes/Test.cls"
apexClassContents := "class Test {}"
ioutil.WriteFile(apexClassPath, []byte(apexClassContents), 0644)
})
It("should add the file to package", func() {
_, err := pb.AddFile(apexClassPath)
Expect(err).ToNot(HaveOccurred())
Expect(pb.Files).To(HaveKey("classes/Test.cls"))
})
It("should add the file to the package.xml", func() {
pb.AddFile(apexClassPath)
Expect(pb.Metadata).To(HaveKey("ApexClass"))
Expect(pb.Metadata["ApexClass"].Members[0]).To(Equal("Test"))
})
})
Context("when adding a meta.xml file", func() {
var apexClassMetadataPath string
BeforeEach(func() {
os.MkdirAll(tempDir+"/src/classes", 0755)
apexClassMetadataPath = tempDir + "/src/classes/Test.cls-meta.xml"
apexClassMetadataContents := `<?xml version="1.0" encoding="UTF-8"?>`
ioutil.WriteFile(apexClassMetadataPath, []byte(apexClassMetadataContents), 0644)
})
It("should add the file to package", func() {
_, err := pb.AddFile(apexClassMetadataPath)
Expect(err).ToNot(HaveOccurred())
Expect(pb.Files).To(HaveKey("classes/Test.cls-meta.xml"))
})
It("should not add the file to the package.xml", func() {
pb.AddFile(apexClassMetadataPath)
Expect(pb.Metadata).ToNot(HaveKey("ApexClass"))
})
})
Context("when adding a CustomMetadata file", func() {
var customMetadataPath string
BeforeEach(func() {
os.MkdirAll(tempDir+"/src/customMetadata", 0755)
customMetadataPath = tempDir + "/src/customMetadata/My_Type.My_Object.md"
customMetadataContents := `<?xml version="1.0" encoding="UTF-8"?>`
ioutil.WriteFile(customMetadataPath, []byte(customMetadataContents), 0644)
})
It("should add the file to package", func() {
_, err := pb.AddFile(customMetadataPath)
Expect(err).ToNot(HaveOccurred())
Expect(pb.Files).To(HaveKey("customMetadata/My_Type.My_Object.md"))
})
It("should add the file to the package.xml", func() {
pb.AddFile(customMetadataPath)
Expect(pb.Metadata).To(HaveKey("CustomMetadata"))
Expect(pb.Metadata["CustomMetadata"].Members[0]).To(Equal("My_Type.My_Object"))
})
})
Context("when adding a non-existent file", func() {
It("should not add the file to package", func() {
_, err := pb.AddFile(tempDir + "/no/such/file")
Expect(err).To(HaveOccurred())
Expect(pb.Files).To(BeEmpty())
})
It("should not add the file to the package.xml", func() {
pb.AddFile(tempDir + "/no/such/file")
Expect(pb.Metadata).To(BeEmpty())
})
})
Context("when adding a destructiveChanges file", func() {
var destructiveChangesPath string
BeforeEach(func() {
pb = NewPushBuilder()
tempDir, _ := ioutil.TempDir("", "packagebuilder-test")
destructiveChangesPath = tempDir + "/destructiveChanges.xml"
destructiveChangesXml := `<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<version>34.0</version>
</Package>
`
ioutil.WriteFile(destructiveChangesPath, []byte(destructiveChangesXml), 0644)
})
It("should add the file to package", func() {
_, err := pb.AddFile(destructiveChangesPath)
Expect(err).ToNot(HaveOccurred())
Expect(pb.Files).To(HaveKey("destructiveChanges.xml"))
})
It("should not add the file to the package.xml", func() {
pb.AddFile(destructiveChangesPath)
Expect(pb.Metadata).To(BeEmpty())
})
})
})
})