diff options
author | Martin Polden <mpolden@mpolden.no> | 2023-09-08 11:39:05 +0200 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2023-09-08 11:39:05 +0200 |
commit | 04f79e9739593d9eaab6cf2a74a2578a57ea0acb (patch) | |
tree | 7094de581c86e14558ac9a7dbe2b865f0ec938d6 /client | |
parent | 3c129c2ac776a392ab604b5c158981d60700f7d1 (diff) |
Ensure that application-test is included when it exists
Diffstat (limited to 'client')
-rw-r--r-- | client/go/internal/vespa/application.go | 40 | ||||
-rw-r--r-- | client/go/internal/vespa/deploy_test.go | 14 |
2 files changed, 26 insertions, 28 deletions
diff --git a/client/go/internal/vespa/application.go b/client/go/internal/vespa/application.go index b6b5b9427b3..13d3b63cfa9 100644 --- a/client/go/internal/vespa/application.go +++ b/client/go/internal/vespa/application.go @@ -220,36 +220,31 @@ func copyFile(src *zip.File, dst string) error { // Package to use is preferred in this order: // 1. Given path, if it's a zip // 2. target/application -// 3. target/application.zip -// 4. src/main/application -// 5. Given path, if it contains services.xml +// 3. src/main/application +// 4. Given path, if it contains services.xml func FindApplicationPackage(zipOrDir string, requirePackaging bool) (ApplicationPackage, error) { if isZip(zipOrDir) { return ApplicationPackage{Path: zipOrDir}, nil } - // Prefer uncompressed application because this allows us to add security/clients.pem to the package on-demand - if path := filepath.Join(zipOrDir, "target", "application"); util.PathExists(path) { - return ApplicationPackage{Path: path}, nil - } - appZip := filepath.Join(zipOrDir, "target", "application.zip") - if util.PathExists(filepath.Join(zipOrDir, "pom.xml")) || util.PathExists(appZip) { - if util.PathExists(appZip) { - if testZip := filepath.Join(zipOrDir, "target", "application-test.zip"); util.PathExists(testZip) { - return ApplicationPackage{Path: appZip, TestPath: testZip}, nil - } - return ApplicationPackage{Path: appZip}, nil + // Pre-packaged application. We prefer the uncompressed application because this allows us to add + // security/clients.pem to the package on-demand + hasPOM := util.PathExists(filepath.Join(zipOrDir, "pom.xml")) + if hasPOM { + path := filepath.Join(zipOrDir, "target", "application") + if util.PathExists(path) { + testPath := existingPath(filepath.Join(zipOrDir, "target", "application-test")) + return ApplicationPackage{Path: path, TestPath: testPath}, nil } if requirePackaging { - return ApplicationPackage{}, errors.New("found pom.xml, but target/application.zip does not exist: run 'mvn package' first") + return ApplicationPackage{}, fmt.Errorf("found pom.xml, but %s does not exist: run 'mvn package' first", path) } } + // Application with Maven directory structure, but with no POM or no hard requirement on packaging if path := filepath.Join(zipOrDir, "src", "main", "application"); util.PathExists(path) { - testPath := "" - if d := filepath.Join(zipOrDir, "src", "test", "application"); util.PathExists(d) { - testPath = d - } + testPath := existingPath(filepath.Join(zipOrDir, "src", "test", "application")) return ApplicationPackage{Path: path, TestPath: testPath}, nil } + // Application without Java components if util.PathExists(filepath.Join(zipOrDir, "services.xml")) { testPath := "" if util.PathExists(filepath.Join(zipOrDir, "tests")) { @@ -259,3 +254,10 @@ func FindApplicationPackage(zipOrDir string, requirePackaging bool) (Application } return ApplicationPackage{}, fmt.Errorf("could not find an application package source in '%s'", zipOrDir) } + +func existingPath(path string) string { + if util.PathExists(path) { + return path + } + return "" +} diff --git a/client/go/internal/vespa/deploy_test.go b/client/go/internal/vespa/deploy_test.go index 693d4527624..ff278578e8a 100644 --- a/client/go/internal/vespa/deploy_test.go +++ b/client/go/internal/vespa/deploy_test.go @@ -151,18 +151,14 @@ func TestFindApplicationPackage(t *testing.T) { fail: true, }) assertFindApplicationPackage(t, dir, pkgFixture{ - expectedPath: filepath.Join(dir, "target", "application.zip"), - existingFiles: []string{filepath.Join(dir, "pom.xml"), filepath.Join(dir, "target", "application.zip")}, - requirePackaging: true, - }) - assertFindApplicationPackage(t, dir, pkgFixture{ - expectedPath: filepath.Join(dir, "target", "application.zip"), - existingFiles: []string{filepath.Join(dir, "target", "application.zip")}, - }) - assertFindApplicationPackage(t, dir, pkgFixture{ expectedPath: filepath.Join(dir, "target", "application"), existingFiles: []string{filepath.Join(dir, "target", "application"), filepath.Join(dir, "target", "application.zip")}, }) + assertFindApplicationPackage(t, dir, pkgFixture{ + expectedPath: filepath.Join(dir, "target", "application"), + expectedTestPath: filepath.Join(dir, "target", "application-test"), + existingFiles: []string{filepath.Join(dir, "target", "application"), filepath.Join(dir, "target", "application-test")}, + }) zip := filepath.Join(dir, "myapp.zip") assertFindApplicationPackage(t, zip, pkgFixture{ expectedPath: zip, |