From adba4c67cb1bb366cc39858ce549a8ded554ed3c Mon Sep 17 00:00:00 2001 From: Martin Polden Date: Fri, 18 Nov 2022 09:55:21 +0100 Subject: Do not require tests in prod submit Fixes #24907 --- client/go/cmd/prod.go | 3 +++ client/go/cmd/prod_test.go | 25 +++++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) (limited to 'client/go/cmd') diff --git a/client/go/cmd/prod.go b/client/go/cmd/prod.go index 46b7a673215..6b5470aaa6c 100644 --- a/client/go/cmd/prod.go +++ b/client/go/cmd/prod.go @@ -363,6 +363,9 @@ func prompt(cli *CLI, stdin *bufio.Reader, question, defaultAnswer string, valid } func verifyTests(cli *CLI, app vespa.ApplicationPackage) error { + if !app.HasTests() { + return nil + } // TODO: system-test, staging-setup and staging-test should be required if the application // does not have any Java tests. suites := map[string]bool{ diff --git a/client/go/cmd/prod_test.go b/client/go/cmd/prod_test.go index eff06cf860e..c9584511203 100644 --- a/client/go/cmd/prod_test.go +++ b/client/go/cmd/prod_test.go @@ -17,7 +17,7 @@ import ( func TestProdInit(t *testing.T) { pkgDir := filepath.Join(t.TempDir(), "app") - createApplication(t, pkgDir, false) + createApplication(t, pkgDir, false, false) answers := []string{ // Regions @@ -85,7 +85,7 @@ func readFileString(t *testing.T, filename string) string { return string(content) } -func createApplication(t *testing.T, pkgDir string, java bool) { +func createApplication(t *testing.T, pkgDir string, java bool, skipTests bool) { appDir := filepath.Join(pkgDir, "src", "main", "application") targetDir := filepath.Join(pkgDir, "target") if err := os.MkdirAll(appDir, 0755); err != nil { @@ -125,10 +125,13 @@ func createApplication(t *testing.T, pkgDir string, java bool) { 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 { + } else if !skipTests { testsDir := filepath.Join(pkgDir, "src", "test", "application", "tests") testBytes, _ := io.ReadAll(strings.NewReader("{\"steps\":[{}]}")) writeTest(filepath.Join(testsDir, "system-test", "test.json"), testBytes, t) @@ -148,8 +151,18 @@ func writeTest(path string, content []byte, t *testing.T) { func TestProdSubmit(t *testing.T) { pkgDir := filepath.Join(t.TempDir(), "app") - createApplication(t, pkgDir, false) + createApplication(t, pkgDir, false, false) + prodSubmit(pkgDir, t) +} + +func TestProdSubmitWithoutTests(t *testing.T) { + pkgDir := filepath.Join(t.TempDir(), "app") + createApplication(t, pkgDir, false, true) + prodSubmit(pkgDir, t) +} +func prodSubmit(pkgDir string, t *testing.T) { + t.Helper() httpClient := &mock.HTTPClient{} httpClient.NextResponseString(200, `ok`) @@ -192,7 +205,7 @@ func TestProdSubmit(t *testing.T) { func TestProdSubmitWithJava(t *testing.T) { pkgDir := filepath.Join(t.TempDir(), "app") - createApplication(t, pkgDir, true) + createApplication(t, pkgDir, true, false) httpClient := &mock.HTTPClient{} httpClient.NextResponseString(200, `ok`) @@ -219,7 +232,7 @@ func TestProdSubmitWithJava(t *testing.T) { func TestProdSubmitInvalidZip(t *testing.T) { pkgDir := filepath.Join(t.TempDir(), "app") - createApplication(t, pkgDir, true) + createApplication(t, pkgDir, true, false) httpClient := &mock.HTTPClient{} httpClient.NextResponseString(200, `ok`) -- cgit v1.2.3