2 describe 'apt::source', :type => :define do
13 :required_packages => false,
15 :key_server => 'keyserver.ubuntu.com',
23 :location => 'somewhere',
24 :release => 'precise',
26 :include_src => false,
27 :required_packages => 'apache',
29 :key_server => 'keyserver.debian.com',
31 :key_content => 'ABCD1234'
34 describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
36 param_set == {} ? default_params : params
44 "/etc/apt/sources.list.d/#{title}.list"
48 content = "# #{title}"
49 content << "\ndeb #{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n"
50 if param_hash[:include_src]
51 content << "deb-src #{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n"
56 it { should contain_class("apt::params") }
58 it { should contain_file("#{title}.list")\
64 .with_content(content)
69 should create_resource("apt::pin", param_hash[:release]).with_param("priority", param_hash[:pin]).with_param("before", "File[#{title}.list]")
71 should_not create_resource("apt::pin", param_hash[:release]).with_param("priority", param_hash[:pin]).with_param("before", "File[#{title}.list]")
76 should contain_exec("#{title} apt update")\
77 .with_command("/usr/bin/apt-get update")\
78 .with_subscribe("File[#{title}.list]")\
79 .with_refreshonly(true)
83 if param_hash[:required_packages]
84 should contain_exec("/usr/bin/apt-get -y install #{param_hash[:required_packages]}")\
85 .with_subscribe("File[#{title}.list]")\
86 .with_refreshonly(true)
88 should_not contain_exec("/usr/bin/apt-get -y install #{param_hash[:required_packages]}")\
89 .with_subscribe("File[#{title}.list]")\
90 .with_refreshonly(true)
96 if param_hash[:key_content]
97 should contain_exec("Add key: #{param_hash[:key]} from content")\
98 .with_command("/bin/echo '#{param_hash[:key_content]}' | /usr/bin/apt-key add -")\
99 .with_unless("/usr/bin/apt-key list | /bin/grep '#{param_hash[:key]}'")\
100 .with_before("File[#{title}.list]")
101 should_not contain_exec("/usr/bin/apt-key adv --keyserver #{param_hash[:key_server]} --recv-keys #{param_hash[:key]}")\
102 .with_unless("/usr/bin/apt-key list | /bin/grep #{param_hash[:key]}")\
103 .with_before("File[#{title}.list]")
106 should contain_exec("/usr/bin/apt-key adv --keyserver #{param_hash[:key_server]} --recv-keys #{param_hash[:key]}")\
107 .with_unless("/usr/bin/apt-key list | /bin/grep #{param_hash[:key]}")\
108 .with_before("File[#{title}.list]")
109 should_not contain_exec("Add key: #{param_hash[:key]} from content")\
110 .with_command("/bin/echo '#{param_hash[:key_content]}' | /usr/bin/apt-key add -")\
111 .with_unless("/usr/bin/apt-key list | /bin/grep '#{param_hash[:key]}'")\
112 .with_before("File[#{title}.list]")
115 should_not contain_exec("Add key: #{param_hash[:key]} from content")\
116 .with_command("/bin/echo '#{param_hash[:key_content]}' | /usr/bin/apt-key add -")\
117 .with_unless("/usr/bin/apt-key list | /bin/grep '#{param_hash[:key]}'")\
118 .with_before("File[#{title}.list]")
119 should_not contain_exec("/usr/bin/apt-key adv --keyserver #{param_hash[:key_server]} --recv-keys #{param_hash[:key]}")\
120 .with_unless("/usr/bin/apt-key list | /bin/grep #{param_hash[:key]}")\
121 .with_before("File[#{title}.list]")