aboutsummaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorJon Marius Venstad <venstad@gmail.com>2021-11-26 12:00:11 +0100
committerJon Marius Venstad <venstad@gmail.com>2021-11-26 12:00:11 +0100
commitd0b2ffd1292644b02bdf0fdfcd8564222d376f3d (patch)
tree61c1b1466e5e1864a2b53b3c16650ec87f7212e6 /client
parent175d4a81870e638a72dd7e9e688277af71c1ed7e (diff)
Let vespa prod package src/main/application and src/test/application and submit
Diffstat (limited to 'client')
-rw-r--r--client/go/cmd/prod.go7
-rw-r--r--client/go/cmd/prod_test.go52
-rw-r--r--client/go/vespa/deploy.go4
3 files changed, 53 insertions, 10 deletions
diff --git a/client/go/cmd/prod.go b/client/go/cmd/prod.go
index d1d72362448..57d8275c625 100644
--- a/client/go/cmd/prod.go
+++ b/client/go/cmd/prod.go
@@ -116,7 +116,7 @@ For more information about production deployments in Vespa Cloud see:
https://cloud.vespa.ai/en/getting-to-production
https://cloud.vespa.ai/en/automated-deployments`,
DisableAutoGenTag: true,
- Example: `$ mvn package
+ Example: `$ mvn package # when adding custom Java components
$ vespa prod submit`,
Run: func(cmd *cobra.Command, args []string) {
target := getTarget()
@@ -139,9 +139,8 @@ $ vespa prod submit`,
fatalErrHint(fmt.Errorf("No deployment.xml found"), "Try creating one with vespa prod init")
return
}
- if !pkg.IsJava() {
- // TODO: Loosen this requirement when we start supporting applications with Java in production
- fatalErrHint(fmt.Errorf("No jar files found in %s", pkg.Path), "Only applications containing Java components are currently supported")
+ if pkg.TestPath == "" {
+ fatalErrHint(fmt.Errorf("No tests found"), "The application must be a Java maven project, or include basic HTTP tests under src/test/application")
return
}
isCI := os.Getenv("CI") != ""
diff --git a/client/go/cmd/prod_test.go b/client/go/cmd/prod_test.go
index 4ce6112122a..9e8f90ed8c3 100644
--- a/client/go/cmd/prod_test.go
+++ b/client/go/cmd/prod_test.go
@@ -16,7 +16,7 @@ import (
func TestProdInit(t *testing.T) {
homeDir := filepath.Join(t.TempDir(), ".vespa")
pkgDir := filepath.Join(t.TempDir(), "app")
- createApplication(t, pkgDir)
+ createApplication(t, pkgDir, false)
answers := []string{
// Regions
@@ -81,7 +81,7 @@ func readFileString(t *testing.T, filename string) string {
return string(content)
}
-func createApplication(t *testing.T, pkgDir string) {
+func createApplication(t *testing.T, pkgDir string, java bool) {
appDir := filepath.Join(pkgDir, "src", "main", "application")
targetDir := filepath.Join(pkgDir, "target")
if err := os.MkdirAll(appDir, 0755); err != nil {
@@ -120,15 +120,55 @@ func createApplication(t *testing.T, pkgDir string) {
if err := os.MkdirAll(targetDir, 0755); err != nil {
t.Fatal(err)
}
- if err := ioutil.WriteFile(filepath.Join(pkgDir, "pom.xml"), []byte(""), 0644); err != nil {
- t.Fatal(err)
+ if java {
+ if err := ioutil.WriteFile(filepath.Join(pkgDir, "pom.xml"), []byte(""), 0644); err != nil {
+ t.Fatal(err)
+ }
+ } else {
+ testsDir := filepath.Join(pkgDir, "src", "test", "application", "tests", "system-test")
+ if err := os.MkdirAll(testsDir, 0700); err != nil {
+ t.Fatal(err)
+ }
+ if err := ioutil.WriteFile(filepath.Join(testsDir, "test.json"), []byte(""), 0644); err != nil {
+ t.Fatal(err)
+ }
}
}
func TestProdSubmit(t *testing.T) {
homeDir := filepath.Join(t.TempDir(), ".vespa")
pkgDir := filepath.Join(t.TempDir(), "app")
- createApplication(t, pkgDir)
+ createApplication(t, pkgDir, false)
+
+ httpClient := &mockHttpClient{}
+ httpClient.NextResponse(200, `ok`)
+ execute(command{homeDir: homeDir, args: []string{"config", "set", "application", "t1.a1.i1"}}, t, httpClient)
+ execute(command{homeDir: homeDir, args: []string{"config", "set", "target", "cloud"}}, t, httpClient)
+ execute(command{homeDir: homeDir, args: []string{"api-key"}}, t, httpClient)
+ execute(command{homeDir: homeDir, args: []string{"cert", pkgDir}}, t, httpClient)
+
+ // Zipping requires relative paths, so much let command run from pkgDir, then reset cwd for subsequent tests.
+ if cwd, err := os.Getwd(); err != nil {
+ t.Fatal(err)
+ } else {
+ defer os.Chdir(cwd)
+ }
+ if err := os.Chdir(pkgDir); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Setenv("CI", "true"); err != nil {
+ t.Fatal(err)
+ }
+ out, err := execute(command{homeDir: homeDir, args: []string{"prod", "submit"}}, t, httpClient)
+ assert.Equal(t, "", err)
+ assert.Contains(t, out, "Success: Submitted")
+ assert.Contains(t, out, "See https://console.vespa.oath.cloud/tenant/t1/application/a1/prod/deployment for deployment progress")
+}
+
+func TestProdSubmitWithJava(t *testing.T) {
+ homeDir := filepath.Join(t.TempDir(), ".vespa")
+ pkgDir := filepath.Join(t.TempDir(), "app")
+ createApplication(t, pkgDir, true)
httpClient := &mockHttpClient{}
httpClient.NextResponse(200, `ok`)
@@ -137,7 +177,7 @@ func TestProdSubmit(t *testing.T) {
execute(command{homeDir: homeDir, args: []string{"api-key"}}, t, httpClient)
execute(command{homeDir: homeDir, args: []string{"cert", pkgDir}}, t, httpClient)
- // Copy an application package pre-assambled with mvn package
+ // Copy an application package pre-assembled with mvn package
testAppDir := filepath.Join("testdata", "applications", "withDeployment", "target")
zipFile := filepath.Join(testAppDir, "application.zip")
copyFile(t, filepath.Join(pkgDir, "target", "application.zip"), zipFile)
diff --git a/client/go/vespa/deploy.go b/client/go/vespa/deploy.go
index c1cc868e16f..14158453c96 100644
--- a/client/go/vespa/deploy.go
+++ b/client/go/vespa/deploy.go
@@ -167,6 +167,10 @@ func FindApplicationPackage(zipOrDir string, requirePackaging bool) (Application
}
}
if util.PathExists(filepath.Join(zipOrDir, "src", "main", "application")) {
+ if util.PathExists(filepath.Join(zipOrDir, "src", "test", "application")) {
+ return ApplicationPackage{Path: filepath.Join(zipOrDir, "src", "main", "application"),
+ TestPath: filepath.Join(zipOrDir, "src", "test", "application")}, nil
+ }
return ApplicationPackage{Path: filepath.Join(zipOrDir, "src", "main", "application")}, nil
}
if util.PathExists(filepath.Join(zipOrDir, "services.xml")) {