Skip to content

Commit

Permalink
Create unix-normalized paths for MANIFEST.MF
Browse files Browse the repository at this point in the history
Replace the usage of filepath.Join with concatenation of "/".
Bump GO version in travis.yml
JIRA: LMCROSSITXSADEPLOY-2061
  • Loading branch information
radoslav-d committed Apr 28, 2020
1 parent 7fc4874 commit d941300
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: go
go:
- 1.8
- 1.11
install:
- chmod +x bin/test.sh
- chmod +x build.sh
Expand Down
11 changes: 6 additions & 5 deletions util/archive_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ func (builder MtaArchiveBuilder) Build(deploymentDescriptorLocation string) (str
}
bindingParametersPaths := builder.getBindingParametersPaths(descriptor.Modules)

modulesSections := buildSection(normalizePaths(modulesPaths), MtaModule)
resourcesSections := buildSection(normalizePaths(resourcesPaths), MtaResource)
bindingParametersSections := buildSection(normalizePaths(bindingParametersPaths), MtaRequires)
modulesSections := buildSection(normalizePathsUsingUnixSeparator(modulesPaths), MtaModule)
resourcesSections := buildSection(normalizePathsUsingUnixSeparator(resourcesPaths), MtaResource)
bindingParametersSections := buildSection(normalizePathsUsingUnixSeparator(bindingParametersPaths), MtaRequires)

manifestBuilder := NewMtaManifestBuilder()
manifestBuilder.ManifestSections(modulesSections)
Expand Down Expand Up @@ -316,11 +316,12 @@ func (builder MtaArchiveBuilder) getModulesPaths(deploymentDescriptorResources [
return result, nil
}

func normalizePaths(elementsPaths map[string]string) map[string]string {
func normalizePathsUsingUnixSeparator(elementsPaths map[string]string) map[string]string {
normalizedPaths := make(map[string]string, len(elementsPaths))
for key, value := range elementsPaths {
if value != "" {
normalizedPaths[key] = filepath.Join(key, filepath.Base(value))
zipEntryNormalizedPath := fmt.Sprintf("%s/%s", key, filepath.Base(value))
normalizedPaths[key] = zipEntryNormalizedPath
}
}
return normalizedPaths
Expand Down
18 changes: 11 additions & 7 deletions util/archive_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var _ = Describe("ArchiveBuilder", func() {
})

AfterEach(func() {
expectedModulePath := filepath.Join(moduleName, requiredDependencyContent)
expectedModulePath := filepathUnixJoin(moduleName, requiredDependencyContent)
Expect(err).To(BeNil())
_, err = os.Stat(mtaArchiveLocation)
Expect(err).To(BeNil())
Expand Down Expand Up @@ -206,7 +206,7 @@ var _ = Describe("ArchiveBuilder", func() {
Expect(err).To(BeNil())
_, err = os.Stat(mtaArchiveLocation)
Expect(err).To(BeNil())
expectedModulePath := filepath.Join("TestModule", "test-module-1-content")
expectedModulePath := filepathUnixJoin("TestModule", "test-module-1-content")
Expect(isInArchive(expectedModulePath, mtaArchiveLocation)).To(BeTrue())
Expect(isInArchive("META-INF/MANIFEST.MF", mtaArchiveLocation)).To(BeTrue())
Expect(isInArchive("META-INF/mtad.yaml", mtaArchiveLocation)).To(BeTrue())
Expand All @@ -232,7 +232,7 @@ var _ = Describe("ArchiveBuilder", func() {
Expect(err).To(BeNil())
_, err = os.Stat(mtaArchiveLocation)
Expect(err).To(BeNil())
expectedModulePath := filepath.Join("TestModule", "test-module-1-content")
expectedModulePath := filepathUnixJoin("TestModule", "test-module-1-content")
Expect(isInArchive(expectedModulePath, mtaArchiveLocation)).To(BeTrue())
Expect(isInArchive("META-INF/MANIFEST.MF", mtaArchiveLocation)).To(BeTrue())
Expect(isInArchive("META-INF/mtad.yaml", mtaArchiveLocation)).To(BeTrue())
Expand Down Expand Up @@ -279,7 +279,7 @@ var _ = Describe("ArchiveBuilder", func() {
Expect(err).To(BeNil())
_, err = os.Stat(mtaArchiveLocation)
Expect(err).To(BeNil())
expectedResourcePath := filepath.Join("TestResource", "test-resource-1-content")
expectedResourcePath := filepathUnixJoin("TestResource", "test-resource-1-content")
Expect(isInArchive(expectedResourcePath, mtaArchiveLocation)).To(BeTrue())
Expect(isInArchive("META-INF/MANIFEST.MF", mtaArchiveLocation)).To(BeTrue())
Expect(isInArchive("META-INF/mtad.yaml", mtaArchiveLocation)).To(BeTrue())
Expand All @@ -303,7 +303,7 @@ var _ = Describe("ArchiveBuilder", func() {
Expect(err).To(BeNil())
_, err = os.Stat(mtaArchiveLocation)
Expect(err).To(BeNil())
expectedResourcePath := filepath.Join("TestResource", "test-resource-1-content")
expectedResourcePath := filepathUnixJoin("TestResource", "test-resource-1-content")
Expect(isInArchive(expectedResourcePath, mtaArchiveLocation)).To(BeTrue())
Expect(isInArchive("META-INF/MANIFEST.MF", mtaArchiveLocation)).To(BeTrue())
Expect(isInArchive("META-INF/mtad.yaml", mtaArchiveLocation)).To(BeTrue())
Expand Down Expand Up @@ -354,7 +354,7 @@ var _ = Describe("ArchiveBuilder", func() {
Expect(err).To(BeNil())
_, err = os.Stat(mtaArchiveLocation)
Expect(err).To(BeNil())
expectedRequiredDependenciesPath := filepath.Join("TestModule", "TestRequired", "test-required-dep-1-content")
expectedRequiredDependenciesPath := filepathUnixJoin("TestModule", "TestRequired", "test-required-dep-1-content")
Expect(isInArchive(expectedRequiredDependenciesPath, mtaArchiveLocation)).To(BeTrue())
Expect(isInArchive("META-INF/MANIFEST.MF", mtaArchiveLocation)).To(BeTrue())
Expect(isInArchive("META-INF/mtad.yaml", mtaArchiveLocation)).To(BeTrue())
Expand Down Expand Up @@ -385,7 +385,7 @@ var _ = Describe("ArchiveBuilder", func() {
Expect(err).To(BeNil())
_, err = os.Stat(mtaArchiveLocation)
Expect(err).To(BeNil())
expectedRequiredDependenciesPath := filepath.Join("TestModule", "TestRequired", "test-required-dep-1-content")
expectedRequiredDependenciesPath := filepathUnixJoin("TestModule", "TestRequired", "test-required-dep-1-content")
Expect(isInArchive(expectedRequiredDependenciesPath, mtaArchiveLocation)).To(BeTrue())
Expect(isInArchive("META-INF/MANIFEST.MF", mtaArchiveLocation)).To(BeTrue())
Expect(isInArchive("META-INF/mtad.yaml", mtaArchiveLocation)).To(BeTrue())
Expand Down Expand Up @@ -446,3 +446,7 @@ func isManifestValid(manifestLocation string, searchCriteria map[string]string,
}
return searchCriteriaResult
}

func filepathUnixJoin(elements ...string) string {
return strings.Join(elements, "/")
}

0 comments on commit d941300

Please sign in to comment.