aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/internal/cli/cmd/prod_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'client/go/internal/cli/cmd/prod_test.go')
-rw-r--r--client/go/internal/cli/cmd/prod_test.go47
1 files changed, 19 insertions, 28 deletions
diff --git a/client/go/internal/cli/cmd/prod_test.go b/client/go/internal/cli/cmd/prod_test.go
index 944f09b3d42..4cca54a76c8 100644
--- a/client/go/internal/cli/cmd/prod_test.go
+++ b/client/go/internal/cli/cmd/prod_test.go
@@ -50,12 +50,12 @@ func TestProdInit(t *testing.T) {
assert.Nil(t, cli.Run("prod", "init", pkgDir))
// Verify contents
- deploymentPath := filepath.Join(pkgDir, "src", "main", "application", "deployment.xml")
+ deploymentPath := filepath.Join(pkgDir, "deployment.xml")
deploymentXML := readFileString(t, deploymentPath)
assert.Contains(t, deploymentXML, `<region>aws-us-west-2a</region>`)
assert.Contains(t, deploymentXML, `<region>aws-eu-west-1a</region>`)
- servicesPath := filepath.Join(pkgDir, "src", "main", "application", "services.xml")
+ servicesPath := filepath.Join(pkgDir, "services.xml")
servicesXML := readFileString(t, servicesPath)
containerFragment := `<container id="qrs" version="1.0">
<document-api></document-api>
@@ -80,6 +80,7 @@ func TestProdInit(t *testing.T) {
}
func readFileString(t *testing.T, filename string) string {
+ t.Helper()
content, err := os.ReadFile(filename)
if err != nil {
t.Fatal(err)
@@ -88,12 +89,15 @@ func readFileString(t *testing.T, filename string) string {
}
func createApplication(t *testing.T, pkgDir string, java bool, skipTests bool) {
- appDir := filepath.Join(pkgDir, "src", "main", "application")
- targetDir := filepath.Join(pkgDir, "target")
+ appDir := pkgDir
+ testsDir := pkgDir
+ if java {
+ appDir = filepath.Join(pkgDir, "target", "application")
+ testsDir = filepath.Join(pkgDir, "target", "application-test")
+ }
if err := os.MkdirAll(appDir, 0755); err != nil {
t.Fatal(err)
}
-
deploymentXML := `<deployment version="1.0">
<prod>
<region>aws-us-east-1c</region>
@@ -102,7 +106,6 @@ func createApplication(t *testing.T, pkgDir string, java bool, skipTests bool) {
if err := os.WriteFile(filepath.Join(appDir, "deployment.xml"), []byte(deploymentXML), 0644); err != nil {
t.Fatal(err)
}
-
servicesXML := `<services version="1.0" xmlns:deploy="vespa" xmlns:preprocess="properties">
<container id="qrs" version="1.0">
<document-api/>
@@ -123,19 +126,16 @@ func createApplication(t *testing.T, pkgDir string, java bool, skipTests bool) {
if err := os.WriteFile(filepath.Join(appDir, "services.xml"), []byte(servicesXML), 0644); err != nil {
t.Fatal(err)
}
- if err := os.MkdirAll(targetDir, 0755); err != nil {
- t.Fatal(err)
- }
if java {
- if skipTests {
- t.Fatalf("skipTests=%t has no effect when java=%t", skipTests, java)
- }
if err := os.WriteFile(filepath.Join(pkgDir, "pom.xml"), []byte(""), 0644); err != nil {
t.Fatal(err)
}
- } else if !skipTests {
- testsDir := filepath.Join(pkgDir, "src", "test", "application", "tests")
- testBytes, _ := io.ReadAll(strings.NewReader("{\"steps\":[{}]}"))
+ }
+ if !skipTests {
+ if err := os.MkdirAll(testsDir, 0755); err != nil {
+ t.Fatal(err)
+ }
+ testBytes := []byte("{\"steps\":[{}]}")
writeTest(filepath.Join(testsDir, "system-test", "test.json"), testBytes, t)
writeTest(filepath.Join(testsDir, "staging-setup", "test.json"), testBytes, t)
writeTest(filepath.Join(testsDir, "staging-test", "test.json"), testBytes, t)
@@ -203,23 +203,17 @@ func TestProdDeployWithJava(t *testing.T) {
httpClient := &mock.HTTPClient{}
httpClient.NextResponseString(200, `ok`)
- cli, stdout, _ := newTestCLI(t, "CI=true")
+ cli, stdout, stderr := newTestCLI(t, "CI=true")
cli.httpClient = httpClient
assert.Nil(t, cli.Run("config", "set", "application", "t1.a1.i1"))
assert.Nil(t, cli.Run("config", "set", "target", "cloud"))
assert.Nil(t, cli.Run("auth", "api-key"))
assert.Nil(t, cli.Run("auth", "cert", "--no-add"))
- // 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)
- testZipFile := filepath.Join(testAppDir, "application-test.zip")
- copyFile(t, filepath.Join(pkgDir, "target", "application-test.zip"), testZipFile)
-
stdout.Reset()
cli.Environment["VESPA_CLI_API_KEY_FILE"] = filepath.Join(cli.config.homeDir, "t1.api-key.pem")
- assert.Nil(t, cli.Run("prod", "deploy", pkgDir))
+ assert.Nil(t, cli.Run("prod", "deploy", "--add-cert", pkgDir))
+ assert.Equal(t, "", stderr.String())
assert.Contains(t, stdout.String(), "Success: Deployed")
assert.Contains(t, stdout.String(), "See https://console.vespa-cloud.com/tenant/t1/application/a1/prod/deployment for deployment progress")
}
@@ -240,11 +234,8 @@ func TestProdDeployInvalidZip(t *testing.T) {
// Copy an invalid application package containing relative file names
testAppDir := filepath.Join("testdata", "applications", "withInvalidEntries", "target")
zipFile := filepath.Join(testAppDir, "application.zip")
- copyFile(t, filepath.Join(pkgDir, "target", "application.zip"), zipFile)
- testZipFile := filepath.Join(testAppDir, "application-test.zip")
- copyFile(t, filepath.Join(pkgDir, "target", "application-test.zip"), testZipFile)
- assert.NotNil(t, cli.Run("prod", "deploy", pkgDir))
+ assert.NotNil(t, cli.Run("prod", "deploy", zipFile))
assert.Equal(t, "Error: found invalid path inside zip: ../../../../../../../tmp/foo\n", stderr.String())
}