From e170349b43453c22d7f99bcaf8a004a4e0ac8c40 Mon Sep 17 00:00:00 2001 From: Zakir Dzhamaliddinov Date: Thu, 25 Jul 2024 14:21:13 +0300 Subject: [PATCH] Remove config validation for cpflow generate command --- lib/command/generate.rb | 1 + spec/command/generate_spec.rb | 17 +++++++++++++---- spec/spec_helper.rb | 12 ++++++++++++ spec/support/command_helpers.rb | 7 ++++++- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/lib/command/generate.rb b/lib/command/generate.rb index 64d41425..22b47f70 100644 --- a/lib/command/generate.rb +++ b/lib/command/generate.rb @@ -26,6 +26,7 @@ class Generate < Base ``` EX WITH_INFO_HEADER = false + VALIDATIONS = [].freeze def call if controlplane_directory_exists? diff --git a/spec/command/generate_spec.rb b/spec/command/generate_spec.rb index 4d8069e4..705ae337 100644 --- a/spec/command/generate_spec.rb +++ b/spec/command/generate_spec.rb @@ -17,7 +17,9 @@ def inside_dir(path) Dir.chdir original_working_dir end -describe Command::Generate do +describe Command::Generate, :enable_validations, :without_config_file do + let(:controlplane_config_file_path) { CONTROLPLANE_CONFIG_DIR_PATH.join("controlplane.yml") } + before do FileUtils.rm_r(GENERATOR_PLAYGROUND_PATH) if Dir.exist?(GENERATOR_PLAYGROUND_PATH) FileUtils.mkdir_p GENERATOR_PLAYGROUND_PATH @@ -30,23 +32,30 @@ def inside_dir(path) context "when no configuration exist in the project" do it "generates base config files" do inside_dir(GENERATOR_PLAYGROUND_PATH) do + expect(controlplane_config_file_path).not_to exist + Cpflow::Cli.start([described_class::NAME]) - controlplane_config_file_path = CONTROLPLANE_CONFIG_DIR_PATH.join("controlplane.yml") + expect(controlplane_config_file_path).to exist end end end context "when .controlplane directory already exist" do + let(:controlplane_config_dir) { controlplane_config_file_path.parent } + + before do + Dir.mkdir(controlplane_config_dir) + end + it "doesn't generates base config files" do inside_dir(GENERATOR_PLAYGROUND_PATH) do - Dir.mkdir(CONTROLPLANE_CONFIG_DIR_PATH) + expect(controlplane_config_dir).to exist expect do Cpflow::Cli.start([described_class::NAME]) end.to output(/already exist/).to_stderr - controlplane_config_file_path = CONTROLPLANE_CONFIG_DIR_PATH.join("controlplane.yml") expect(controlplane_config_file_path).not_to exist end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ec8ccfec..383a3d6d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -152,4 +152,16 @@ # Times out after 10 minutes Timeout.timeout(600) { example.run } end + + config.around(:example, :without_config_file) do |example| + CommandHelpers.unset_config_file + example.run + CommandHelpers.configure_config_file + end + + config.around(:example, :enable_validations) do |example| + ENV["DISABLE_VALIDATIONS"] = "false" + example.run + ENV["DISABLE_VALIDATIONS"] = "true" + end end diff --git a/spec/support/command_helpers.rb b/spec/support/command_helpers.rb index 6e275083..f6914c33 100644 --- a/spec/support/command_helpers.rb +++ b/spec/support/command_helpers.rb @@ -63,11 +63,16 @@ def configure_config_file(extra_prefix = "") ENV["CONFIG_FILE_PATH"] = @@tmp_config_file.path end + def unset_config_file + @@tmp_config_file = nil # rubocop:disable Style/ClassVars + ENV["CONFIG_FILE_PATH"] = nil + end + def delete_config_file return unless @@tmp_config_file File.delete(@@tmp_config_file.path) - @@tmp_config_file = nil # rubocop:disable Style/ClassVars + unset_config_file end def temporarily_switch_config_file(extra_prefix = "")