Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YumrepoをResourceTypeに追加する #162

Merged
merged 8 commits into from Jun 23, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/serverspec/commands/base.rb
Expand Up @@ -13,6 +13,14 @@ def check_enabled service
raise NotImplementedError.new
end

def check_yumrepo(repository)
raise NotImplementedError.new
end

def check_yumrepo_enabled(repository)
raise NotImplementedError.new
end

def check_mounted path
regexp = "on #{path}"
"mount | grep -w -- #{escape(regexp)}"
Expand Down
8 changes: 8 additions & 0 deletions lib/serverspec/commands/redhat.rb
Expand Up @@ -10,6 +10,14 @@ def check_enabled service
"chkconfig --list #{escape(service)} | grep 3:on"
end

def check_yumrepo(repository)
"yum repolist -C | grep ^#{escape(repository)}"
end

def check_yumrepo_enabled(repository)
"yum repolist all -C | grep ^#{escape(repository)} | grep enabled"
end

def check_installed package
"rpm -q #{escape(package)}"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/serverspec/helper/type.rb
Expand Up @@ -2,7 +2,7 @@ module Serverspec
module Helper
module Type
types = %w(
base service package port file cron command linux_kernel_parameter iptables host
base yumrepo service package port file cron command linux_kernel_parameter iptables host
routing_table default_gateway selinux user group zfs ipnat ipfilter kernel_module
)

Expand Down
13 changes: 13 additions & 0 deletions lib/serverspec/type/yumrepo.rb
@@ -0,0 +1,13 @@
module Serverspec
module Type
class Yumrepo < Base
def exists?
backend.check_yumrepo(@name)
end

def enabled?
backend.check_yumrepo_enabled(@name)
end
end
end
end
10 changes: 10 additions & 0 deletions spec/redhat/commands_spec.rb
Expand Up @@ -66,6 +66,16 @@
it { should eq 'chkconfig --list httpd | grep 3:on' }
end

describe 'check_yumrepo' do
subject { commands.check_yumrepo('epel') }
it { should eq 'yum repolist -C | grep ^epel' }
end

describe 'check_yumrepo_enabled' do
subject { commands.check_yumrepo_enabled('epel') }
it { should eq 'yum repolist all -C | grep ^epel | grep enabled' }
end

describe 'check_installed' do
subject { commands.check_installed('httpd') }
it { should eq 'rpm -q httpd' }
Expand Down
25 changes: 25 additions & 0 deletions spec/redhat/yumrepo_spec.rb
@@ -0,0 +1,25 @@
require 'spec_helper'

include Serverspec::Helper::RedHat

describe 'Serverspec yumrepo matchers of Red Hat family' do
describe 'exist' do
describe yumrepo('epel') do
it { should exist }
end

describe yumrepo('invalid-repository') do
it { should_not exist }
end
end

describe 'be_enabled' do
describe yumrepo('epel') do
it { should be_enabled }
end

describe yumrepo('invalid-repository') do
it { should_not be_enabled }
end
end
end