From f0691189e1833c8af183149d2dfc03ecec2db2c2 Mon Sep 17 00:00:00 2001 From: Volkov Date: Mon, 4 Feb 2019 13:32:04 +0200 Subject: [PATCH 1/2] Manifest fix. Skip module entry in manifest with no path attribute in mtad.yaml --- internal/artifacts/manifest.go | 15 +++++++++------ internal/artifacts/manifest_test.go | 14 ++++++++++++++ .../testdata/golden_assembly_manifest.mf | 6 ------ .../testdata/golden_assembly_manifest_no_paths.mf | 6 ++++++ internal/artifacts/testdata/mta/mta_no_paths.yaml | 11 +++++++++++ 5 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 internal/artifacts/testdata/golden_assembly_manifest_no_paths.mf create mode 100644 internal/artifacts/testdata/mta/mta_no_paths.yaml diff --git a/internal/artifacts/manifest.go b/internal/artifacts/manifest.go index a2d703a77..ec06a8740 100644 --- a/internal/artifacts/manifest.go +++ b/internal/artifacts/manifest.go @@ -62,13 +62,16 @@ func setManifestDesc(ep dir.ITargetArtifacts, targetPathGetter dir.ITargetPath, return errors.Wrapf(err, "failed to generate the manifest file when getting the %s module content type", mod.Name) } - moduleEntry := entry{ - EntryName: mod.Name, - EntryPath: getModulePath(mod, targetPathGetter), - ContentType: contentType, - EntryType: moduleEntry, + modulePath := getModulePath(mod, targetPathGetter) + if modulePath != "" { + moduleEntry := entry{ + EntryName: mod.Name, + EntryPath: modulePath, + ContentType: contentType, + EntryType: moduleEntry, + } + entries = append(entries, moduleEntry) } - entries = append(entries, moduleEntry) if onlyModules { continue diff --git a/internal/artifacts/manifest_test.go b/internal/artifacts/manifest_test.go index 2d4538ce2..7ff9f6ca4 100644 --- a/internal/artifacts/manifest_test.go +++ b/internal/artifacts/manifest_test.go @@ -45,6 +45,18 @@ var _ = Describe("manifest", func() { fmt.Println(golden) Ω(actual).Should(Equal(golden)) }) + It("Sanity - no paths", func() { + os.Mkdir(getTestPath("result", "mta", "node-js"), os.ModePerm) + loc := dir.Loc{SourcePath: getTestPath("mta"), TargetPath: getResultPath(), MtaFilename: "mta_no_paths.yaml"} + mtaObj, err := loc.ParseFile() + Ω(err).Should(Succeed()) + Ω(setManifestDesc(&loc, &loc, mtaObj.Modules, []*mta.Resource{}, []string{}, false)).Should(Succeed()) + actual := getFileContent(getTestPath("result", "mta", "META-INF", "MANIFEST.MF")) + golden := getFileContent(getTestPath("golden_assembly_manifest_no_paths.mf")) + fmt.Println(actual) + fmt.Println(golden) + Ω(actual).Should(Equal(golden)) + }) It("With resources", func() { os.MkdirAll(getTestPath("result", "assembly-sample", "META-INF"), os.ModePerm) os.MkdirAll(getTestPath("result", "assembly-sample", "web"), os.ModePerm) @@ -56,6 +68,8 @@ var _ = Describe("manifest", func() { Ω(setManifestDesc(&loc, &loc, mtaObj.Modules, mtaObj.Resources, []string{}, false)).Should(Succeed()) actual := getFileContent(getTestPath("result", "assembly-sample", "META-INF", "MANIFEST.MF")) golden := getFileContent(getTestPath("golden_assembly_manifest.mf")) + fmt.Println(actual) + fmt.Println(golden) Ω(actual).Should(Equal(golden)) }) It("With missing module path", func() { diff --git a/internal/artifacts/testdata/golden_assembly_manifest.mf b/internal/artifacts/testdata/golden_assembly_manifest.mf index 3544ec86f..3bb33e8df 100644 --- a/internal/artifacts/testdata/golden_assembly_manifest.mf +++ b/internal/artifacts/testdata/golden_assembly_manifest.mf @@ -5,12 +5,6 @@ Name: web/ MTA-Module: java-hello-world Content-Type: text/directory - -Name: -MTA-Module: java-hello-world-backend -Content-Type: text/directory - - Name: config-site-host.json MTA-Requires: java-hello-world-backend/java-site-host Content-Type: application/json diff --git a/internal/artifacts/testdata/golden_assembly_manifest_no_paths.mf b/internal/artifacts/testdata/golden_assembly_manifest_no_paths.mf new file mode 100644 index 000000000..099c06e2e --- /dev/null +++ b/internal/artifacts/testdata/golden_assembly_manifest_no_paths.mf @@ -0,0 +1,6 @@ +manifest-Version: 1.0 +Created-By: SAP Application Archive Builder 0.0.1 + +Name: META-INF/mtad.yaml +Content-Type: text/plain + diff --git a/internal/artifacts/testdata/mta/mta_no_paths.yaml b/internal/artifacts/testdata/mta/mta_no_paths.yaml new file mode 100644 index 000000000..9ecb4500f --- /dev/null +++ b/internal/artifacts/testdata/mta/mta_no_paths.yaml @@ -0,0 +1,11 @@ +ID: mta +_schema-version: '2.1' +version: 0.0.1 + +modules: + - name: test_node-js + type: nodejs + provides: + - name: node-js_api + properties: + url: ${default-url} From a5bc1aeb3cfdbdeb64b4e2778ee28f3ba1f64b91 Mon Sep 17 00:00:00 2001 From: Volkov Date: Mon, 4 Feb 2019 13:52:07 +0200 Subject: [PATCH 2/2] fix lint problem - method complexity --- internal/artifacts/manifest.go | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/internal/artifacts/manifest.go b/internal/artifacts/manifest.go index ec06a8740..49ab93aa1 100644 --- a/internal/artifacts/manifest.go +++ b/internal/artifacts/manifest.go @@ -62,16 +62,8 @@ func setManifestDesc(ep dir.ITargetArtifacts, targetPathGetter dir.ITargetPath, return errors.Wrapf(err, "failed to generate the manifest file when getting the %s module content type", mod.Name) } - modulePath := getModulePath(mod, targetPathGetter) - if modulePath != "" { - moduleEntry := entry{ - EntryName: mod.Name, - EntryPath: modulePath, - ContentType: contentType, - EntryType: moduleEntry, - } - entries = append(entries, moduleEntry) - } + + entries = addModuleEntry(targetPathGetter, entries, mod, contentType) if onlyModules { continue @@ -98,6 +90,21 @@ func setManifestDesc(ep dir.ITargetArtifacts, targetPathGetter dir.ITargetPath, return genManifest(ep.GetManifestPath(), entries) } +func addModuleEntry(targetPathGetter dir.ITargetPath, entries []entry, module *mta.Module, contentType string) []entry { + result := entries + modulePath := getModulePath(module, targetPathGetter) + if modulePath != "" { + moduleEntry := entry{ + EntryName: module.Name, + EntryPath: modulePath, + ContentType: contentType, + EntryType: moduleEntry, + } + result = append(entries, moduleEntry) + } + return result +} + func getResourcesEntries(targetPathGetter dir.ITargetPath, resources []*mta.Resource, contentTypes *contenttype.ContentTypes) ([]entry, error) { var entries []entry