Skip to content

Commit

Permalink
Add disabling specified applications
Browse files Browse the repository at this point in the history
  • Loading branch information
otahi committed Nov 29, 2014
1 parent b73020f commit f46fe6c
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/vagrant-proxyconf/action/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(app, env)
def call(env)
@machine = env[:machine]

if !config.enabled?
if disabled?
logger.info I18n.t("vagrant_proxyconf.#{config_name}.not_enabled")
elsif !supported?
logger.info I18n.t("vagrant_proxyconf.#{config_name}.not_supported")
Expand Down Expand Up @@ -106,6 +106,16 @@ def cap_name
"#{config_name}_conf".to_sym
end

def disabled?
enabled = @machine.config.proxy.enabled
return true if enabled == false

app_name = config_name.gsub(/_proxy/, '').to_sym
return enabled[app_name] == false if enabled.respond_to?(:key)

!config.enabled?
end

def supported?
@machine.guest.capability?(cap_name) &&
@machine.guest.capability(cap_name)
Expand Down
67 changes: 67 additions & 0 deletions spec/unit/vagrant-proxyconf/action/configure_env_proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,71 @@
it { is_expected.to eq 'env_proxy' }
end

describe '#disabled?' do
subject do
conf = described_class.new(double, double)
allow(conf).to receive_message_chain(:config, :enabled?)
.and_return(@config_enabled)
machine = double('machine')
allow(machine).to receive_message_chain(:config, :proxy, :enabled)
.and_return(@config_proxy_enabled)
conf.instance_variable_set(:@machine, machine)
conf.send(:disabled?)
end

context 'when both config and proxy are enabled' do
it do
@config_enabled = true
@config_proxy_enabled = true
is_expected.to eq false
end
end
context 'when config is enabled and config proxy is not enabled' do
it do
@config_enabled = true
@config_proxy_enabled = false
is_expected.to eq true
end
end
context 'when config enabled is not enabled and proxy is enabled' do
it do
@config_enabled = false
@config_proxy_enabled = true
is_expected.to eq true
end
end

context 'when both config and target proxy are enabled' do
it do
@config_enabled = true
@config_proxy_enabled = { env: true }
is_expected.to eq false
end
end
context 'when config is enabled and target proxy target is not enabled' do
it do
@config_enabled = true
@config_proxy_enabled = { env: false }
is_expected.to eq true
end
end
context 'when config is enabled and other proxy are not enabled' do
it do
@config_enabled = true
@config_proxy_enabled = {
svn: false,
apt: false,
chef: false,
docker: false,
git: false,
npm: false,
pear: false,
svn: false,
yum: false
}
is_expected.to eq false
end

end
end
end

0 comments on commit f46fe6c

Please sign in to comment.