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

added "be_reachable" matcher for connection checks #86

Closed
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
2 participants
@wubel
Contributor

wubel commented May 4, 2013

hello,

currently im writing tests for our server infrastructure with help from serverspec. we need to check if some servers can connect to a specific ip and port. so ive implementeted a be_reachable matcher. example:

describe "my host" do
  describe "can connect" do
    context "to localhost on port ssh" do
      it { should be_reachable }
    end
    context "10.0.0.1:22" do
      it { should be_reachable.with("tcp") }
    end
    context "with udp to 127.0.0.1:5353" do
      it { should be_reachable }
    end
    context "connect examplehost:22" do
      it { should be_reachable.with(:proto => "tcp", :timeout => 5) }
    end                     
  end
end

you can specifiy the settings in the context string or by parameters. you can also pass names (from /etc/services) instead of port numbers because it uses nc as command line tool.

i hope this time i have implemented all necessary tests for the matcher right.

thx :)

@mizzy

This comment has been minimized.

Show comment
Hide comment
@mizzy

mizzy May 5, 2013

Owner

I don't like the expression like this.

    context "to localhost on port ssh" do
      it { should be_reachable }
    end

It seems natural as English, but so complicated to learn and implement.

Subject should contain only the host name or ip address for simpleness.

And, other matchers don't take these kind of the subject, so it is strange that only be_reachable takes the subject like that.It breaks the integrity.

Owner

mizzy commented May 5, 2013

I don't like the expression like this.

    context "to localhost on port ssh" do
      it { should be_reachable }
    end

It seems natural as English, but so complicated to learn and implement.

Subject should contain only the host name or ip address for simpleness.

And, other matchers don't take these kind of the subject, so it is strange that only be_reachable takes the subject like that.It breaks the integrity.

@mizzy

View changes

Show outdated Hide outdated spec/support/shared_matcher_examples.rb
@mizzy

This comment has been minimized.

Show comment
Hide comment
@mizzy

mizzy May 5, 2013

Owner

"be_reachable" without any arguments should check the host reachability with ICMP.

# ICMP reachability checking
describe 'localhost' do
  it { should be_reachable }
end
Owner

mizzy commented May 5, 2013

"be_reachable" without any arguments should check the host reachability with ICMP.

# ICMP reachability checking
describe 'localhost' do
  it { should be_reachable }
end
@wubel

This comment has been minimized.

Show comment
Hide comment
@wubel

wubel May 5, 2013

Contributor

thx for your review :) to do a normal ping check without any arguments seems like a really good idea. i will change the code that it behaves like you posted and update the pull request.

Contributor

wubel commented May 5, 2013

thx for your review :) to do a normal ping check without any arguments seems like a really good idea. i will change the code that it behaves like you posted and update the pull request.

@wubel

This comment has been minimized.

Show comment
Hide comment
@wubel

wubel May 5, 2013

Contributor

ive updated the code. now you can only use "host:port" and "host" (which makes a icmp check) as description. and i have removed the tcp and udp listeners from the specs.

    # icmp check
    context "127.0.0.1" do
      it { should be_reachable }
    end
    # ping fail
    context "localhost2" do
      it { should_not be_reachable }
    end
Contributor

wubel commented May 5, 2013

ive updated the code. now you can only use "host:port" and "host" (which makes a icmp check) as description. and i have removed the tcp and udp listeners from the specs.

    # icmp check
    context "127.0.0.1" do
      it { should be_reachable }
    end
    # ping fail
    context "localhost2" do
      it { should_not be_reachable }
    end
@mizzy

This comment has been minimized.

Show comment
Hide comment
@mizzy

mizzy May 5, 2013

Owner

Thnaks.I've merged and made some fixes.

Owner

mizzy commented May 5, 2013

Thnaks.I've merged and made some fixes.

@mizzy mizzy closed this May 5, 2013

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