Skip to content

Commit

Permalink
Renamed PROBE_DOCK to PROBEDOCK in environment variables (old variabl…
Browse files Browse the repository at this point in the history
…es still work for now).
  • Loading branch information
AlphaHydrae committed Aug 20, 2015
1 parent 6ef3d68 commit b5d96ea
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
10 changes: 7 additions & 3 deletions lib/probe_dock_ruby/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def home_config_file
end

def working_config_file
File.expand_path ENV['PROBE_DOCK_CONFIG'] || 'probedock.yml', Dir.pwd
File.expand_path parse_env_option(:config) || 'probedock.yml', Dir.pwd
end

def parse_env_flag name, default = false
Expand All @@ -157,8 +157,12 @@ def parse_env_flag name, default = false
end

def parse_env_option name
var = "PROBE_DOCK_#{name.upcase}"
ENV.key?(var) ? ENV[var] : nil

var = "PROBEDOCK_#{name.to_s.upcase}"
return ENV[var] if ENV.key? var

old_var = "PROBE_DOCK_#{name.to_s.upcase}"
ENV.key?(old_var) ? ENV[old_var] : nil
end

def parse_general_options h
Expand Down
9 changes: 6 additions & 3 deletions lib/probe_dock_ruby/uid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
module ProbeDockProbe

class UID
ENVIRONMENT_VARIABLE = 'PROBE_DOCK_TEST_REPORT_UID'
ENVIRONMENT_VARIABLE = 'PROBEDOCK_TEST_REPORT_UID'
OLD_ENVIRONMENT_VARIABLE = 'PROBE_DOCK_TEST_REPORT_UID'

class Error < ProbeDockProbe::Error; end

Expand All @@ -25,12 +26,14 @@ def generate_uid_to_file
end

def generate_uid_to_env
raise Error.new("$PROBE_DOCK_TEST_REPORT_UID is already defined") if env_var
raise Error.new("$PROBEDOCK_TEST_REPORT_UID is already defined") if env_var
ENV[ENVIRONMENT_VARIABLE] = generate_uid
ENV.delete OLD_ENVIRONMENT_VARIABLE
end

def clean_uid
ENV.delete ENVIRONMENT_VARIABLE
ENV.delete OLD_ENVIRONMENT_VARIABLE
FileUtils.remove_entry_secure uid_file if @workspace and File.exists?(uid_file)
end

Expand All @@ -42,7 +45,7 @@ def save_uid uid
end

def env_var
ENV[ENVIRONMENT_VARIABLE]
ENV[ENVIRONMENT_VARIABLE] || ENV[OLD_ENVIRONMENT_VARIABLE]
end

def current_uid
Expand Down
10 changes: 5 additions & 5 deletions spec/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
end

before :each do
@probe_dock_env_vars = ENV.select{ |k,v| k.match /\APROBE_DOCK_/ }.each_key{ |k| ENV.delete k }
@probe_dock_env_vars = ENV.select{ |k,v| k.match /\APROBEDOCK_/ }.each_key{ |k| ENV.delete k }
end

after :each do
Expand Down Expand Up @@ -273,7 +273,7 @@
}
end

before(:each){ probe_dock_env_vars.each_pair{ |k,v| ENV["PROBE_DOCK_#{k.upcase}"] = v } }
before(:each){ probe_dock_env_vars.each_pair{ |k,v| ENV["PROBEDOCK_#{k.upcase}"] = v } }

it "should override the selected server" do
expect(loaded_config.server).to have_received(:api_url=).with('http://yet-another-subdomain.example.com')
Expand All @@ -292,7 +292,7 @@
print_payload: '1'
}
end
before(:each){ probe_dock_env_vars.each_pair{ |k,v| ENV["PROBE_DOCK_#{k.upcase}"] = v } }
before(:each){ probe_dock_env_vars.each_pair{ |k,v| ENV["PROBEDOCK_#{k.upcase}"] = v } }

it "should have no load warnings" do
expect(subject.load_warnings).to be_empty
Expand Down Expand Up @@ -358,9 +358,9 @@

it_should_behave_like "an overriden config"

describe "with $PROBE_DOCK_CONFIG overriding the working file path" do
describe "with $PROBEDOCK_CONFIG overriding the working file path" do
let(:working_config_path){ '/tmp/foo/probedock.yml' }
before(:each){ ENV['PROBE_DOCK_CONFIG'] = '/tmp/foo/probedock.yml' }
before(:each){ ENV['PROBEDOCK_CONFIG'] = '/tmp/foo/probedock.yml' }
it_should_behave_like "an overriden config"
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
let(:http_responses){ [] }

before :each do
ENV.delete_if{ |k,v| k.match(/\APROBE_DOCK_/) }
ENV.delete_if{ |k,v| k.match(/\APROBEDOCK_/) }
allow(HTTParty).to receive(:get){ http_responses.shift }
allow(HTTParty).to receive(:post){ http_responses.shift }
end
Expand Down
6 changes: 3 additions & 3 deletions spec/uid_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

describe ProbeDockProbe::UID, fakefs: true do
UID ||= ProbeDockProbe::UID
ENVIRONMENT_VARIABLE = 'PROBE_DOCK_TEST_REPORT_UID'
ENVIRONMENT_VARIABLE = 'PROBEDOCK_TEST_REPORT_UID'
UID_REGEXP = /\d{14}\-[a-f0-9]{8}\-[a-f0-9]{4}\-[a-f0-9]{4}\-[a-f0-9]{4}\-[a-f0-9]{12}/

let(:workspace){ '/tmp' }
let(:uid_options){ { workspace: workspace } }
subject{ UID.new uid_options }

before :each do
@probe_dock_env_vars = ENV.select{ |k,v| k.match /\APROBE_DOCK_/ }.each_key{ |k| ENV.delete k }
@probe_dock_env_vars = ENV.select{ |k,v| k.match /\APROBEDOCK_/ }.each_key{ |k| ENV.delete k }
end

after :each do
Expand Down Expand Up @@ -81,7 +81,7 @@
end

it "should raise an error" do
expect{ subject.generate_uid_to_env }.to raise_error(UID::Error, /\$PROBE_DOCK_TEST_REPORT_UID is already defined/)
expect{ subject.generate_uid_to_env }.to raise_error(UID::Error, /\$PROBEDOCK_TEST_REPORT_UID is already defined/)
end
end
end
Expand Down

0 comments on commit b5d96ea

Please sign in to comment.