Skip to content

Commit a17db7b

Browse files
Fix tests
1 parent 5ae9bf5 commit a17db7b

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

util/archive_builder_test.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ package util_test
22

33
import (
44
"archive/zip"
5+
"github.com/cloudfoundry-incubator/multiapps-cli-plugin/testutil"
56
"io/ioutil"
67
"os"
78
"path/filepath"
89
"strings"
910

10-
"github.com/cloudfoundry-incubator/multiapps-cli-plugin/testutil"
1111
"github.com/cloudfoundry-incubator/multiapps-cli-plugin/util"
1212
. "github.com/onsi/ginkgo"
1313
. "github.com/onsi/gomega"
14-
yaml "gopkg.in/yaml.v2"
14+
"gopkg.in/yaml.v2"
1515
)
1616

1717
var _ = Describe("ArchiveBuilder", func() {
@@ -22,8 +22,8 @@ var _ = Describe("ArchiveBuilder", func() {
2222
})
2323
Context("With not existing resources", func() {
2424
It("should try to find the directory and fail with error", func() {
25-
_, err := util.NewMtaArchiveBuilder([]string{}, []string{}).Build("not-existing-location/")
26-
Expect(err).To(MatchError("Deployment descriptor location does not exist not-existing-location/"))
25+
_, err := util.NewMtaArchiveBuilder([]string{}, []string{}).Build("not-existing-location")
26+
Expect(err).To(MatchError("Deployment descriptor location does not exist not-existing-location"))
2727
})
2828
It("should try to find the deployment descriptor in the provided location and fail with error", func() {
2929
_, err := util.NewMtaArchiveBuilder([]string{}, []string{}).Build(tempDirLocation)
@@ -40,7 +40,7 @@ var _ = Describe("ArchiveBuilder", func() {
4040
testDeploymentDescriptor := tempDirLocation + string(os.PathSeparator) + "mtad.yaml"
4141
ioutil.WriteFile(testDeploymentDescriptor, generatedYamlBytes, os.ModePerm)
4242
_, err := util.NewMtaArchiveBuilder([]string{"TestModule"}, []string{}).Build(tempDirLocation)
43-
Expect(err.Error()).To(MatchRegexp("Error building MTA Archive: file path .*/not-existing-path not found"))
43+
Expect(err.Error()).To(MatchRegexp("Error building MTA Archive: file path .*?not-existing-path not found"))
4444
})
4545

4646
It("Try to parse the specified resources and fail as the paths are not existing", func() {
@@ -53,7 +53,7 @@ var _ = Describe("ArchiveBuilder", func() {
5353
testDeploymentDescriptor := tempDirLocation + string(os.PathSeparator) + "mtad.yaml"
5454
ioutil.WriteFile(testDeploymentDescriptor, generatedYamlBytes, os.ModePerm)
5555
_, err := util.NewMtaArchiveBuilder([]string{}, []string{"foo"}).Build(tempDirLocation)
56-
Expect(err.Error()).To(MatchRegexp("Error building MTA Archive: file path .*/not-existing-resource-path not found"))
56+
Expect(err.Error()).To(MatchRegexp("Error building MTA Archive: file path .*?not-existing-resource-path not found"))
5757
})
5858

5959
It("Try to parse the specified required dependencies config paths and fail as the paths are not existing", func() {
@@ -71,7 +71,7 @@ var _ = Describe("ArchiveBuilder", func() {
7171
testDeploymentDescriptor := tempDirLocation + string(os.PathSeparator) + "mtad.yaml"
7272
ioutil.WriteFile(testDeploymentDescriptor, generatedYamlBytes, os.ModePerm)
7373
_, err := util.NewMtaArchiveBuilder([]string{"TestModule"}, []string{}).Build(tempDirLocation)
74-
Expect(err.Error()).To(MatchRegexp("Error building MTA Archive: file path .*/not-existing-required-dependency-path not found"))
74+
Expect(err.Error()).To(MatchRegexp("Error building MTA Archive: file path .*?not-existing-required-dependency-path not found"))
7575
})
7676
})
7777

@@ -286,10 +286,15 @@ func isManifestValid(manifestLocation string, searchCriteria map[string]string,
286286
manifestBytes, _ := ioutil.ReadAll(reader)
287287
manifestSplittedByNewLine := strings.Split(string(manifestBytes), "\n")
288288
for _, manifestSectionElement := range manifestSplittedByNewLine {
289-
manifestLineElements := strings.Split(manifestSectionElement, ":")
290-
if searchCriteria[manifestLineElements[0]] != "" {
291-
delete(searchCriteria, manifestLineElements[0])
292-
searchCriteriaResult[manifestLineElements[0]] = strings.Trim(manifestLineElements[1], " ")
289+
if strings.Trim(manifestSectionElement, " ") == "" {
290+
continue
291+
}
292+
separatorIndex := strings.Index(manifestSectionElement, ":")
293+
key := manifestSectionElement[:separatorIndex]
294+
value := manifestSectionElement[separatorIndex+1:]
295+
if searchCriteria[key] != "" {
296+
delete(searchCriteria, key)
297+
searchCriteriaResult[key] = strings.Trim(value, " ")
293298
}
294299
}
295300
break

0 commit comments

Comments
 (0)