serverspec 2.0.0.beta7 → 2.0.0.beta8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86276d22b163697d65c60b346e9b6e6b0ff9e5cb
4
- data.tar.gz: 58808a070ee544fe9a86a7a3f50c52a35149ebcc
3
+ metadata.gz: 22d2a873870ecdddc00919f06be8c80c0a3d4f41
4
+ data.tar.gz: f2c1d92a9211eeda7a2f080dca4fc8a5eabf03c8
5
5
  SHA512:
6
- metadata.gz: cf3996aefa9f11b279130f27ea47b27673d47e0ae25d9929b9e3103294c59c645a91911d1e3e099250db39925c39402109cb39ca5fb9593a623acd97e556a8a1
7
- data.tar.gz: 1f91b85d4ea7f6bc52d54afbc13244b689bb97ac93d7ada9544b980181b64bacb0cabfa2879e8773c0f2b1cd216dffbd5cbc8ad89b8c972c7ceae40363697f67
6
+ metadata.gz: f4f893ae50ce59810c2f2ebde4a94f4a0d95e5d25601702b64b6d39b0511e5d85d751968a005d1f0e3c5608f1e60f0eccdee4fb744011b9ff87df36de451166c
7
+ data.tar.gz: d0698d14a569d5b855b5237ae41a8c8f307b066b13b907ba1f0f74c2af25d307e49ed6966c900ffb315ccc25a4b2e74094317cdd724ed6af928d548d5fc1da6c
@@ -1,9 +1,13 @@
1
1
  RSpec::Matchers.define :be_listening do
2
2
  match do |port|
3
- port.listening?(@with)
3
+ port.listening? @with, @local_address
4
4
  end
5
5
 
6
6
  chain :with do |with|
7
- @with = with
7
+ @with = with
8
+ end
9
+
10
+ chain :on do |local_address|
11
+ @local_address = local_address
8
12
  end
9
13
  end
@@ -1,18 +1,42 @@
1
+ require 'resolv'
2
+
1
3
  module Serverspec
2
4
  module Type
3
5
  class Port < Base
4
- def listening?(protocol)
5
- if protocol
6
- protocol = protocol.to_s.downcase
7
- unless ["udp", "tcp", "tcp6", "udp6"].include?(protocol)
8
- raise ArgumentError.new("`be_listening` matcher doesn't support #{protocol}")
9
- end
6
+ def protocols
7
+ %w(udp tcp tcp6 udp6)
8
+ end
9
+
10
+ def options
11
+ @options ||= {}
12
+ end
13
+
14
+ def protocol_matcher(protocol)
15
+ protocol = protocol.to_s.downcase
16
+ if protocols.include?(protocol)
17
+ options[:protocol] = protocol
18
+ else
19
+ raise ArgumentError.new("`be_listening` matcher doesn't support #{protocol}")
20
+ end
21
+ end
10
22
 
11
- @runner.check_listening_with_protocol(@name, protocol)
23
+ def local_address_matcher(local_address)
24
+ if valid_ip_address?(local_address)
25
+ options[:local_address] = local_address
12
26
  else
13
- @runner.check_listening(@name)
27
+ raise ArgumentError.new("`be_listening` matcher requires valid IPv4 or IPv6 address")
14
28
  end
15
29
  end
30
+
31
+ def listening?(protocol, local_address)
32
+ protocol_matcher(protocol) if protocol
33
+ local_address_matcher(local_address) if local_address
34
+ @runner.check_listening(@name, options)
35
+ end
36
+
37
+ def valid_ip_address?(ip_address)
38
+ !!(ip_address =~ Resolv::IPv4::Regex) || !!(ip_address =~ Resolv::IPv6::Regex)
39
+ end
16
40
  end
17
41
  end
18
42
  end
@@ -1,3 +1,3 @@
1
1
  module Serverspec
2
- VERSION = "2.0.0.beta7"
2
+ VERSION = "2.0.0.beta8"
3
3
  end
@@ -2,26 +2,32 @@ require 'spec_helper'
2
2
 
3
3
  include Specinfra::Helper::RedHat
4
4
 
5
- describe port(80) do
6
- it { should be_listening }
7
- end
5
+ describe Serverspec::Type::Port do
6
+ describe port(80) do
7
+ it { should be_listening }
8
8
 
9
- describe port('invalid') do
10
- it { should_not be_listening }
11
- end
9
+ it('protocol: tcp') { should be_listening.with('tcp') }
12
10
 
13
- describe port(80) do
14
- it { should be_listening.with("tcp") }
15
- end
11
+ it 'invalid protocol raises error' do
12
+ expect {
13
+ should be_listening.with('not implemented')
14
+ }.to raise_error(ArgumentError, %r/\A`be_listening` matcher doesn\'t support/)
15
+ end
16
16
 
17
- describe port(123) do
18
- it { should be_listening.with("udp") }
19
- end
17
+ it('on: 127.0.0.1') do
18
+ should be_listening.on('127.0.0.1')
19
+ end
20
+
21
+ it 'invalid local address raises error' do
22
+ expect{ should be_listening.on('') }.to raise_error(ArgumentError)
23
+ end
24
+ end
25
+
26
+ describe port('invalid') do
27
+ it { should_not be_listening }
28
+ end
20
29
 
21
- describe port(80) do
22
- it {
23
- expect {
24
- should be_listening.with('not implemented')
25
- }.to raise_error(ArgumentError, %r/\A`be_listening` matcher doesn\'t support/)
26
- }
30
+ describe port(123) do
31
+ it { should be_listening.with("udp") }
32
+ end
27
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serverspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta7
4
+ version: 2.0.0.beta8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gosuke Miyashita