Skip to content

Commit

Permalink
Remove config validation for cpflow generate command (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzaakiirr authored Jul 31, 2024
1 parent 66e532b commit 82ff517
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/command/generate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Generate < Base
```
EX
WITH_INFO_HEADER = false
VALIDATIONS = [].freeze

def call
if controlplane_directory_exists?
Expand Down
17 changes: 13 additions & 4 deletions spec/command/generate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions spec/support/command_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "")
Expand Down

0 comments on commit 82ff517

Please sign in to comment.