Skip to content

Commit

Permalink
Rename find_app_config_file to config_file_path
Browse files Browse the repository at this point in the history
  • Loading branch information
ahangarha committed Nov 29, 2023
1 parent 652fcf7 commit efa2865
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 15 deletions.
10 changes: 4 additions & 6 deletions lib/core/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,12 @@ def load_apps # rubocop:disable Metrics/MethodLength
ensure_current_config_app!(app) if app
end

def find_app_config_file
def config_file_path
return @config_file_path if @config_file_path

path = Pathname.new(".").expand_path

loop do
@config_file_path = loop do
config_file = path + CONFIG_FILE_LOCATIION
break config_file if File.file?(config_file)

Expand All @@ -153,10 +155,6 @@ def find_app_config_file
end
end

def config_file_path
@config_file_path ||= find_app_config_file
end

def new_option_keys
{
org: :cpln_org,
Expand Down
2 changes: 1 addition & 1 deletion spec/command/cleanup_images_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
allow(ENV).to receive(:fetch).with("CPLN_ENDPOINT", "https://api.cpln.io").and_return("https://api.cpln.io")
allow(ENV).to receive(:fetch).with("CPLN_TOKEN", nil).and_return("token")
allow(ENV).to receive(:fetch).with("CPLN_ORG", nil).and_return(nil)
allow_any_instance_of(Config).to receive(:find_app_config_file).and_return("spec/fixtures/config.yml") # rubocop:disable RSpec/AnyInstance
allow_any_instance_of(Config).to receive(:config_file_path).and_return("spec/fixtures/config.yml") # rubocop:disable RSpec/AnyInstance

Timecop.freeze(Time.local(2023, 8, 23))
end
Expand Down
2 changes: 1 addition & 1 deletion spec/command/copy_image_from_upstream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
allow(ENV).to receive(:fetch).with("CPLN_ENDPOINT", "https://api.cpln.io").and_return("https://api.cpln.io")
allow(ENV).to receive(:fetch).with("CPLN_TOKEN", nil).and_return("token")
allow(ENV).to receive(:fetch).with("CPLN_ORG", nil).and_return(nil)
allow_any_instance_of(Config).to receive(:find_app_config_file).and_return("spec/fixtures/config.yml")
allow_any_instance_of(Config).to receive(:config_file_path).and_return("spec/fixtures/config.yml")
allow_any_instance_of(described_class).to receive(:ensure_docker_running!)
allow_any_instance_of(Controlplane).to receive(:profile_exists?).and_return(false)
allow_any_instance_of(Controlplane).to receive(:profile_create).and_return(true)
Expand Down
2 changes: 1 addition & 1 deletion spec/command/maintenance_off_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
allow(ENV).to receive(:fetch).with("CPLN_ENDPOINT", "https://api.cpln.io").and_return("https://api.cpln.io")
allow(ENV).to receive(:fetch).with("CPLN_TOKEN", nil).and_return("token")
allow(ENV).to receive(:fetch).with("CPLN_ORG", nil).and_return(nil)
allow_any_instance_of(Config).to receive(:find_app_config_file).and_return("spec/fixtures/config.yml")
allow_any_instance_of(Config).to receive(:config_file_path).and_return("spec/fixtures/config.yml")
allow_any_instance_of(described_class).to receive(:sleep).and_return(true)
end
# rubocop:enable RSpec/AnyInstance
Expand Down
2 changes: 1 addition & 1 deletion spec/command/maintenance_on_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
allow(ENV).to receive(:fetch).with("CPLN_ENDPOINT", "https://api.cpln.io").and_return("https://api.cpln.io")
allow(ENV).to receive(:fetch).with("CPLN_TOKEN", nil).and_return("token")
allow(ENV).to receive(:fetch).with("CPLN_ORG", nil).and_return(nil)
allow_any_instance_of(Config).to receive(:find_app_config_file).and_return("spec/fixtures/config.yml")
allow_any_instance_of(Config).to receive(:config_file_path).and_return("spec/fixtures/config.yml")
allow_any_instance_of(described_class).to receive(:sleep).and_return(true)
end
# rubocop:enable RSpec/AnyInstance
Expand Down
2 changes: 1 addition & 1 deletion spec/command/maintenance_set_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
allow(ENV).to receive(:fetch).with("CPLN_ENDPOINT", "https://api.cpln.io").and_return("https://api.cpln.io")
allow(ENV).to receive(:fetch).with("CPLN_TOKEN", nil).and_return("token")
allow(ENV).to receive(:fetch).with("CPLN_ORG", nil).and_return(nil)
allow_any_instance_of(Config).to receive(:find_app_config_file).and_return("spec/fixtures/config.yml") # rubocop:disable RSpec/AnyInstance
allow_any_instance_of(Config).to receive(:config_file_path).and_return("spec/fixtures/config.yml") # rubocop:disable RSpec/AnyInstance
end

it "displays error if maintenance workload is not found", vcr: true do
Expand Down
2 changes: 1 addition & 1 deletion spec/command/maintenance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
allow(ENV).to receive(:fetch).with("CPLN_ENDPOINT", "https://api.cpln.io").and_return("https://api.cpln.io")
allow(ENV).to receive(:fetch).with("CPLN_TOKEN", nil).and_return("token")
allow(ENV).to receive(:fetch).with("CPLN_ORG", nil).and_return(nil)
allow_any_instance_of(Config).to receive(:find_app_config_file).and_return("spec/fixtures/config.yml") # rubocop:disable RSpec/AnyInstance
allow_any_instance_of(Config).to receive(:config_file_path).and_return("spec/fixtures/config.yml") # rubocop:disable RSpec/AnyInstance
end

it "displays error if domain is not found", vcr: true do
Expand Down
2 changes: 1 addition & 1 deletion spec/command/run_cleanup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
allow(ENV).to receive(:fetch).with("CPLN_ENDPOINT", "https://api.cpln.io").and_return("https://api.cpln.io")
allow(ENV).to receive(:fetch).with("CPLN_TOKEN", nil).and_return("token")
allow(ENV).to receive(:fetch).with("CPLN_ORG", nil).and_return(nil)
allow_any_instance_of(Config).to receive(:find_app_config_file).and_return("spec/fixtures/config.yml") # rubocop:disable RSpec/AnyInstance
allow_any_instance_of(Config).to receive(:config_file_path).and_return("spec/fixtures/config.yml") # rubocop:disable RSpec/AnyInstance

Timecop.freeze(Time.local(2023, 5, 15))
end
Expand Down
4 changes: 2 additions & 2 deletions spec/cpl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
end
end

allow_any_instance_of(Config).to receive(:find_app_config_file).and_return("spec/fixtures/config.yml") # rubocop:disable RSpec/AnyInstance
allow_any_instance_of(Config).to receive(:config_file_path).and_return("spec/fixtures/config.yml") # rubocop:disable RSpec/AnyInstance
expect_any_instance_of(command_class).to receive(:call) # rubocop:disable RSpec/AnyInstance

Cpl::Cli.start([command_class::NAME, *args])
Expand All @@ -39,7 +39,7 @@

allow(Config).to receive(:new).with([], { option[:name].to_sym => option_value }).and_call_original

allow_any_instance_of(Config).to receive(:find_app_config_file).and_return("spec/fixtures/config.yml") # rubocop:disable RSpec/AnyInstance
allow_any_instance_of(Config).to receive(:config_file_path).and_return("spec/fixtures/config.yml") # rubocop:disable RSpec/AnyInstance
expect_any_instance_of(Command::Test).to receive(:call) # rubocop:disable RSpec/AnyInstance

Cpl::Cli.start(["test", *args])
Expand Down

0 comments on commit efa2865

Please sign in to comment.