Skip to content

Commit 82ff517

Browse files
authored
Remove config validation for cpflow generate command (#219)
1 parent 66e532b commit 82ff517

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

lib/command/generate.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Generate < Base
2626
```
2727
EX
2828
WITH_INFO_HEADER = false
29+
VALIDATIONS = [].freeze
2930

3031
def call
3132
if controlplane_directory_exists?

spec/command/generate_spec.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ def inside_dir(path)
1717
Dir.chdir original_working_dir
1818
end
1919

20-
describe Command::Generate do
20+
describe Command::Generate, :enable_validations, :without_config_file do
21+
let(:controlplane_config_file_path) { CONTROLPLANE_CONFIG_DIR_PATH.join("controlplane.yml") }
22+
2123
before do
2224
FileUtils.rm_r(GENERATOR_PLAYGROUND_PATH) if Dir.exist?(GENERATOR_PLAYGROUND_PATH)
2325
FileUtils.mkdir_p GENERATOR_PLAYGROUND_PATH
@@ -30,23 +32,30 @@ def inside_dir(path)
3032
context "when no configuration exist in the project" do
3133
it "generates base config files" do
3234
inside_dir(GENERATOR_PLAYGROUND_PATH) do
35+
expect(controlplane_config_file_path).not_to exist
36+
3337
Cpflow::Cli.start([described_class::NAME])
34-
controlplane_config_file_path = CONTROLPLANE_CONFIG_DIR_PATH.join("controlplane.yml")
38+
3539
expect(controlplane_config_file_path).to exist
3640
end
3741
end
3842
end
3943

4044
context "when .controlplane directory already exist" do
45+
let(:controlplane_config_dir) { controlplane_config_file_path.parent }
46+
47+
before do
48+
Dir.mkdir(controlplane_config_dir)
49+
end
50+
4151
it "doesn't generates base config files" do
4252
inside_dir(GENERATOR_PLAYGROUND_PATH) do
43-
Dir.mkdir(CONTROLPLANE_CONFIG_DIR_PATH)
53+
expect(controlplane_config_dir).to exist
4454

4555
expect do
4656
Cpflow::Cli.start([described_class::NAME])
4757
end.to output(/already exist/).to_stderr
4858

49-
controlplane_config_file_path = CONTROLPLANE_CONFIG_DIR_PATH.join("controlplane.yml")
5059
expect(controlplane_config_file_path).not_to exist
5160
end
5261
end

spec/spec_helper.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,16 @@
152152
# Times out after 10 minutes
153153
Timeout.timeout(600) { example.run }
154154
end
155+
156+
config.around(:example, :without_config_file) do |example|
157+
CommandHelpers.delete_config_file
158+
example.run
159+
CommandHelpers.configure_config_file
160+
end
161+
162+
config.around(:example, :enable_validations) do |example|
163+
ENV["DISABLE_VALIDATIONS"] = "false"
164+
example.run
165+
ENV["DISABLE_VALIDATIONS"] = "true"
166+
end
155167
end

spec/support/command_helpers.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ def delete_config_file
6767
return unless @@tmp_config_file
6868

6969
File.delete(@@tmp_config_file.path)
70+
7071
@@tmp_config_file = nil # rubocop:disable Style/ClassVars
72+
ENV["CONFIG_FILE_PATH"] = nil
7173
end
7274

7375
def temporarily_switch_config_file(extra_prefix = "")

0 commit comments

Comments
 (0)