1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
#! /usr/bin/env ruby
require 'spec_helper'
require 'puppet/face'
describe Puppet::Face[:plugin, :current] do
let(:pluginface) { described_class }
let(:action) { pluginface.get_action(:download) }
def render(result)
action.when_rendering(:console).call(result)
end
context "download" do
before :each do
#Server_agent version needs to be at 5.3.4 in order to mount locales
Puppet.push_context({:server_agent_version => "5.3.4"})
end
it "downloads plugins, external facts, and locales" do
Puppet::Configurer::Downloader.any_instance.expects(:evaluate).times(3).returns([])
pluginface.download
end
it "renders 'No plugins downloaded' if nothing was downloaded" do
Puppet::Configurer::Downloader.any_instance.expects(:evaluate).times(3).returns([])
result = pluginface.download
expect(render(result)).to eq('No plugins downloaded.')
end
it "renders comma separate list of downloaded file names" do
Puppet::Configurer::Downloader.any_instance.expects(:evaluate).times(3).returns(%w[/a]).then.returns(%w[/b]).then.returns(%w[/c])
result = pluginface.download
expect(render(result)).to eq('Downloaded these plugins: /a, /b, /c')
end
end
context "download when server_agent_version is 5.3.3" do
before :each do
#Server_agent version needs to be at 5.3.4 in order to mount locales
Puppet.push_context({:server_agent_version => "5.3.3"})
end
it "downloads plugins, and external facts, but not locales" do
Puppet::Configurer::Downloader.any_instance.expects(:evaluate).times(2).returns([])
pluginface.download
end
it "renders comma separate list of downloaded file names that does not include locales" do
Puppet::Configurer::Downloader.any_instance.expects(:evaluate).times(2).returns(%w[/a]).then.returns(%w[/b])
result = pluginface.download
expect(render(result)).to eq('Downloaded these plugins: /a, /b')
end
end
context "download when server_agent_version is blank" do
before :each do
#Server_agent version needs to be at 5.3.4 in order to mount locales
#A blank version will default to 0.0
Puppet.push_context({:server_agent_version => ""})
end
it "downloads plugins, and external facts, but not locales" do
Puppet::Configurer::Downloader.any_instance.expects(:evaluate).times(2).returns([])
pluginface.download
end
it "renders comma separate list of downloaded file names that does not include locales" do
Puppet::Configurer::Downloader.any_instance.expects(:evaluate).times(2).returns(%w[/a]).then.returns(%w[/b])
result = pluginface.download
expect(render(result)).to eq('Downloaded these plugins: /a, /b')
end
end
end
|