mcollective-test 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/Gemfile +8 -0
- data/README.md +2 -0
- data/Rakefile +3 -0
- data/lib/mcollective/test/matchers/application_description.rb +23 -31
- data/lib/mcollective/test/matchers/rpc_result_items.rb +8 -112
- data/lib/mcollective/test/matchers/rpc_status.rb +24 -43
- data/lib/mcollective/test/matchers.rb +0 -1
- data/lib/mcollective/test/util.rb +6 -4
- data/mcollective-test.gemspec +13 -0
- metadata +32 -52
- data/lib/mcollective/test/matchers/rpc_metadata.rb +0 -40
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '09fe1fb38a726df66f6f2eaa11d686d051be473dfbddb505192f315fb14155cd'
|
4
|
+
data.tar.gz: a2716539431f26ab49178a4ec0db25d0593be3a1d88da74242981655b9dce9c8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c28142f4dd7d8efa665fdb5e1e98eca8c72a30bf239083a864c8f96056b3e1f3d54a46f5936733e5928a75d5865383cfc582c9e488a59effe45fa7f3b4f8b69e
|
7
|
+
data.tar.gz: 52a7ddd99061d7598c40a5191d55882a0c20cd9e0acc1a65bb2785e9985d80c3b3969ba76ff864552086eb11f14746855ef1f4214ba657eac5cd970d645d31be
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
@@ -1,39 +1,31 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
def have_a_description(description=nil); ApplicationDescription.new(description); end
|
1
|
+
RSpec::Matchers.define(:have_a_description) do |expected|
|
2
|
+
match do |actual|
|
3
|
+
actual = actual.application_description
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
if expected
|
6
|
+
actual == expected
|
7
|
+
else
|
8
|
+
!actual.nil?
|
9
|
+
end
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
failure_message do |actual|
|
13
|
+
actual = actual.application_description
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
if expected
|
16
|
+
"application should have description #{expected.inspect} but got #{actual.inspect}"
|
17
|
+
else
|
18
|
+
"application should have a description, got #{actual.inspect}"
|
19
|
+
end
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
"application should have a description '#{@match}' but got '#{@actual}'"
|
24
|
-
else
|
25
|
-
"application should have a description, got #{@match}"
|
26
|
-
end
|
27
|
-
end
|
22
|
+
failure_message_when_negated do |actual|
|
23
|
+
actual = actual.application_description
|
28
24
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
"application should not have a description"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
25
|
+
if expected
|
26
|
+
"application should not have a description matching #{expected.inspect} but got #{actual.inspect}"
|
27
|
+
else
|
28
|
+
"application should not have a description, got #{actual.inspect}"
|
37
29
|
end
|
38
30
|
end
|
39
31
|
end
|
@@ -1,115 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@actual = []
|
10
|
-
end
|
11
|
-
|
12
|
-
def matches?(actual)
|
13
|
-
# Data::Result has a bug in it's method missing in < 2.2.2 and < 2.3.0
|
14
|
-
# which raised the wrong exception class should someone call for example
|
15
|
-
# #to_ary like [x].flatten does causing the tests to fail, this works
|
16
|
-
# around that bug while we fix it in core.
|
17
|
-
unless actual.is_a?(Array)
|
18
|
-
actual = [actual]
|
19
|
-
end
|
20
|
-
|
21
|
-
if actual == []
|
22
|
-
return false
|
23
|
-
end
|
24
|
-
|
25
|
-
actual.each do |result|
|
26
|
-
if result.is_a?(MCollective::RPC::Result)
|
27
|
-
result = result.results
|
28
|
-
elsif result.is_a?(MCollective::Data::Result)
|
29
|
-
result = {:data => result.instance_variable_get("@data")}
|
30
|
-
end
|
31
|
-
|
32
|
-
@nodeid = result[:data][:test_sender]
|
33
|
-
@actual << result
|
34
|
-
@expected.each do |e|
|
35
|
-
if e.is_a? Hash
|
36
|
-
e.keys.each do |k|
|
37
|
-
unless result[:data].keys.include?(k)
|
38
|
-
return false
|
39
|
-
end
|
40
|
-
end
|
41
|
-
e.keys.each do |k|
|
42
|
-
if e[k].is_a?(String) || e[k].is_a?(Regexp)
|
43
|
-
unless result[:data][k].match e[k]
|
44
|
-
return false
|
45
|
-
end
|
46
|
-
else
|
47
|
-
unless result[:data][k] == e[k]
|
48
|
-
return false
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
else
|
53
|
-
unless result[:data].keys.include? e
|
54
|
-
return false
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
true
|
60
|
-
end
|
61
|
-
|
62
|
-
def failure_message
|
63
|
-
return_string = "Failure from #{@nodeid}\n"
|
64
|
-
return_string << "Expected : \n"
|
65
|
-
@expected.each do |e|
|
66
|
-
if e.is_a? Hash
|
67
|
-
e.keys.each do |k|
|
68
|
-
return_string << " '#{k}' with value '#{e[k]}'\n"
|
69
|
-
end
|
70
|
-
else
|
71
|
-
return_string << " '#{e}' to be present\n"
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
return_string << "Got : \n"
|
76
|
-
@actual.each do |a|
|
77
|
-
if a[:sender] == @nodeid
|
78
|
-
a[:data].each do |data|
|
79
|
-
return_string << " '#{data[0]}' with value '#{data[1]}'\n"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
return_string
|
85
|
-
end
|
86
|
-
|
87
|
-
def negative_failure_message
|
88
|
-
return_string = "Failure from #{@nodeid}\n"
|
89
|
-
return_string << "Did not expect : \n"
|
90
|
-
@expected.each do |e|
|
91
|
-
if e.is_a? Hash
|
92
|
-
e.keys.each do |k|
|
93
|
-
return_string << " '#{k}' with value '#{e[k]}'\n"
|
94
|
-
end
|
95
|
-
else
|
96
|
-
return_string << " '#{e}' to not be present\n"
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
return_string << "But got : \n"
|
101
|
-
@actual.each do |a|
|
102
|
-
if a[:sender] == @nodeid
|
103
|
-
a[:data].each do |data|
|
104
|
-
return_string << " '#{data[0]}' with value '#{data[1]}'\n"
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
return_string
|
110
|
-
end
|
111
|
-
|
112
|
-
end
|
1
|
+
RSpec::Matchers.define(:have_data_items) do |expected|
|
2
|
+
match do |actual|
|
3
|
+
if actual.is_a?(MCollective::RPC::Result)
|
4
|
+
actual.results.should include(expected)
|
5
|
+
elsif actual.is_a?(MCollective::Data::Result)
|
6
|
+
actual.instance_variable_get(:@data).should include(expected)
|
7
|
+
else
|
8
|
+
actual.should include(data: include(expected))
|
113
9
|
end
|
114
10
|
end
|
115
11
|
end
|
@@ -1,48 +1,29 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
alias be_unknown_action_error rpc_unknown_action
|
14
|
-
alias be_missing_data_error rpc_missing_data
|
15
|
-
alias be_invalid_data_error rpc_invalid_data
|
16
|
-
alias be_unknown_error rpc_unknown
|
17
|
-
|
18
|
-
class RPCStatus
|
19
|
-
def initialize(code)
|
20
|
-
@code = code
|
21
|
-
end
|
22
|
-
|
23
|
-
def matches?(actual)
|
24
|
-
if actual == []
|
25
|
-
return false
|
26
|
-
end
|
27
|
-
[actual].flatten.each do |result|
|
28
|
-
result = result.results if result.is_a?(MCollective::RPC::Result)
|
29
|
-
|
30
|
-
@actual = result[:statuscode]
|
31
|
-
|
32
|
-
unless @actual == @code
|
33
|
-
return false
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
1
|
+
{
|
2
|
+
0 => :rpc_success,
|
3
|
+
1 => :rpc_aborted,
|
4
|
+
2 => :rpc_unknown_action,
|
5
|
+
3 => :rpc_missing_data,
|
6
|
+
4 => :rpc_invalid_data,
|
7
|
+
5 => :rpc_unknown
|
8
|
+
}.each do |code, name|
|
9
|
+
RSpec::Matchers.define(name) do
|
10
|
+
match do |actual|
|
11
|
+
actual[:statuscode] == code
|
12
|
+
end
|
37
13
|
|
38
|
-
|
39
|
-
|
40
|
-
|
14
|
+
failure_message do |actual|
|
15
|
+
"expected :statuscode == #{code} but got #{actual[:statuscode]}"
|
16
|
+
end
|
41
17
|
|
42
|
-
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
18
|
+
failure_message_when_negated do |actual|
|
19
|
+
"expected :statuscode != #{code} but got #{actual[:statuscode]}"
|
46
20
|
end
|
47
21
|
end
|
48
22
|
end
|
23
|
+
|
24
|
+
RSpec::Matchers.alias_matcher :be_successful, :rpc_success
|
25
|
+
RSpec::Matchers.alias_matcher :be_aborted_error, :rpc_aborted
|
26
|
+
RSpec::Matchers.alias_matcher :be_unknown_error, :rpc_unknown_action
|
27
|
+
RSpec::Matchers.alias_matcher :be_missing_data_error, :rpc_missing_data
|
28
|
+
RSpec::Matchers.alias_matcher :be_invalid_data_error, :rpc_invalid_data
|
29
|
+
RSpec::Matchers.alias_matcher :be_unknown_error, :rpc_unknown
|
@@ -2,7 +2,6 @@ module MCollective
|
|
2
2
|
module Test
|
3
3
|
module Matchers
|
4
4
|
require 'mcollective/test/matchers/rpc_result_items.rb'
|
5
|
-
require 'mcollective/test/matchers/rpc_metadata.rb'
|
6
5
|
require 'mcollective/test/matchers/rpc_status.rb'
|
7
6
|
require 'mcollective/test/matchers/application_description.rb'
|
8
7
|
end
|
@@ -1,8 +1,10 @@
|
|
1
1
|
module MCollective
|
2
2
|
module Test
|
3
3
|
module Util
|
4
|
+
include Mocha::API
|
5
|
+
|
4
6
|
def create_facts_mock(factsource)
|
5
|
-
facts =
|
7
|
+
facts = mock('facts')
|
6
8
|
facts.stubs(:get_facts).returns(factsource)
|
7
9
|
|
8
10
|
factsource.each_pair do |k, v|
|
@@ -15,7 +17,7 @@ module MCollective
|
|
15
17
|
def create_config_mock(config)
|
16
18
|
pluginconf = {}
|
17
19
|
|
18
|
-
cfg =
|
20
|
+
cfg = mock('config')
|
19
21
|
cfg.stubs(:configured).returns(true)
|
20
22
|
cfg.stubs(:rpcauthorization).returns(false)
|
21
23
|
cfg.stubs(:main_collective).returns("mcollective")
|
@@ -55,7 +57,7 @@ module MCollective
|
|
55
57
|
end
|
56
58
|
|
57
59
|
def create_logger_mock
|
58
|
-
logger =
|
60
|
+
logger = mock(:logger)
|
59
61
|
|
60
62
|
[:log, :start, :debug, :info, :warn].each do |meth|
|
61
63
|
logger.stubs(meth)
|
@@ -69,7 +71,7 @@ module MCollective
|
|
69
71
|
end
|
70
72
|
|
71
73
|
def create_connector_mock
|
72
|
-
connector =
|
74
|
+
connector = mock(:connector)
|
73
75
|
|
74
76
|
[:connect, :receive, :publish, :subscribe, :unsubscribe, :disconnect].each do |meth|
|
75
77
|
connector.stubs(meth)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
spec = Gem::Specification.new do |s|
|
2
|
+
s.name = "mcollective-test"
|
3
|
+
s.version = "0.5.0"
|
4
|
+
s.author = "R.I.Pienaar"
|
5
|
+
s.email = "rip@devco.net"
|
6
|
+
s.homepage = "https://github.com/ripienaar/mcollective-test/"
|
7
|
+
s.summary = "Test helper for MCollective"
|
8
|
+
s.description = "Helpers, matchers and other utilities for writing agent, application and integration tests"
|
9
|
+
s.files = Dir.chdir(File.expand_path(__dir__)) do
|
10
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
11
|
+
end
|
12
|
+
s.require_path = "lib"
|
13
|
+
end
|
metadata
CHANGED
@@ -1,77 +1,57 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: mcollective-test
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease: false
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 4
|
9
|
-
- 3
|
10
|
-
version: 0.4.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- R.I.Pienaar
|
14
|
-
autorequire:
|
8
|
+
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2013-03-14 00:00:00 +00:00
|
19
|
-
default_executable:
|
11
|
+
date: 2024-08-24 00:00:00.000000000 Z
|
20
12
|
dependencies: []
|
21
|
-
|
22
|
-
|
13
|
+
description: Helpers, matchers and other utilities for writing agent, application
|
14
|
+
and integration tests
|
23
15
|
email: rip@devco.net
|
24
16
|
executables: []
|
25
|
-
|
26
17
|
extensions: []
|
27
|
-
|
28
18
|
extra_rdoc_files: []
|
29
|
-
|
30
|
-
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- Gemfile
|
22
|
+
- README.md
|
23
|
+
- Rakefile
|
31
24
|
- lib/mcollective/test.rb
|
25
|
+
- lib/mcollective/test/application_test.rb
|
26
|
+
- lib/mcollective/test/data_test.rb
|
32
27
|
- lib/mcollective/test/local_agent_test.rb
|
33
28
|
- lib/mcollective/test/matchers.rb
|
34
|
-
- lib/mcollective/test/
|
35
|
-
- lib/mcollective/test/data_test.rb
|
36
|
-
- lib/mcollective/test/matchers/rpc_metadata.rb
|
29
|
+
- lib/mcollective/test/matchers/application_description.rb
|
37
30
|
- lib/mcollective/test/matchers/rpc_result_items.rb
|
38
31
|
- lib/mcollective/test/matchers/rpc_status.rb
|
39
|
-
- lib/mcollective/test/
|
32
|
+
- lib/mcollective/test/remote_agent_test.rb
|
40
33
|
- lib/mcollective/test/util.rb
|
41
|
-
-
|
42
|
-
has_rdoc: true
|
34
|
+
- mcollective-test.gemspec
|
43
35
|
homepage: https://github.com/ripienaar/mcollective-test/
|
44
36
|
licenses: []
|
45
|
-
|
46
|
-
post_install_message:
|
37
|
+
metadata: {}
|
38
|
+
post_install_message:
|
47
39
|
rdoc_options: []
|
48
|
-
|
49
|
-
require_paths:
|
40
|
+
require_paths:
|
50
41
|
- lib
|
51
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
-
|
53
|
-
requirements:
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
54
44
|
- - ">="
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
version: "0"
|
60
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
-
none: false
|
62
|
-
requirements:
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
63
49
|
- - ">="
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
|
66
|
-
segments:
|
67
|
-
- 0
|
68
|
-
version: "0"
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
69
52
|
requirements: []
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
signing_key:
|
74
|
-
specification_version: 3
|
53
|
+
rubygems_version: 3.2.33
|
54
|
+
signing_key:
|
55
|
+
specification_version: 4
|
75
56
|
summary: Test helper for MCollective
|
76
57
|
test_files: []
|
77
|
-
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module MCollective
|
2
|
-
module Test
|
3
|
-
module Matchers
|
4
|
-
def have_valid_metadata; RPCMetadata.new; end
|
5
|
-
|
6
|
-
class RPCMetadata
|
7
|
-
def matches?(actual)
|
8
|
-
actual = actual.meta
|
9
|
-
|
10
|
-
@msg = "Unknown error"
|
11
|
-
|
12
|
-
[:name, :description, :author, :license, :version, :url, :timeout].each do |item|
|
13
|
-
unless actual.include?(item)
|
14
|
-
@msg = "needs a '#{item}' item"
|
15
|
-
return false
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
[:name, :description, :author, :license, :version, :url].each do |item|
|
20
|
-
unless actual[item].is_a?(String)
|
21
|
-
@msg = "#{item} should be a string"
|
22
|
-
return false
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
unless actual[:timeout].is_a?(Numeric)
|
27
|
-
@msg = "timeout should be numeric"
|
28
|
-
return false
|
29
|
-
end
|
30
|
-
|
31
|
-
return true
|
32
|
-
end
|
33
|
-
|
34
|
-
def failure_message
|
35
|
-
"Invalid meta data: #{@msg}"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|