|
| 1 | +#! /usr/bin/env ruby |
| 2 | +require 'spec_helper' |
| 3 | +require 'puppet/configurer' |
| 4 | + |
| 5 | +describe Puppet::Configurer::DownloaderFactory do |
| 6 | + let(:factory) { Puppet::Configurer::DownloaderFactory.new } |
| 7 | + let(:environment) { Puppet::Node::Environment.create(:myenv, []) } |
| 8 | + |
| 9 | + let(:plugin_downloader) do |
| 10 | + factory.create_plugin_downloader(environment) |
| 11 | + end |
| 12 | + |
| 13 | + let(:facts_downloader) do |
| 14 | + factory.create_plugin_facts_downloader(environment) |
| 15 | + end |
| 16 | + |
| 17 | + def ignores_source_permissions(downloader) |
| 18 | + expect(downloader.file[:source_permissions]).to eq(:ignore) |
| 19 | + end |
| 20 | + |
| 21 | + def uses_source_permissions(downloader) |
| 22 | + expect(downloader.file[:source_permissions]).to eq(:use) |
| 23 | + end |
| 24 | + |
| 25 | + context "when creating a plugin downloader for modules" do |
| 26 | + it 'is named "plugin"' do |
| 27 | + expect(plugin_downloader.name).to eq('plugin') |
| 28 | + end |
| 29 | + |
| 30 | + it 'downloads files into Puppet[:plugindest]' do |
| 31 | + plugindest = File.expand_path("/tmp/pdest") |
| 32 | + Puppet[:plugindest] = plugindest |
| 33 | + |
| 34 | + expect(plugin_downloader.file[:path]).to eq(plugindest) |
| 35 | + end |
| 36 | + |
| 37 | + it 'downloads files from Puppet[:pluginsource]' do |
| 38 | + Puppet[:pluginsource] = 'puppet:///myotherplugins' |
| 39 | + |
| 40 | + expect(plugin_downloader.file[:source]).to eq([Puppet[:pluginsource]]) |
| 41 | + end |
| 42 | + |
| 43 | + it 'ignores files from Puppet[:pluginsignore]' do |
| 44 | + Puppet[:pluginsignore] = 'pignore' |
| 45 | + |
| 46 | + expect(plugin_downloader.file[:ignore]).to eq(['pignore']) |
| 47 | + end |
| 48 | + |
| 49 | + it 'splits Puppet[:pluginsignore] on whitespace' do |
| 50 | + Puppet[:pluginsignore] = ".svn CVS .git" |
| 51 | + |
| 52 | + expect(plugin_downloader.file[:ignore]).to eq(%w[.svn CVS .git]) |
| 53 | + end |
| 54 | + |
| 55 | + it "ignores source permissions" do |
| 56 | + ignores_source_permissions(plugin_downloader) |
| 57 | + end |
| 58 | + end |
| 59 | + |
| 60 | + context "when creating a plugin downloader for external facts" do |
| 61 | + it 'is named "pluginfacts"' do |
| 62 | + expect(facts_downloader.name).to eq('pluginfacts') |
| 63 | + end |
| 64 | + |
| 65 | + it 'downloads files into Puppet[:pluginfactdest]' do |
| 66 | + plugindest = File.expand_path("/tmp/pdest") |
| 67 | + Puppet[:pluginfactdest] = plugindest |
| 68 | + |
| 69 | + expect(facts_downloader.file[:path]).to eq(plugindest) |
| 70 | + end |
| 71 | + |
| 72 | + it 'downloads files from Puppet[:pluginfactsource]' do |
| 73 | + Puppet[:pluginfactsource] = 'puppet:///myotherfacts' |
| 74 | + |
| 75 | + expect(facts_downloader.file[:source]).to eq([Puppet[:pluginfactsource]]) |
| 76 | + end |
| 77 | + |
| 78 | + it 'ignores files from Puppet[:pluginsignore]' do |
| 79 | + Puppet[:pluginsignore] = 'pignore' |
| 80 | + |
| 81 | + expect(facts_downloader.file[:ignore]).to eq(['pignore']) |
| 82 | + end |
| 83 | + |
| 84 | + context "on POSIX", :if => Puppet.features.posix? do |
| 85 | + it "uses source permissions" do |
| 86 | + uses_source_permissions(facts_downloader) |
| 87 | + end |
| 88 | + end |
| 89 | + |
| 90 | + context "on Windows", :if => Puppet.features.microsoft_windows? do |
| 91 | + it "ignores source permissions during external fact pluginsync" do |
| 92 | + ignores_source_permissions(facts_downloader) |
| 93 | + end |
| 94 | + end |
| 95 | + end |
| 96 | +end |
0 commit comments