From 6b3f7998da190bd0f34f4728644198e244334a85 Mon Sep 17 00:00:00 2001 From: Jon Perry Date: Mon, 31 Jan 2022 21:53:23 +0000 Subject: [PATCH 1/3] check if the confirm flag has been set before prompting for components --- cli/internal/packager/common.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cli/internal/packager/common.go b/cli/internal/packager/common.go index a27401a4ae..04732341b4 100644 --- a/cli/internal/packager/common.go +++ b/cli/internal/packager/common.go @@ -4,7 +4,6 @@ import ( "crypto/sha256" "encoding/hex" "fmt" - "github.com/defenseunicorns/zarf/cli/types" "io" "io/ioutil" "net/http" @@ -13,6 +12,8 @@ import ( "strings" "time" + "github.com/defenseunicorns/zarf/cli/types" + "github.com/goccy/go-yaml" "github.com/AlecAivazis/survey/v2" @@ -99,7 +100,7 @@ func getValidComponents(allComponents []types.ZarfComponent, requestedComponentN // If the component is not required check if the user wants it deployed if !confirmComponent { // Check if this is one of the components that has been requested - if len(requestedComponentNames) > 0 { + if len(requestedComponentNames) > 0 || config.DeployOptions.Confirm { for index, requestedComponent := range requestedComponentNames { if strings.ToLower(requestedComponent) == component.Name { confirmComponent = true From 60bceabe7705747cf542e4f5163e7fed550f6968 Mon Sep 17 00:00:00 2001 From: Jon Perry Date: Mon, 7 Feb 2022 16:24:55 -0500 Subject: [PATCH 2/3] Update interactive confirm to not write response to config This is so we can read the config.confirm value later to determine if the command is being run in 'script' mode. This gives us the ability to be confident if/when we can prompt the user with a question. --- cli/internal/packager/common.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cli/internal/packager/common.go b/cli/internal/packager/common.go index 04732341b4..e8facc96ce 100644 --- a/cli/internal/packager/common.go +++ b/cli/internal/packager/common.go @@ -79,16 +79,18 @@ func confirmAction(configPath string, userMessage string) bool { utils.ColorPrintYAML(text) // Display prompt if not auto-confirmed + var confirmFlag bool if config.DeployOptions.Confirm { message.Infof("%s Zarf package confirmed", userMessage) + return config.DeployOptions.Confirm } else { prompt := &survey.Confirm{ Message: userMessage + " this Zarf package?", } - _ = survey.AskOne(prompt, &config.DeployOptions.Confirm) + _ = survey.AskOne(prompt, &confirmFlag) } - return config.DeployOptions.Confirm + return confirmFlag } func getValidComponents(allComponents []types.ZarfComponent, requestedComponentNames []string) []types.ZarfComponent { From cb62afc767d0176e034b64a42a4cf681c10be648 Mon Sep 17 00:00:00 2001 From: Jon Perry Date: Tue, 8 Feb 2022 10:38:49 -0500 Subject: [PATCH 3/3] add e2e test to verify confirm flag works --- Makefile | 6 +++++- test/e2e/e2e_general_cli_test.go | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 7d8e3530ae..b689348c54 100644 --- a/Makefile +++ b/Makefile @@ -74,6 +74,10 @@ package-example-single-big-bang-package: ## Create the Zarf package for single-b package-example-gitops-data: cd examples/gitops-data && ../../$(ZARF_BIN) package create --confirm && mv zarf-package-* ../../build/ +.PHONY: package-example-tiny-kafka +package-example-tiny-kafka: + cd examples/tiny-kafka && ../../$(ZARF_BIN) package create --confirm && mv zarf-package-* ../../build/ + .PHONY: test-cloud-e2e-example-game test-cloud-e2e-example-game: ## Runs the Doom game as an E2E test in the cloud. Requires access to an AWS account. Costs money. Make sure you ran the `build-cli`, `init-package`, and `package-example-game` targets first cd test/e2e && go test ./... -run TestE2eExampleGame -v -timeout 1200s @@ -97,7 +101,7 @@ test-cloud-e2e-git-based-helm-chart: ################ END Pending removal post-merge .PHONY: test-cloud-e2e-general-cli -test-cloud-e2e-general-cli: ## Runs tests of the CLI that don't need a cluster +test-cloud-e2e-general-cli: package-example-tiny-kafka ## Runs tests of the CLI that don't need a cluster cd test/e2e && go test ./... -run TestGeneralCli -v -timeout 1200s .PHONY: test-e2e diff --git a/test/e2e/e2e_general_cli_test.go b/test/e2e/e2e_general_cli_test.go index 54b80d209d..74afbe1316 100644 --- a/test/e2e/e2e_general_cli_test.go +++ b/test/e2e/e2e_general_cli_test.go @@ -19,6 +19,8 @@ func TestGeneralCli(t *testing.T) { // Upload the Zarf artifacts teststructure.RunTestStage(e2e.testing, "UPLOAD", func() { e2e.syncFileToRemoteServer("../../build/zarf", fmt.Sprintf("/home/%s/build/zarf", e2e.username), "0700") + e2e.syncFileToRemoteServer("../../build/zarf-init.tar.zst", fmt.Sprintf("/home/%s/build/zarf-init.tar.zst", e2e.username), "0700") + e2e.syncFileToRemoteServer("../../build/zarf-package-kafka-strimzi-demo.tar.zst", fmt.Sprintf("/home/%s/build/zarf-package-kafka-strimzi-demo.tar.zst", e2e.username), "0700") }) teststructure.RunTestStage(e2e.testing, "TEST", func() { @@ -57,6 +59,14 @@ func TestGeneralCli(t *testing.T) { output, err = e2e.runSSHCommand("cd /home/%s/build && ./zarf pki regenerate --host some_unique_server", e2e.username) require.Error(e2e.testing, err, output) + // Initialize Zarf for the next set of tests + output, err = e2e.runSSHCommand("sudo bash -c 'cd /home/%s/build && ./zarf init --confirm --components k3s'", e2e.username) + require.NoError(e2e.testing, err, output) + + // Verify that we do not timeout when passing the `--confirm` flag without specifying the `--components` flag + output, err = e2e.runSSHCommand("sudo timeout 120 sudo bash -c 'cd /home/%s/build && ./zarf package deploy zarf-package-kafka-strimzi-demo.tar.zst --confirm' || false", e2e.username) + require.NoError(e2e.testing, err, output) + // Test that `zarf package deploy` doesn't die when given a URL // NOTE: Temporarily commenting this out because this seems out of scope for a general cli test. Having this included also means we would have to fully standup a `zarf init` command. // TODO: Move this to it's own e2e test.