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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

two new matchers "be_mounted" and "be_resolvable" #76

Merged
merged 1 commit into from May 3, 2013

Conversation

Projects
None yet
2 participants
@wubel
Contributor

wubel commented May 1, 2013

hello :)

ive been playing around with serverspec today. i really like the idea of test servers with rspec. this is the first github project i contribute to ever and my first ruby project too. ive created two new matchers:

  • be_mounted
  • be_resolvable

usage example:

describe 'resolv' do
  context "hostA" do
    it { should be_resolvable.by("dns") }
  end
  context "hostB" do
    it { should be_resolvable.by("hosts") }
  end
  context "hostC" do
    # use dns by default
    it { should be_resolvable }
  end
end

describe "/usr/local" do
  it { should be_mounted }
end

i hope i have done everything right. thx 馃槃

@mizzy

This comment has been minimized.

Show comment
Hide comment
@mizzy

mizzy May 2, 2013

Owner

These matchers are very useful!

Serverspec runs shell commands to test servers.
So you should define shell commands to test in commands/base.rb like this.

def check_mounted(path)
  "mount | grep -w 'on #{path}'"
end

def check_resolvable(name, type)
  if type == 'hosts'
    cmd = "grep -w #{name} /etc/hosts"
  elsif type == 'dns'
    cmd = "nslookup #{name}"
  else
    cmd = "getent hosts #{name}"
  end
  cmd
end

And you don't need to touch backend/exec.rb .

Owner

mizzy commented May 2, 2013

These matchers are very useful!

Serverspec runs shell commands to test servers.
So you should define shell commands to test in commands/base.rb like this.

def check_mounted(path)
  "mount | grep -w 'on #{path}'"
end

def check_resolvable(name, type)
  if type == 'hosts'
    cmd = "grep -w #{name} /etc/hosts"
  elsif type == 'dns'
    cmd = "nslookup #{name}"
  else
    cmd = "getent hosts #{name}"
  end
  cmd
end

And you don't need to touch backend/exec.rb .

@wubel

This comment has been minimized.

Show comment
Hide comment
@wubel

wubel May 2, 2013

Contributor

hello :)

i have updated the pull request and implemented the matchers with shell commands. i hope ive done the rebasing right.

may i ask why you prefer shell commands instead of ruby builtin library ? i think its because of the remote execution of commands with ssh ?

regards

Contributor

wubel commented May 2, 2013

hello :)

i have updated the pull request and implemented the matchers with shell commands. i hope ive done the rebasing right.

may i ask why you prefer shell commands instead of ruby builtin library ? i think its because of the remote execution of commands with ssh ?

regards

@mizzy

This comment has been minimized.

Show comment
Hide comment
@mizzy

mizzy May 2, 2013

Owner

Thanks! LGTM.

And I'd like to you change spec files spec/debian/*, spec/gentoo/*, spec/redhat/* and spec/solaris/* .
(You don't need to test on those platforms.Only just change these files to pass specs for matchers and commands you've added.)

may i ask why you prefer shell commands instead of ruby builtin library ? i think its because of the remote execution of commands with ssh ?

Exactly, you're right.

Owner

mizzy commented May 2, 2013

Thanks! LGTM.

And I'd like to you change spec files spec/debian/*, spec/gentoo/*, spec/redhat/* and spec/solaris/* .
(You don't need to test on those platforms.Only just change these files to pass specs for matchers and commands you've added.)

may i ask why you prefer shell commands instead of ruby builtin library ? i think its because of the remote execution of commands with ssh ?

Exactly, you're right.

@wubel

This comment has been minimized.

Show comment
Hide comment
@wubel

wubel May 2, 2013

Contributor

done

Contributor

wubel commented May 2, 2013

done

@mizzy mizzy merged commit 6a3dff2 into mizzy:master May 3, 2013

1 check passed

default The Travis build passed
Details
@mizzy

This comment has been minimized.

Show comment
Hide comment
@mizzy

mizzy May 3, 2013

Owner

Great! Thanks!

I've merged and made some fixes like 1c829a2.

And I will try to change be_mounted like this.

describe '/' do
  it { should be_mounted.with( :type => 'ext4', :options => { :rw => true, :mode => 620 } ) }
end

After implementing this, I will release as gem.

Thanks!

Owner

mizzy commented May 3, 2013

Great! Thanks!

I've merged and made some fixes like 1c829a2.

And I will try to change be_mounted like this.

describe '/' do
  it { should be_mounted.with( :type => 'ext4', :options => { :rw => true, :mode => 620 } ) }
end

After implementing this, I will release as gem.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment