Add `be_listening.with("protocol")` matcher for Port resource. #200
Conversation
Solaris のコマンドを用意してもらえたのはうれしいのですが、 以下のようにすれば動くと思います。
Solaris 用のコマンドが必要だけどコマンドの確認ができない場合は、 |
@ftnk |
This comment has been minimized.
This comment has been minimized.
これは定義しなくていいよ。method_missing で同じ事をやってくれるから。 |
This comment has been minimized.
This comment has been minimized.
def check_listening_with_protocol(port, protocol)
ret = run_command(commands.check_listening_with_protocol(port, protocol))
ret[:exit_status] == 0
end ってすればふたつを共通にできるし、さらにこういうメソッド定義であれば、method_missing が同じ事をやってくれるから、書く必要もなくなるよね。 |
This comment has been minimized.
This comment has been minimized.
tcp, udp 以外に増えることもなさそうだし、 if with
backend.check_listening_with_protcol(@name, with) とかでいいんじゃないかな。tcp か udp じゃなければ例外出す、ってのも入れとくと良さそう。 ただ、with だとちょっとわかりにくいので、 def listening?(protocol)
if protocol とすると更にわかりやすくなって良さそう。 |
@@ -12,6 +12,9 @@ | |||
it_behaves_like 'support command check_user', 'root' | |||
it_behaves_like 'support command check_user', 'wheel' | |||
|
|||
it_behaves_like 'support command check_listening', 80 | |||
it_behaves_like 'support command check_listening_with_protocol', 80, :tcp |
mizzy
Jul 4, 2013
Owner
spec/<os_name>/port_spec.rb の方でコマンドのチェックもやってるので、こっちは追加しなくていいよ。
この commands_spec.rb 自体完全になくす予定です。
spec/<os_name>/port_spec.rb の方でコマンドのチェックもやってるので、こっちは追加しなくていいよ。
この commands_spec.rb 自体完全になくす予定です。
subject { commands.check_listening_with_protocol(port, protocol) } | ||
it { should eq "netstat -tunl | grep -- \\^tcp\\ .\\*:80\\ " } | ||
end | ||
|
mizzy
Jul 4, 2013
Owner
この追加も不要です。
この追加も不要です。
@@ -14,6 +14,9 @@ | |||
|
|||
it_behaves_like 'support command check_file_md5checksum', '/etc/passewd', '96c8c50f81a29965f7af6de371ab4250' | |||
|
|||
it_behaves_like 'support command check_listening', 80 | |||
it_behaves_like 'support command check_listening_with_protocol', 80, :tcp | |||
|
mizzy
Jul 4, 2013
Owner
これも不要。
これも不要。
@@ -14,6 +14,9 @@ | |||
|
|||
it_behaves_like 'support command check_file_md5checksum', '/etc/passewd', '96c8c50f81a29965f7af6de371ab4250' | |||
|
|||
it_behaves_like 'support command check_listening', 80 | |||
it_behaves_like 'support command check_listening_with_protocol', 80, :tcp | |||
|
mizzy
Jul 4, 2013
Owner
これも不要。
これも不要。
@@ -14,6 +14,9 @@ | |||
|
|||
it_behaves_like 'support command check_file_md5checksum', '/etc/passewd', '96c8c50f81a29965f7af6de371ab4250' | |||
|
|||
it_behaves_like 'support command check_listening', 80 | |||
it_behaves_like 'support command check_listening_with_protocol', 80, :tcp | |||
|
mizzy
Jul 4, 2013
Owner
これも不要。
これも不要。
@mizzy |
あと、 シンボルの方がオブジェクトよりもオーバーヘッド少ないだろうけど、現段階で気にすることではないし、このコードだと、文字列でもシンボルでもどちらでもいけると思うけど、あるマッチャが文字列で、別のマッチャがシンボルだと、使う人が混乱するだろうし、シンボルってRubyに慣れていない人にはわかりにくい概念なので、serverspec を利用する層の人には、わかりにくいだろうし、といった理由で、文字列で統一したいです。 それから、spec に udp のテストもあるといいな。 |
了解です。 |
Good! |
Add "be_listening.with(:protocol)" matcher for Port resource.
Portリソースで使える
be_listening.with("protocol")
マッチャを追加しました。指定されたポートが与えられたプロトコルでlistenされているかどうか確認できます。
以下が記述例になります。
commandsとmatcherのテストを記述して通ることを確認しています(Solarisのcommandは実際にこれでよいかどうか確かめていないです)。