Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove config validation for cpflow generate command #219

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
rafaelgomesxyz marked this conversation as resolved.
Show resolved Hide resolved
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.unset_config_file
zzaakiirr marked this conversation as resolved.
Show resolved Hide resolved
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
7 changes: 6 additions & 1 deletion spec/support/command_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "")
Expand Down
Loading