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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
#!/usr/bin/env ruby
$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/
# Test the yumrepo type
require 'puppettest'
require 'puppet'
require 'fileutils'
class TestYumRepo < Test::Unit::TestCase
include PuppetTest
def setup
super
@yumdir = tempfile()
Dir.mkdir(@yumdir)
@yumconf = File.join(@yumdir, "yum.conf")
File.open(@yumconf, "w") do |f|
f.print "[main]\nreposdir=#{@yumdir} /no/such/dir\n"
end
Puppet.type(:yumrepo).yumconf = @yumconf
end
# Modify one existing section
def test_modify
copy_datafiles
devel = make_repo("development", { :descr => "New description" })
devel.retrieve
assert_equal("development", devel[:name])
assert_equal('Fedora Core $releasever - Development Tree',
devel.state(:descr).is)
assert_equal('New description',
devel.state(:descr).should)
assert_apply(devel)
inifile = Puppet.type(:yumrepo).read()
assert_equal('New description', inifile['development']['name'])
assert_equal('Fedora Core $releasever - $basearch - Base',
inifile['base']['name'])
assert_equal(['base', 'development', 'main'],
all_sections(inifile))
end
# Create a new section
def test_create
values = {
:descr => "Fedora Core $releasever - $basearch - Base",
:baseurl => "http://example.com/yum/$releasever/$basearch/os/",
:enabled => "1",
:gpgcheck => "1",
:includepkgs => "absent",
:gpgkey => "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora"
}
repo = make_repo("base", values)
assert_apply(repo)
inifile = Puppet.type(:yumrepo).read()
sections = all_sections(inifile)
assert_equal(['base', 'main'], sections)
text = inifile["base"].format
assert_equal(CREATE_EXP, text)
end
# Delete mirrorlist by setting it to :absent and enable baseurl
def test_absent
copy_datafiles
baseurl = 'http://example.com/'
devel = make_repo("development",
{ :mirrorlist => 'absent',
:baseurl => baseurl })
devel.retrieve
assert_apply(devel)
inifile = Puppet.type(:yumrepo).read()
sec = inifile["development"]
assert_nil(sec["mirrorlist"])
assert_equal(baseurl, sec["baseurl"])
end
def make_repo(name, hash={})
hash[:name] = name
Puppet.type(:yumrepo).create(hash)
end
def all_sections(inifile)
sections = []
inifile.each_section { |section| sections << section.name }
return sections.sort
end
def copy_datafiles
fakedata("data/types/yumrepos").select { |file|
file =~ /\.repo$/
}.each { |src|
dst = File::join(@yumdir, File::basename(src))
FileUtils::copy(src, dst)
}
end
CREATE_EXP = <<'EOF'
[base]
name=Fedora Core $releasever - $basearch - Base
baseurl=http://example.com/yum/$releasever/$basearch/os/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora
EOF
end
|