Module: BeakerSpecHelper
- Defined in:
- lib/beaker_spec_helper.rb,
lib/beaker_spec_helper/version.rb
Defined Under Namespace
Modules: Version
Instance Method Summary collapse
- #clone_repo(host, scm, remote, target, ref = nil, branch = nil) ⇒ Object
-
#fixtures(host, category) ⇒ Object
Copied/pasted/adapted from puppetlabs_spec_helper’s lib/puppetlabs_spec_helper/rake_tasks.rb.
- #revision(host, scm, target, ref) ⇒ Object
- #spec_prep(host) ⇒ Object
Instance Method Details
#clone_repo(host, scm, remote, target, ref = nil, branch = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/beaker_spec_helper.rb', line 35 def clone_repo(host, scm, remote, target, ref=nil, branch=nil) args = [] case scm when 'hg' args.push('clone') args.push('-u', ref) if ref args.push(remote, target) when 'git' args.push('clone') args.push('--depth 1') unless ref args.push('-b', branch) if branch args.push(remote, target) else fail "Unfortunately #{scm} is not supported yet" end on host, "#{scm} #{args.flatten.join ' '} || true" end |
#fixtures(host, category) ⇒ Object
Copied/pasted/adapted from puppetlabs_spec_helper’s lib/puppetlabs_spec_helper/rake_tasks.rb
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 |
# File 'lib/beaker_spec_helper.rb', line 6 def fixtures(host, category) begin fixtures = YAML.load_file(".fixtures.yml")["fixtures"] rescue Errno::ENOENT return {} end if not fixtures abort("malformed fixtures.yml") end result = {} if fixtures.include? category and fixtures[category] != nil fixtures[category].each do |fixture, opts| if opts.instance_of?(String) source = opts target = "#{host['distmoduledir']}/#{fixture}" real_source = eval('"'+source+'"') result[real_source] = target elsif opts.instance_of?(Hash) target = "#{host['distmoduledir']}/#{fixture}" real_source = eval('"'+opts["repo"]+'"') result[real_source] = { "target" => target, "ref" => opts["ref"], "branch" => opts["branch"], "scm" => opts["scm"] } end end end return result end |
#revision(host, scm, target, ref) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/beaker_spec_helper.rb', line 53 def revision(host, 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 on host, "cd #{target} && #{scm} #{args.flatten.join ' '}" end |
#spec_prep(host) ⇒ Object
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 91 92 93 94 95 |
# File 'lib/beaker_spec_helper.rb', line 66 def spec_prep(host) fixtures(host, "repositories").each do |remote, opts| scm = 'git' if opts.instance_of?(String) target = opts elsif opts.instance_of?(Hash) target = opts["target"] ref = opts["ref"] scm = opts["scm"] if opts["scm"] branch = opts["branch"] if opts["branch"] end unless File::exists?(target) || clone_repo(host, scm, remote, target, ref, branch) fail "Failed to clone #{scm} repository #{remote} into #{target}" end revision(host, scm, target, ref) if ref end fixtures(host, "forge_modules").each do |remote, opts| if opts.instance_of?(String) target = opts ref = "" elsif opts.instance_of?(Hash) target = opts["target"] ref = "--version #{opts['ref']}" end next if File::exists?(target) on host, puppet('module', 'install', ref, '--ignore-dependencies', '--force', remote), { :acceptable_exit_codes => [0,1] } end end |