Skip to content

Add be_listening.with("protocol") matcher for Port resource.#200

Merged
mizzy merged 10 commits intomizzy:masterfrom
kitak:with_protocol
Jul 5, 2013
Merged

Add be_listening.with("protocol") matcher for Port resource.#200
mizzy merged 10 commits intomizzy:masterfrom
kitak:with_protocol

Conversation

@kitak
Copy link
Contributor

@kitak kitak commented Jul 4, 2013

Portリソースで使えるbe_listening.with("protocol")マッチャを追加しました。
指定されたポートが与えられたプロトコルでlistenされているかどうか確認できます。
以下が記述例になります。

describe port(80) do
  it { should be_listening.with("tcp") }
end

commandsとmatcherのテストを記述して通ることを確認しています(Solarisのcommandは実際にこれでよいかどうか確かめていないです)。

@ftnk
Copy link
Contributor

ftnk commented Jul 4, 2013

Solaris のコマンドを用意してもらえたのはうれしいのですが、
残念ながら、用意していただいたコマンドでは動作しません。

以下のようにすれば動くと思います。

    regexp = ".*\.#{port} "
    "netstat -an -P #{protocol} 2> /dev/null | egrep 'LISTEN|Idle' | grep -- #{escape(regexp)}"

Solaris 用のコマンドが必要だけどコマンドの確認ができない場合は、
raise NotImplementedError.new してもらえると、
Solaris 用のコマンドが必要だとわかるので助かります。

@kitak
Copy link
Contributor Author

kitak commented Jul 4, 2013

@ftnk
ありがとうございます。コマンドを修正します。
今後はraise NotImplementedError.newしますm(_ _)m

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spec/<os_name>/port_spec.rb の方でコマンドのチェックもやってるので、こっちは追加しなくていいよ。
この commands_spec.rb 自体完全になくす予定です。

@kitak
Copy link
Contributor Author

kitak commented Jul 4, 2013

@mizzy
ありがとうございます! 修正しました

@mizzy
Copy link
Owner

mizzy commented Jul 5, 2013

あと、be_listening.with(:tcp) じゃなく be_listening.with('tcp') にして欲しい。他のマッチャとの一貫性という意味で。

シンボルの方がオブジェクトよりもオーバーヘッド少ないだろうけど、現段階で気にすることではないし、このコードだと、文字列でもシンボルでもどちらでもいけると思うけど、あるマッチャが文字列で、別のマッチャがシンボルだと、使う人が混乱するだろうし、シンボルってRubyに慣れていない人にはわかりにくい概念なので、serverspec を利用する層の人には、わかりにくいだろうし、といった理由で、文字列で統一したいです。

それから、spec に udp のテストもあるといいな。

@kitak
Copy link
Contributor Author

kitak commented Jul 5, 2013

了解です。
テストの方を文字列で渡すように修正します。

@mizzy
Copy link
Owner

mizzy commented Jul 5, 2013

Good!

mizzy added a commit that referenced this pull request Jul 5, 2013
Add "be_listening.with(:protocol)" matcher for Port resource.
@mizzy mizzy merged commit 2cd6ad3 into mizzy:master Jul 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

Development

Successfully merging this pull request may close these issues.

3 participants