summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorEirik Nygaard <eirik.nygaard@yahooinc.com>2022-03-01 15:53:45 +0100
committerEirik Nygaard <eirik.nygaard@yahooinc.com>2022-03-01 19:00:51 +0100
commit8b1f1b0ca3695cc07f39adcc3800b3e9574b89c7 (patch)
tree6a8dcebc55f319bc45d8ab9a5c736ed3aeef15c1 /client
parent02e472a7fd8d6bdb68450e11da745cb247267777 (diff)
Support verifying Basic HTTP tests in application-test.zip
Diffstat (limited to 'client')
-rw-r--r--client/go/cmd/prod.go21
-rw-r--r--client/go/vespa/application.go55
2 files changed, 68 insertions, 8 deletions
diff --git a/client/go/cmd/prod.go b/client/go/cmd/prod.go
index 4a834ebf46d..7ba6072b3a9 100644
--- a/client/go/cmd/prod.go
+++ b/client/go/cmd/prod.go
@@ -152,11 +152,8 @@ $ vespa prod submit`,
"The application must be a Java maven project, or include basic HTTP tests under src/test/application/",
"See https://cloud.vespa.ai/en/getting-to-production")
}
- // TODO: Always verify tests. Do it before packaging, when running Maven from this CLI.
- if !pkg.IsZip() {
- if err := verifyTests(pkg.TestPath, target); err != nil {
- return err
- }
+ if err := verifyTests(pkg, target); err != nil {
+ return err
}
isCI := os.Getenv("CI") != ""
if !isCI {
@@ -377,18 +374,26 @@ func prompt(r *bufio.Reader, question, defaultAnswer string, validator func(inpu
return input, nil
}
-func verifyTests(testsParent string, target vespa.Target) error {
+func verifyTests(app vespa.ApplicationPackage, target vespa.Target) error {
// TODO: system-test, staging-setup and staging-test should be required if the application
// does not have any Java tests.
suites := map[string]bool{
- // suite name: required
"system-test": false,
"staging-setup": false,
"staging-test": false,
"production-test": false,
}
+ testPath := app.TestPath
+ if app.IsZip() {
+ path, err := app.Unzip(true)
+ if err != nil {
+ return err
+ }
+ defer os.RemoveAll(path)
+ testPath = path
+ }
for suite, required := range suites {
- if err := verifyTest(testsParent, suite, target, required); err != nil {
+ if err := verifyTest(testPath, suite, target, required); err != nil {
return err
}
}
diff --git a/client/go/vespa/application.go b/client/go/vespa/application.go
index 28643515906..80965987b66 100644
--- a/client/go/vespa/application.go
+++ b/client/go/vespa/application.go
@@ -146,6 +146,61 @@ func (ap *ApplicationPackage) zipReader(test bool) (io.ReadCloser, error) {
return f, nil
}
+func (ap *ApplicationPackage) Unzip(test bool) (string, error) {
+ if !ap.IsZip() {
+ return "", fmt.Errorf("can't unzip a package that is a directory structure")
+ }
+ cleanTemp := true
+ tmp, err := os.MkdirTemp(os.TempDir(), "vespa-test-pkg")
+ if err != nil {
+ return "", err
+ }
+ defer func() {
+ if cleanTemp {
+ os.RemoveAll(tmp)
+ }
+ }()
+ path := ap.Path
+ if test {
+ path = ap.TestPath
+ }
+ f, err := zip.OpenReader(path)
+ if err != nil {
+ return "", err
+ }
+ defer f.Close()
+ for _, f := range f.File {
+ dst := filepath.Join(tmp, f.Name)
+ if f.FileInfo().IsDir() {
+ if err := os.Mkdir(dst, f.FileInfo().Mode()); err != nil {
+ return "", err
+ }
+ continue
+ }
+ if err := copyFile(f, dst); err != nil {
+ return "", fmt.Errorf("copyFile: %w", err)
+ }
+
+ }
+ cleanTemp = false
+ return tmp, nil
+}
+
+func copyFile(src *zip.File, dst string) error {
+ from, err := src.Open()
+ if err != nil {
+ return err
+ }
+ defer from.Close()
+ to, err := os.OpenFile(dst, os.O_CREATE|os.O_WRONLY, src.FileInfo().Mode())
+ if err != nil {
+ return err
+ }
+ defer to.Close()
+ _, err = io.Copy(to, from)
+ return err
+}
+
// FindApplicationPackage finds the path to an application package from the zip file or directory zipOrDir.
func FindApplicationPackage(zipOrDir string, requirePackaging bool) (ApplicationPackage, error) {
if isZip(zipOrDir) {