forked from voxpupuli/puppet-jenkins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor the $jenkins_plugins fact more, the fact will now be alphabe…
…tically sorted and more consistent This also opens up the ability to use Puppet::Jenkins::Plugins#available inside the plugins package provider (to be written)
- Loading branch information
R. Tyler Croy
committed
Mar 12, 2014
1 parent
ceaa71b
commit aa14e97
Showing
5 changed files
with
111 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require 'facter' | ||
require 'puppet/jenkins' | ||
require 'puppet/jenkins/plugins' | ||
|
||
module Puppet | ||
module Jenkins | ||
module Facts | ||
# Method to call the Facter DSL and dynamically add facts at runtime. | ||
# | ||
# This method is necessary to add reasonable RSpec coverage for the custom | ||
# fact | ||
# | ||
# @return [NilClass] | ||
def self.install | ||
Facter.add(:jenkins_plugins) do | ||
confine :kernel => "Linux" | ||
setcode do | ||
self.plugins_str | ||
end | ||
end | ||
return nil | ||
end | ||
|
||
# Return a list of plugins and their versions, e.g.: | ||
# pam-auth 1.1, pmd 3.36, rake 1.7.8 | ||
# | ||
# @return [String] Comma-separated version of "<plugin> <version>", empty | ||
# string if there are no plugins | ||
def self.plugins_str | ||
plugins = Puppet::Jenkins::Plugins.available | ||
buffer = [] | ||
plugins.keys.sort.each do |plugin| | ||
manifest = plugins[plugin] | ||
buffer << "#{plugin} #{manifest[:plugin_version]}" | ||
end | ||
return buffer.join(', ') | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,75 @@ | ||
require 'spec_helper' | ||
require 'lib/facter/jenkins' | ||
|
||
describe 'jenkins_plugins fact', :type => :fact do | ||
let(:fact) { Facter.fact(:jenkins_plugins) } | ||
subject(:plugins) { fact.value } | ||
describe Puppet::Jenkins::Facts do | ||
describe '.plugins_str' do | ||
subject(:plugins_str) { described_class.plugins_str } | ||
let(:plugins) { {} } | ||
|
||
before :each do | ||
Facter.fact(:kernel).stubs(:value).returns(kernel) | ||
Jenkins::Facts.add_facts | ||
end | ||
|
||
context 'on Linux' do | ||
let(:kernel) { 'Linux' } | ||
before :each do | ||
Puppet::Jenkins::Plugins.should_receive(:available).and_return(plugins) | ||
end | ||
|
||
context 'with no plugins' do | ||
it { should be_nil } | ||
it { should be_instance_of String } | ||
it { should be_empty } | ||
end | ||
|
||
context 'with one plugin' do | ||
let(:plugins) do | ||
{ | ||
'greenballs' => {:plugin_version => '1.1', :description => 'rspec'} | ||
} | ||
end | ||
|
||
it { should be_instance_of String } | ||
it { should eql 'greenballs 1.1' } | ||
end | ||
|
||
context 'with plugins' do | ||
let(:plugins_str) { 'ant 1.2, git 2.0.1' } | ||
before :each do | ||
Jenkins::Facts::Plugins.should_receive(:plugins).and_return(plugins_str) | ||
context 'with multiple plugins' do | ||
let(:plugins) do | ||
{ | ||
'greenballs' => {:plugin_version => '1.1', :description => 'rspec'}, | ||
'git' => {:plugin_version => '1.7', :description => 'rspec'} | ||
} | ||
end | ||
|
||
it { should eql(plugins_str) } | ||
it { should be_instance_of String } | ||
it { should eql 'git 1.7, greenballs 1.1' } | ||
end | ||
end | ||
|
||
context 'on FreeBSD' do | ||
let(:kernel) { 'FreeBSD' } | ||
describe 'jenkins_plugins fact', :type => :fact do | ||
let(:fact) { Facter.fact(:jenkins_plugins) } | ||
subject(:plugins) { fact.value } | ||
|
||
before :each do | ||
Facter.fact(:kernel).stubs(:value).returns(kernel) | ||
Puppet::Jenkins::Facts.install | ||
end | ||
|
||
context 'on Linux' do | ||
let(:kernel) { 'Linux' } | ||
|
||
context 'with no plugins' do | ||
it { should be_nil } | ||
end | ||
|
||
context 'with plugins' do | ||
let(:plugins_str) { 'ant 1.2, git 2.0.1' } | ||
before :each do | ||
Jenkins::Facts::Plugins.should_receive(:plugins).and_return(plugins_str) | ||
end | ||
|
||
it { should eql(plugins_str) } | ||
end | ||
end | ||
|
||
context 'on FreeBSD' do | ||
let(:kernel) { 'FreeBSD' } | ||
|
||
it { should be_nil } | ||
it { should be_nil } | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters