Top Level Namespace
Defined Under Namespace
Modules: Puppet, PuppetlabsSpec, PuppetlabsSpecHelper, RSpec
Instance Method Summary collapse
- #clone_repo(scm, remote, target, ref = nil, branch = nil, flags = nil) ⇒ Object
-
#current_thread_count(items) ⇒ Object
returns the current thread count that is currently active a status of false or nil means the thread completed so when anything else we count that as a active thread.
- #fixtures(category) ⇒ Object
-
#logger ⇒ Object
creates a logger so we can log events with certain levels.
-
#max_thread_limit ⇒ Object
returns the max_thread_count because we may want to limit ssh or https connections.
- #param_value(subject, type, title, param) ⇒ Object
-
#repositories ⇒ Object
cache the repositories and retruns and hash object.
- #revision(scm, target, ref) ⇒ Object
-
#source_dir ⇒ Object
This is a helper for the self-symlink entry of fixtures.yml.
- #verify_contents(subject, title, expected_lines) ⇒ Object
Instance Method Details
#clone_repo(scm, remote, target, ref = nil, branch = nil, flags = nil) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/puppetlabs_spec_helper/rake_tasks.rb', line 86 def clone_repo(scm, remote, target, ref=nil, branch=nil, flags = nil) args = [] case scm when 'hg' args.push('clone') args.push('-u', ref) if ref args.push(flags) if flags args.push(remote, target) when 'git' args.push('clone') args.push('--depth 1') unless ref args.push('-b', branch) if branch args.push(flags) if flags args.push(remote, target) else fail "Unfortunately #{scm} is not supported yet" end result = system("#{scm} #{args.flatten.join ' '}") unless File::exists?(target) fail "Failed to clone #{scm} repository #{remote} into #{target}" end result end |
#current_thread_count(items) ⇒ Object
returns the current thread count that is currently active a status of false or nil means the thread completed so when anything else we count that as a active thread
141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/puppetlabs_spec_helper/rake_tasks.rb', line 141 def current_thread_count(items) active_threads = items.find_all do |item, opts| if opts[:thread] opts[:thread].status else false end end logger.debug "Current thread count #{active_threads.count}" active_threads.count end |
#fixtures(category) ⇒ Object
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 |
# File 'lib/puppetlabs_spec_helper/rake_tasks.rb', line 51 def fixtures(category) if File.exists?('.fixtures.yml') fixtures_yaml = '.fixtures.yml' elsif File.exists?('.fixtures.yaml') fixtures_yaml = '.fixtures.yaml' else fixtures_yaml = '' end begin fixtures = YAML.load_file(fixtures_yaml)["fixtures"] rescue Errno::ENOENT return {} rescue Psych::SyntaxError => e abort("Found malformed YAML in #{fixtures_yaml} on line #{e.line} column #{e.column}: #{e.problem}") end result = {} if fixtures.include? category and fixtures[category] != nil fixtures[category].each do |fixture, opts| if opts.instance_of?(String) source = opts target = "spec/fixtures/modules/#{fixture}" real_source = eval('"'+source+'"') result[real_source] = target elsif opts.instance_of?(Hash) target = "spec/fixtures/modules/#{fixture}" real_source = eval('"'+opts["repo"]+'"') result[real_source] = { "target" => target, "ref" => opts["ref"], "branch" => opts["branch"], "scm" => opts["scm"], "flags" => opts["flags"]} end end end return result end |
#logger ⇒ Object
creates a logger so we can log events with certain levels
124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/puppetlabs_spec_helper/rake_tasks.rb', line 124 def logger unless @logger require 'logger' if ENV['ENABLE_LOGGER'] level = Logger::DEBUG else level = Logger::INFO end @logger = Logger.new(STDOUT) @logger.level = level end @logger end |
#max_thread_limit ⇒ Object
returns the max_thread_count because we may want to limit ssh or https connections
155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/puppetlabs_spec_helper/rake_tasks.rb', line 155 def max_thread_limit unless @max_thread_limit # the default thread count is 10 but can be # raised by using environment variable MAX_FIXTURE_THREAD_COUNT if ENV['MAX_FIXTURE_THREAD_COUNT'].to_i > 0 @max_thread_limit = ENV['MAX_FIXTURE_THREAD_COUNT'].to_i else @max_thread_limit = 10 # the default end end @max_thread_limit end |
#param_value(subject, type, title, param) ⇒ Object
5 6 7 |
# File 'lib/puppetlabs_spec_helper/module_spec_helper.rb', line 5 def param_value(subject, type, title, param) subject.resource(type, title).send(:parameters)[param.to_sym] end |
#repositories ⇒ Object
cache the repositories and retruns and hash object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/puppetlabs_spec_helper/rake_tasks.rb', line 38 def repositories unless @repositories @repositories = fixtures('repositories') @repositories.each do |remote, opts| if opts.instance_of?(String) @repositories[remote] = {"target" => opts} # inject a hash end end end @repositories end |
#revision(scm, target, ref) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/puppetlabs_spec_helper/rake_tasks.rb', line 110 def revision(scm, target, ref) args = [] case scm when 'hg' args.push('update', 'clean', '-r', ref) when 'git' args.push('reset', '--hard', ref) else fail "Unfortunately #{scm} is not supported yet" end system("cd #{target} && #{scm} #{args.flatten.join ' '}") end |
#source_dir ⇒ Object
This is a helper for the self-symlink entry of fixtures.yml
33 34 35 |
# File 'lib/puppetlabs_spec_helper/rake_tasks.rb', line 33 def source_dir Dir.pwd end |
#verify_contents(subject, title, expected_lines) ⇒ Object
9 10 11 12 |
# File 'lib/puppetlabs_spec_helper/module_spec_helper.rb', line 9 def verify_contents(subject, title, expected_lines) content = subject.resource('file', title).send(:parameters)[:content] (content.split("\n") & expected_lines).should == expected_lines end |