From 82ff517297fa79e066192d9d298f32c8820b77d2 Mon Sep 17 00:00:00 2001 From: Zakir Dzhamaliddinov Date: Wed, 31 Jul 2024 19:38:51 +0300 Subject: [PATCH] Remove config validation for cpflow generate command (#219) --- lib/command/generate.rb | 1 + spec/command/generate_spec.rb | 17 +++++++++++++---- spec/spec_helper.rb | 12 ++++++++++++ spec/support/command_helpers.rb | 2 ++ 4 files changed, 28 insertions(+), 4 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..1a319a27 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.delete_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..189c5f44 100644 --- a/spec/support/command_helpers.rb +++ b/spec/support/command_helpers.rb @@ -67,7 +67,9 @@ def delete_config_file return unless @@tmp_config_file File.delete(@@tmp_config_file.path) + @@tmp_config_file = nil # rubocop:disable Style/ClassVars + ENV["CONFIG_FILE_PATH"] = nil end def temporarily_switch_config_file(extra_prefix = "")