blob: 9622b0649b4dd5fce606a720a2f576864de70d8a (
plain)
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
82
83
84
85
86
87
88
89
90
|
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/agent'
require 'puppet/agent/fact_handler'
class FactHandlerTester
include Puppet::Agent::FactHandler
end
describe Puppet::Agent::FactHandler do
before do
@facthandler = FactHandlerTester.new
end
it "should have a method for downloading fact plugins" do
@facthandler.should respond_to(:download_fact_plugins)
end
it "should have a boolean method for determining whether fact plugins should be downloaded" do
@facthandler.should respond_to(:download_fact_plugins?)
end
it "should download fact plugins when :factsync is true" do
Puppet.settings.expects(:value).with(:factsync).returns true
@facthandler.should be_download_fact_plugins
end
it "should not download fact plugins when :factsync is false" do
Puppet.settings.expects(:value).with(:factsync).returns false
@facthandler.should_not be_download_fact_plugins
end
it "should not download fact plugins when downloading is disabled" do
Puppet::Agent::Downloader.expects(:new).never
@facthandler.expects(:download_fact_plugins?).returns false
@facthandler.download_fact_plugins
end
it "should use an Agent Downloader, with the name, source, destination, and ignore set correctly, to download fact plugins when downloading is enabled" do
downloader = mock 'downloader'
Puppet.settings.expects(:value).with(:factsource).returns "fsource"
Puppet.settings.expects(:value).with(:factdest).returns "fdest"
Puppet.settings.expects(:value).with(:factsignore).returns "fignore"
Puppet::Agent::Downloader.expects(:new).with("fact", "fsource", "fdest", "fignore").returns downloader
downloader.expects(:evaluate)
@facthandler.expects(:download_fact_plugins?).returns true
@facthandler.download_fact_plugins
end
it "should have a method for uploading facts" do
@facthandler.should respond_to(:upload_facts)
end
it "should reload Facter and find local facts when asked to upload facts" do
@facthandler.expects(:reload_facter)
Puppet.settings.expects(:value).with(:certname).returns "myhost"
Puppet::Node::Facts.expects(:find).with("myhost")
@facthandler.upload_facts
end
describe "when reloading Facter" do
before do
Facter.stubs(:clear)
Facter.stubs(:load)
Facter.stubs(:loadfacts)
end
it "should clear Facter" do
Facter.expects(:clear)
@facthandler.reload_facter
end
it "should load all Facter facts" do
Facter.expects(:loadfacts)
@facthandler.reload_facter
end
it "should use the Facter terminus load all Puppet Fact plugins" do
Puppet::Node::Facts::Facter.expects(:load_fact_plugins)
@facthandler.reload_facter
end
end
end
|