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

added "be_reachable" matcher for connection checks #86

Closed
wants to merge 1 commit into from
Closed

added "be_reachable" matcher for connection checks #86

wants to merge 1 commit into from

Conversation

@wubel
Copy link
Contributor

@wubel 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
Copy link
Owner

@mizzy 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.

after :all do
@u.close
@t.close
end
Copy link
Owner

@mizzy mizzy May 5, 2013

You don't need before and after hooks.Because specs for serverspec don't run command actually.

See: https://github.com/mizzy/serverspec/blob/master/spec/spec_helper.rb

@mizzy
Copy link
Owner

@mizzy 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
Copy link
Contributor Author

@wubel 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
Copy link
Contributor Author

@wubel 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
Copy link
Owner

@mizzy 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
Labels
None yet
Projects
None yet
2 participants