schemata-health_manager 0.0.1.beta5 → 0.0.1.beta6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/schemata/common/componentbase.rb +42 -0
- data/lib/schemata/common/msgbase.rb +13 -11
- data/lib/schemata/common/msgtypebase.rb +20 -0
- data/lib/schemata/common/parsed_msg.rb +1 -1
- data/lib/schemata/health_manager/health_request.rb +0 -4
- data/lib/schemata/health_manager/health_response.rb +0 -4
- data/lib/schemata/health_manager/status_crashed_response.rb +0 -4
- data/lib/schemata/health_manager/status_flapping_response.rb +0 -4
- data/lib/schemata/health_manager/status_request.rb +0 -4
- data/lib/schemata/health_manager/version.rb +1 -1
- data/lib/schemata/health_manager.rb +2 -24
- data/lib/schemata/helpers/decamelize.rb +23 -0
- data/lib/schemata/helpers/hash_copy.rb +1 -1
- data/lib/schemata/helpers/stringify.rb +1 -1
- data/spec/{cloud_controller/cloud_controller_spec.rb → cloud_controller_spec.rb} +0 -0
- data/spec/common/helpers_spec.rb +16 -16
- data/spec/{dea/dea_spec.rb → dea_spec.rb} +1 -1
- data/spec/{health_manager/health_manager_spec.rb → health_manager_spec.rb} +0 -0
- data/spec/{router/router_spec.rb → router_spec.rb} +0 -0
- data/spec/{staging/staging_spec.rb → staging_spec.rb} +0 -0
- data/spec/support/component_helpers.rb +16 -2
- data/spec/support/helpers.rb +0 -20
- data/spec/support/message_helpers.rb +23 -19
- data/spec/support/message_type_helpers.rb +59 -55
- metadata +25 -69
- data/spec/cloud_controller/droplet_updated_message_spec.rb +0 -10
- data/spec/cloud_controller/hm_start_request_spec.rb +0 -11
- data/spec/cloud_controller/hm_stop_request_spec.rb +0 -12
- data/spec/dea/advertise_message_spec.rb +0 -10
- data/spec/dea/dea_status_response_spec.rb +0 -10
- data/spec/dea/discover_request_spec.rb +0 -10
- data/spec/dea/droplet_status_response_spec.rb +0 -10
- data/spec/dea/exit_message_spec.rb +0 -10
- data/spec/dea/find_droplet_request_spec.rb +0 -27
- data/spec/dea/find_droplet_response_spec.rb +0 -10
- data/spec/dea/heartbeat_response_spec.rb +0 -10
- data/spec/dea/hello_message_spec.rb +0 -10
- data/spec/dea/start_request_spec.rb +0 -10
- data/spec/dea/stop_request_spec.rb +0 -10
- data/spec/dea/update_request_spec.rb +0 -0
- data/spec/health_manager/health_request_spec.rb +0 -12
- data/spec/health_manager/health_response_spec.rb +0 -12
- data/spec/health_manager/status_crashed_response_spec.rb +0 -12
- data/spec/health_manager/status_flapping_response_spec.rb +0 -12
- data/spec/health_manager/status_request_spec.rb +0 -12
- data/spec/router/register_request_spec.rb +0 -10
- data/spec/router/start_message_spec.rb +0 -10
- data/spec/staging/staging_message_spec.rb +0 -14
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'schemata/helpers/decamelize'
|
2
|
+
|
3
|
+
module Schemata
|
4
|
+
module ComponentBase
|
5
|
+
|
6
|
+
def message_types
|
7
|
+
self.constants.select { |x| x != :VERSION }
|
8
|
+
end
|
9
|
+
|
10
|
+
def component_name
|
11
|
+
self.name.split("::")[1]
|
12
|
+
end
|
13
|
+
|
14
|
+
def eigenclass
|
15
|
+
class << self; self; end
|
16
|
+
end
|
17
|
+
|
18
|
+
def register_mock_methods
|
19
|
+
message_types.each do |type|
|
20
|
+
message_type = self::const_get(type)
|
21
|
+
mock_method_name = "mock_#{Schemata::Helpers.decamelize(type.to_s)}"
|
22
|
+
eigenclass.send(:define_method, mock_method_name) do |*args|
|
23
|
+
version = args[0] || message_type.current_version
|
24
|
+
message_type::const_get("V#{version}").mock
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def require_message_classes
|
30
|
+
path = "./lib/schemata/"
|
31
|
+
path << Schemata::Helpers.decamelize(component_name)
|
32
|
+
path << "/*.rb"
|
33
|
+
Dir.glob(path, &method(:require))
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.extended(klass)
|
37
|
+
klass.require_message_classes
|
38
|
+
klass.register_mock_methods
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -14,7 +14,7 @@ module Schemata
|
|
14
14
|
@contents = {}
|
15
15
|
|
16
16
|
data.each do |key, field_value|
|
17
|
-
key = Schemata::
|
17
|
+
key = Schemata::Helpers.stringify(key)
|
18
18
|
field_schema = @schema.schemas[key]
|
19
19
|
next unless field_schema
|
20
20
|
|
@@ -27,7 +27,7 @@ module Schemata
|
|
27
27
|
# symbols, but on the decoding side, it should expect strings. To allow
|
28
28
|
# for this in the schema definition, Schemata stringifies all symbols during
|
29
29
|
# construction of Schemata objects.
|
30
|
-
field_value = Schemata::
|
30
|
+
field_value = Schemata::Helpers.stringify(field_value)
|
31
31
|
|
32
32
|
begin
|
33
33
|
field_schema.validate(field_value)
|
@@ -35,7 +35,7 @@ module Schemata
|
|
35
35
|
raise Schemata::UpdateAttributeError.new(key, e.message)
|
36
36
|
end
|
37
37
|
|
38
|
-
@contents[key] = Schemata::
|
38
|
+
@contents[key] = Schemata::Helpers.deep_copy(field_value)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -45,7 +45,7 @@ module Schemata
|
|
45
45
|
schema.schemas.each do |key, field_schema|
|
46
46
|
vc_klass.send(:define_method, key) do
|
47
47
|
unless @contents[key].nil?
|
48
|
-
return Schemata::
|
48
|
+
return Schemata::Helpers.deep_copy(@contents[key])
|
49
49
|
end
|
50
50
|
nil
|
51
51
|
end
|
@@ -53,13 +53,15 @@ module Schemata
|
|
53
53
|
# TODO This call to stringify should be removed when cc/dea stops using
|
54
54
|
# symbols. See comment above for a better description.
|
55
55
|
vc_klass.send(:define_method, "#{key}=") do |field_value|
|
56
|
-
field_value = Schemata::
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
56
|
+
field_value = Schemata::Helpers.stringify(field_value)
|
57
|
+
unless schema.optional_keys.include?(key) && field_value == nil
|
58
|
+
begin
|
59
|
+
field_schema.validate(field_value)
|
60
|
+
rescue Membrane::SchemaValidationError => e
|
61
|
+
raise Schemata::UpdateAttributeError.new(key, e.message)
|
62
|
+
end
|
61
63
|
end
|
62
|
-
@contents[key] = Schemata::
|
64
|
+
@contents[key] = Schemata::Helpers.deep_copy(field_value)
|
63
65
|
field_value
|
64
66
|
end
|
65
67
|
end
|
@@ -67,7 +69,7 @@ module Schemata
|
|
67
69
|
end
|
68
70
|
|
69
71
|
def contents
|
70
|
-
Schemata::
|
72
|
+
Schemata::Helpers.deep_copy(@contents)
|
71
73
|
end
|
72
74
|
|
73
75
|
def empty?
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'schemata/common/msgbase'
|
2
2
|
require 'schemata/common/parsed_msg'
|
3
|
+
require 'schemata/helpers/decamelize'
|
3
4
|
|
4
5
|
module Schemata
|
5
6
|
module MessageTypeBase
|
@@ -70,8 +71,27 @@ module Schemata
|
|
70
71
|
Schemata::const_get(component)
|
71
72
|
end
|
72
73
|
|
74
|
+
def component_name
|
75
|
+
self.name.split("::")[1]
|
76
|
+
end
|
77
|
+
|
78
|
+
def message_type_name
|
79
|
+
self.name.split("::")[2]
|
80
|
+
end
|
81
|
+
|
82
|
+
def require_message_versions
|
83
|
+
path = "./lib/schemata/"
|
84
|
+
path << Schemata::Helpers.decamelize(component_name)
|
85
|
+
path << "/"
|
86
|
+
path << Schemata::Helpers.decamelize(message_type_name)
|
87
|
+
path << "/*.rb"
|
88
|
+
|
89
|
+
Dir.glob(path, &method(:require))
|
90
|
+
end
|
91
|
+
|
73
92
|
def self.extended(o)
|
74
93
|
o.extend Dsl
|
94
|
+
o.require_message_versions
|
75
95
|
end
|
76
96
|
|
77
97
|
module Dsl
|
@@ -1,29 +1,7 @@
|
|
1
|
-
require 'schemata/
|
2
|
-
require 'schemata/health_manager/status_flapping_response'
|
3
|
-
require 'schemata/health_manager/status_crashed_response'
|
4
|
-
require 'schemata/health_manager/health_request'
|
5
|
-
require 'schemata/health_manager/health_response'
|
1
|
+
require 'schemata/common/componentbase'
|
6
2
|
|
7
3
|
module Schemata
|
8
4
|
module HealthManager
|
9
|
-
|
10
|
-
StatusRequest::const_get("V#{version}").mock
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.mock_status_flapping_response(version=StatusFlappingResponse.current_version)
|
14
|
-
StatusFlappingResponse::const_get("V#{version}").mock
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.mock_status_crashed_response(version=StatusCrashedResponse.current_version)
|
18
|
-
StatusCrashedResponse::const_get("V#{version}").mock
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.mock_health_request(version=HealthRequest.current_version)
|
22
|
-
HealthRequest::const_get("V#{version}").mock
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.mock_health_response(version=HealthResponse.current_version)
|
26
|
-
HealthResponse::const_get("V#{version}").mock
|
27
|
-
end
|
5
|
+
extend Schemata::ComponentBase
|
28
6
|
end
|
29
7
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Schemata
|
2
|
+
module Helpers
|
3
|
+
def self.decamelize(str)
|
4
|
+
words = []
|
5
|
+
curr_word = ""
|
6
|
+
0.upto(str.length - 1) do |i|
|
7
|
+
ch = str[i]
|
8
|
+
if ch =~ /[A-Z]/
|
9
|
+
words.push(curr_word)
|
10
|
+
curr_word = ""
|
11
|
+
end
|
12
|
+
curr_word += ch
|
13
|
+
end
|
14
|
+
words.push(curr_word)
|
15
|
+
words.map! { |x| x.downcase }
|
16
|
+
|
17
|
+
# If the first letter is capitalized, then the first word here is empty
|
18
|
+
words.shift if words[0] == ""
|
19
|
+
|
20
|
+
words.join('_')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
File without changes
|
data/spec/common/helpers_spec.rb
CHANGED
@@ -1,49 +1,49 @@
|
|
1
1
|
require 'schemata/helpers/hash_copy'
|
2
2
|
require 'schemata/helpers/stringify'
|
3
3
|
|
4
|
-
describe Schemata::
|
4
|
+
describe Schemata::Helpers do
|
5
5
|
describe "#deep_copy" do
|
6
6
|
it "should deep copy nil" do
|
7
|
-
copy = Schemata::
|
7
|
+
copy = Schemata::Helpers.deep_copy(nil)
|
8
8
|
copy.should == nil
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should deep copy a given string" do
|
12
12
|
original = "foo"
|
13
|
-
copy = Schemata::
|
13
|
+
copy = Schemata::Helpers.deep_copy(original)
|
14
14
|
copy.should be_instance_of String
|
15
15
|
copy.should == original
|
16
16
|
copy.object_id.should_not == original.object_id
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should deep copy a given boolean" do
|
20
|
-
Schemata::
|
20
|
+
Schemata::Helpers.deep_copy(true).
|
21
21
|
should be_an_instance_of TrueClass
|
22
|
-
Schemata::
|
22
|
+
Schemata::Helpers.deep_copy(false).
|
23
23
|
should be_an_instance_of FalseClass
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should deep copy a given numeric type" do
|
27
27
|
original = 0
|
28
|
-
copy = Schemata::
|
28
|
+
copy = Schemata::Helpers.deep_copy(original)
|
29
29
|
copy.should == original
|
30
30
|
copy.should be_an_instance_of Fixnum
|
31
31
|
|
32
32
|
# set original to be max fixnum + 1
|
33
33
|
original = 2**(0.size * 8 - 2)
|
34
|
-
copy = Schemata::
|
34
|
+
copy = Schemata::Helpers.deep_copy(original)
|
35
35
|
copy.should == original
|
36
36
|
copy.should be_an_instance_of Bignum
|
37
37
|
|
38
38
|
original = 0.0
|
39
|
-
copy = Schemata::
|
39
|
+
copy = Schemata::Helpers.deep_copy(original)
|
40
40
|
copy.should == original
|
41
41
|
copy.should be_an_instance_of Float
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should deep copy a given hash" do
|
45
45
|
original = {"foo" => "bar"}
|
46
|
-
copy = Schemata::
|
46
|
+
copy = Schemata::Helpers.deep_copy(original)
|
47
47
|
copy.should be_instance_of Hash
|
48
48
|
copy.should == original
|
49
49
|
|
@@ -53,7 +53,7 @@ describe Schemata::HashCopyHelpers do
|
|
53
53
|
|
54
54
|
it "should deep copy a given array" do
|
55
55
|
original = [1, 2, "hello"]
|
56
|
-
copy = Schemata::
|
56
|
+
copy = Schemata::Helpers.deep_copy(original)
|
57
57
|
copy.should be_instance_of Array
|
58
58
|
copy.should == original
|
59
59
|
|
@@ -69,7 +69,7 @@ describe Schemata::HashCopyHelpers do
|
|
69
69
|
"hello" => "goodbye",
|
70
70
|
},
|
71
71
|
}
|
72
|
-
copy = Schemata::
|
72
|
+
copy = Schemata::Helpers.deep_copy(original)
|
73
73
|
copy.should be_instance_of Hash
|
74
74
|
copy.should == original
|
75
75
|
|
@@ -83,32 +83,32 @@ describe Schemata::HashCopyHelpers do
|
|
83
83
|
it "should raise error for unknown type" do
|
84
84
|
klass = Class.new
|
85
85
|
expect do
|
86
|
-
Schemata::
|
86
|
+
Schemata::Helpers.deep_copy(klass.new)
|
87
87
|
end.to raise_error(described_class::CopyError, /Unexpected class: /)
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
91
|
describe "#stringify" do
|
92
92
|
it "should stringify nil" do
|
93
|
-
str = Schemata::
|
93
|
+
str = Schemata::Helpers.stringify(nil)
|
94
94
|
str.should == nil
|
95
95
|
end
|
96
96
|
|
97
97
|
it "should stringify a string" do
|
98
98
|
original = "foo"
|
99
|
-
str = Schemata::
|
99
|
+
str = Schemata::Helpers.stringify(original)
|
100
100
|
str.should == "foo"
|
101
101
|
end
|
102
102
|
|
103
103
|
it "should stringify a symbol" do
|
104
104
|
original = :foo
|
105
|
-
str = Schemata::
|
105
|
+
str = Schemata::Helpers.stringify(original)
|
106
106
|
str.should == "foo"
|
107
107
|
end
|
108
108
|
|
109
109
|
it "should stringify a hash" do
|
110
110
|
original = { "foo" => :foo }
|
111
|
-
str = Schemata::
|
111
|
+
str = Schemata::Helpers.stringify(original)
|
112
112
|
str.should == { "foo" => "foo" }
|
113
113
|
end
|
114
114
|
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'support/helpers'
|
2
|
+
require 'schemata/helpers/decamelize'
|
2
3
|
|
3
4
|
shared_examples "a schemata component" do
|
4
5
|
|
5
6
|
described_class.constants.select { |x| x != :VERSION }.each do |msg_type|
|
6
|
-
describe ".mock_#{decamelize(msg_type.to_s)}" do
|
7
|
+
describe ".mock_#{Schemata::Helpers.decamelize(msg_type.to_s)}" do
|
7
8
|
versions = described_class::const_get(msg_type).constants.select { |x| x =~ /V[0-9]+/ }
|
8
9
|
versions.map { |x| x = x.to_s[1..-1].to_i }.each do |version|
|
9
10
|
it_behaves_like "a mocking method", version do
|
@@ -12,11 +13,24 @@ shared_examples "a schemata component" do
|
|
12
13
|
let(:component) { described_class }
|
13
14
|
let(:component_name) { component.name.split("::")[1] }
|
14
15
|
|
15
|
-
let(:mock_method) { "mock_#{decamelize(msg_type)}"}
|
16
|
+
let(:mock_method) { "mock_#{Schemata::Helpers.decamelize(msg_type)}"}
|
16
17
|
end
|
17
18
|
end
|
18
19
|
end
|
20
|
+
|
21
|
+
describe msg_type do
|
22
|
+
message_type = described_class::const_get(msg_type)
|
23
|
+
it_behaves_like "a message type", message_type do
|
24
|
+
let (:message_type) { described_class::const_get(msg_type) }
|
25
|
+
let (:message_type_name) { msg_type.to_s }
|
26
|
+
let (:component) { described_class }
|
27
|
+
let (:component_name) { component.name.split("::")[1] }
|
28
|
+
|
29
|
+
let (:mock_method) { "mock_#{Schemata::Helpers.decamelize(msg_type)}" }
|
30
|
+
end
|
31
|
+
end
|
19
32
|
end
|
33
|
+
|
20
34
|
end
|
21
35
|
|
22
36
|
shared_examples "a mocking method" do |version|
|
data/spec/support/helpers.rb
CHANGED
@@ -26,26 +26,6 @@ def greater_version?(version, benchmark)
|
|
26
26
|
version > benchmark
|
27
27
|
end
|
28
28
|
|
29
|
-
def decamelize(str)
|
30
|
-
words = []
|
31
|
-
curr_word = ""
|
32
|
-
0.upto(str.length - 1) do |i|
|
33
|
-
ch = str[i]
|
34
|
-
if ch =~ /[A-Z]/
|
35
|
-
words.push(curr_word)
|
36
|
-
curr_word = ""
|
37
|
-
end
|
38
|
-
curr_word += ch
|
39
|
-
end
|
40
|
-
words.push(curr_word)
|
41
|
-
words.map! { |x| x.downcase }
|
42
|
-
|
43
|
-
# If the first letter is capitalized, then the first word here is empty
|
44
|
-
words.shift if words[0] == ""
|
45
|
-
|
46
|
-
words.join('_')
|
47
|
-
end
|
48
|
-
|
49
29
|
def num_mandatory_fields(msg_obj)
|
50
30
|
optional = msg_obj.class.schema.optional_keys
|
51
31
|
mandatory = Set.new(msg_obj.class.schema.schemas.keys)
|
@@ -1,16 +1,5 @@
|
|
1
|
-
shared_examples "a message" do
|
2
|
-
|
3
|
-
version = described_class.version
|
4
|
-
|
5
|
-
let(:component_name) { described_class.name.split("::")[1] }
|
6
|
-
let(:message_type_name) { described_class.name.split("::")[2] }
|
7
|
-
let(:message_name) { described_class.name.split("::")[3] }
|
8
|
-
|
9
|
-
let(:component) { Schemata::const_get(component_name) }
|
10
|
-
let(:message_type) { component::const_get(message_type_name) }
|
11
|
-
let(:message) { described_class }
|
12
|
-
|
13
|
-
let(:mock_method) { "mock_#{decamelize(message_type_name)}" }
|
1
|
+
shared_examples "a message" do |msg|
|
2
|
+
version = msg.version
|
14
3
|
|
15
4
|
before :each do
|
16
5
|
set_current_version(message_type, version)
|
@@ -21,7 +10,7 @@ shared_examples "a message" do
|
|
21
10
|
end
|
22
11
|
|
23
12
|
describe "#new" do
|
24
|
-
it "should create a #{
|
13
|
+
it "should create a #{msg} object with an incomplete hash" do
|
25
14
|
mock_hash = component.send(mock_method, 1).contents
|
26
15
|
first_key = mock_hash.keys[0]
|
27
16
|
first_value = mock_hash[first_key]
|
@@ -68,7 +57,7 @@ shared_examples "a message" do
|
|
68
57
|
json_hash.should have_key "V1"
|
69
58
|
json_hash.should have_key "min_version"
|
70
59
|
|
71
|
-
data = Schemata::
|
60
|
+
data = Schemata::Helpers.deep_copy(json_hash["V1"])
|
72
61
|
|
73
62
|
json_hash.delete("V1")
|
74
63
|
json_hash.delete("min_version")
|
@@ -86,7 +75,7 @@ shared_examples "a message" do
|
|
86
75
|
end
|
87
76
|
json_hash.should have_key "min_version"
|
88
77
|
|
89
|
-
data = Schemata::
|
78
|
+
data = Schemata::Helpers.deep_copy(json_hash["V#{version}"])
|
90
79
|
1.upto(version) do |i|
|
91
80
|
json_hash.delete("V#{i}")
|
92
81
|
end
|
@@ -97,9 +86,9 @@ shared_examples "a message" do
|
|
97
86
|
end
|
98
87
|
end
|
99
88
|
|
100
|
-
|
89
|
+
msg.schema.schemas.keys.each do |attr|
|
101
90
|
describe "##{attr}" do
|
102
|
-
it "should the attribute if it was specified at instantiation" do
|
91
|
+
it "should return the attribute if it was specified at instantiation" do
|
103
92
|
mock_value = component.send(mock_method, version).contents[attr]
|
104
93
|
msg_obj = message.new({ attr => mock_value })
|
105
94
|
msg_obj.send(attr).should == mock_value
|
@@ -116,6 +105,21 @@ shared_examples "a message" do
|
|
116
105
|
msg_obj = message.new
|
117
106
|
msg_obj.send(attr).should be_nil
|
118
107
|
end
|
108
|
+
|
109
|
+
if msg.schema.optional_keys.include? attr
|
110
|
+
context "the attribute is optional" do
|
111
|
+
it "should allow nil values during instantiation" do
|
112
|
+
mock_value = component.send(mock_method, version).contents[attr]
|
113
|
+
hash = { attr => mock_value }
|
114
|
+
msg_obj = message.new(hash)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should be able to set the attribute to nil" do
|
118
|
+
msg_obj = message.new
|
119
|
+
msg_obj.send("#{attr}=", nil)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
119
123
|
end
|
120
124
|
|
121
125
|
describe "##{attr}=" do
|
@@ -127,7 +131,7 @@ shared_examples "a message" do
|
|
127
131
|
ret.should == mock_value
|
128
132
|
end
|
129
133
|
|
130
|
-
unless
|
134
|
+
unless msg.schema.schemas[attr].kind_of? Membrane::Schema::Any
|
131
135
|
it "should raise an error if the wrong type is written" do
|
132
136
|
mock_value = component.send(mock_method, version).contents[attr]
|
133
137
|
|
@@ -1,15 +1,8 @@
|
|
1
|
-
shared_examples "a message type" do
|
1
|
+
shared_examples "a message type" do |msg_type|
|
2
2
|
|
3
|
-
versions =
|
3
|
+
versions = msg_type.constants.select {|x| x =~ /V[0-9]+/ }
|
4
4
|
.map {|x| x.to_s[1..-1].to_i}
|
5
5
|
|
6
|
-
let(:message_type_name) { described_class.name.split("::")[2] }
|
7
|
-
let(:message_type) { described_class }
|
8
|
-
let(:component_name) { described_class.name.split("::")[1] }
|
9
|
-
let(:component) { Schemata::const_get(component_name) }
|
10
|
-
|
11
|
-
let(:mock_method) { "mock_#{decamelize(message_type_name)}" }
|
12
|
-
|
13
6
|
describe ".decode" do
|
14
7
|
context "when the current version is 1" do
|
15
8
|
before :each do
|
@@ -50,7 +43,7 @@ shared_examples "a message type" do
|
|
50
43
|
msg_hash = {
|
51
44
|
"V1" => data,
|
52
45
|
"min_version" => 1
|
53
|
-
}.merge(Schemata::
|
46
|
+
}.merge(Schemata::Helpers.deep_copy(data))
|
54
47
|
json = Yajl::Encoder.encode(msg_hash)
|
55
48
|
|
56
49
|
msg_obj = message_type.decode(json)
|
@@ -96,68 +89,68 @@ structure or a complete flash hash" do
|
|
96
89
|
}.to raise_error(Schemata::DecodeError)
|
97
90
|
end
|
98
91
|
end
|
99
|
-
end
|
100
92
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
93
|
+
if versions.include?(2)
|
94
|
+
context "when the current version is 2" do
|
95
|
+
before :each do
|
96
|
+
set_current_version(message_type, 2)
|
97
|
+
end
|
106
98
|
|
107
|
-
|
108
|
-
|
109
|
-
|
99
|
+
after :each do
|
100
|
+
reset_version(message_type)
|
101
|
+
end
|
110
102
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
103
|
+
it "should raise an error given a flat hash" do
|
104
|
+
data = component.send(mock_method, 2).contents
|
105
|
+
json = Yajl::Encoder.encode(data)
|
106
|
+
expect {
|
107
|
+
msg_obj = message_type.decode(json)
|
108
|
+
}.to raise_error(Schemata::DecodeError)
|
109
|
+
end
|
118
110
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
111
|
+
it "should return a V2 object a given a mixed (flat hash + V1-encoded) json" do
|
112
|
+
msg_hash = component.send(mock_method, 2).contents
|
113
|
+
v1_hash = Schemata::Helpers.deep_copy(msg_hash)
|
114
|
+
msg_hash["V1"] = v1_hash
|
115
|
+
msg_hash["min_version"] = 1
|
124
116
|
|
125
|
-
|
117
|
+
json = Yajl::Encoder.encode(msg_hash)
|
126
118
|
|
127
|
-
|
128
|
-
|
119
|
+
msg_obj = message_type.decode(json)
|
120
|
+
msg_obj.class.should == message_type::V2
|
129
121
|
|
130
|
-
|
131
|
-
|
122
|
+
message_type::V2.schema.schemas.keys.each do |key|
|
123
|
+
msg_obj.send(key).should == v1_hash[key]
|
124
|
+
end
|
132
125
|
end
|
133
|
-
end
|
134
126
|
|
135
|
-
|
136
|
-
|
137
|
-
|
127
|
+
it "should return a V2 object given a V1-encoded json" do
|
128
|
+
v1_hash = component.send(mock_method, 1).contents
|
129
|
+
msg_hash = {"V1" => v1_hash, 'min_version' => 1}
|
138
130
|
|
139
|
-
|
131
|
+
json = Yajl::Encoder.encode(msg_hash)
|
140
132
|
|
141
|
-
|
142
|
-
|
133
|
+
msg_obj = message_type.decode(json)
|
134
|
+
msg_obj.class.should == message_type::V2
|
143
135
|
|
144
|
-
|
145
|
-
|
136
|
+
message_type::V2.schema.schemas.keys.each do |key|
|
137
|
+
msg_obj.send(key).should == v1_hash[key]
|
138
|
+
end
|
146
139
|
end
|
147
|
-
end
|
148
140
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
141
|
+
it "should return a V2 object given a V2-encoded object" do
|
142
|
+
data = component.send(mock_method, 2).contents
|
143
|
+
v2_hash = Schemata::Helpers.deep_copy(data)
|
144
|
+
msg_hash = {"V2" => v2_hash, "V1" => {}, "min_version" => 1}
|
153
145
|
|
154
|
-
|
146
|
+
json = Yajl::Encoder.encode(msg_hash)
|
155
147
|
|
156
|
-
|
157
|
-
|
148
|
+
msg_obj = message_type.decode(json)
|
149
|
+
msg_obj.class.should == message_type::V2
|
158
150
|
|
159
|
-
|
160
|
-
|
151
|
+
message_type::V2.schema.schemas.keys.each do |key|
|
152
|
+
msg_obj.send(key).should == data[key]
|
153
|
+
end
|
161
154
|
end
|
162
155
|
end
|
163
156
|
end
|
@@ -168,4 +161,15 @@ structure or a complete flash hash" do
|
|
168
161
|
versions.select { |x| x > 2 }.each do |version|
|
169
162
|
|
170
163
|
end
|
164
|
+
|
165
|
+
# Test message version types
|
166
|
+
versions.each do |version|
|
167
|
+
msg = msg_type::const_get("V#{version}")
|
168
|
+
describe "V#{version}" do
|
169
|
+
it_behaves_like "a message", msg do
|
170
|
+
let (:message) { message_type::const_get("V#{version}") }
|
171
|
+
let (:message_name) { message.to_s }
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
171
175
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schemata-health_manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.
|
4
|
+
version: 0.0.1.beta6
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -115,28 +115,27 @@ executables: []
|
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
-
- lib/schemata/
|
119
|
-
- lib/schemata/
|
120
|
-
- lib/schemata/
|
121
|
-
- lib/schemata/
|
118
|
+
- lib/schemata/common/componentbase.rb
|
119
|
+
- lib/schemata/common/error.rb
|
120
|
+
- lib/schemata/common/msgbase.rb
|
121
|
+
- lib/schemata/common/msgtypebase.rb
|
122
|
+
- lib/schemata/common/parsed_msg.rb
|
122
123
|
- lib/schemata/health_manager/health_request/health_request_v1.rb
|
123
|
-
- lib/schemata/health_manager/health_response/health_response.rb
|
124
|
-
- lib/schemata/health_manager/version.rb
|
125
124
|
- lib/schemata/health_manager/health_request.rb
|
125
|
+
- lib/schemata/health_manager/health_response/health_response.rb
|
126
126
|
- lib/schemata/health_manager/health_response.rb
|
127
|
-
- lib/schemata/health_manager/status_request/status_request_v1.rb
|
128
127
|
- lib/schemata/health_manager/status_crashed_response/status_crashed_response_v1.rb
|
128
|
+
- lib/schemata/health_manager/status_crashed_response.rb
|
129
|
+
- lib/schemata/health_manager/status_flapping_response/status_flapping_response_v1.rb
|
130
|
+
- lib/schemata/health_manager/status_flapping_response.rb
|
131
|
+
- lib/schemata/health_manager/status_request/status_request_v1.rb
|
132
|
+
- lib/schemata/health_manager/status_request.rb
|
133
|
+
- lib/schemata/health_manager/version.rb
|
129
134
|
- lib/schemata/health_manager.rb
|
130
|
-
- lib/schemata/
|
131
|
-
- lib/schemata/common/parsed_msg.rb
|
132
|
-
- lib/schemata/common/msgbase.rb
|
133
|
-
- lib/schemata/common/error.rb
|
134
|
-
- lib/schemata/helpers/stringify.rb
|
135
|
+
- lib/schemata/helpers/decamelize.rb
|
135
136
|
- lib/schemata/helpers/hash_copy.rb
|
136
|
-
-
|
137
|
-
- spec/
|
138
|
-
- spec/cloud_controller/hm_start_request_spec.rb
|
139
|
-
- spec/cloud_controller/hm_stop_request_spec.rb
|
137
|
+
- lib/schemata/helpers/stringify.rb
|
138
|
+
- spec/cloud_controller_spec.rb
|
140
139
|
- spec/common/helpers_spec.rb
|
141
140
|
- spec/common/parsed_msg_spec.rb
|
142
141
|
- spec/component/aux_data_spec.rb
|
@@ -144,31 +143,11 @@ files:
|
|
144
143
|
- spec/component/component_foo_spec.rb
|
145
144
|
- spec/component/foo_spec.rb
|
146
145
|
- spec/component2/component2_bar_spec.rb
|
147
|
-
- spec/
|
148
|
-
- spec/
|
149
|
-
- spec/
|
150
|
-
- spec/dea/discover_request_spec.rb
|
151
|
-
- spec/dea/droplet_status_response_spec.rb
|
152
|
-
- spec/dea/exit_message_spec.rb
|
153
|
-
- spec/dea/find_droplet_request_spec.rb
|
154
|
-
- spec/dea/find_droplet_response_spec.rb
|
155
|
-
- spec/dea/heartbeat_response_spec.rb
|
156
|
-
- spec/dea/hello_message_spec.rb
|
157
|
-
- spec/dea/start_request_spec.rb
|
158
|
-
- spec/dea/stop_request_spec.rb
|
159
|
-
- spec/dea/update_request_spec.rb
|
160
|
-
- spec/health_manager/health_manager_spec.rb
|
161
|
-
- spec/health_manager/health_request_spec.rb
|
162
|
-
- spec/health_manager/health_response_spec.rb
|
163
|
-
- spec/health_manager/status_crashed_response_spec.rb
|
164
|
-
- spec/health_manager/status_flapping_response_spec.rb
|
165
|
-
- spec/health_manager/status_request_spec.rb
|
166
|
-
- spec/router/register_request_spec.rb
|
167
|
-
- spec/router/router_spec.rb
|
168
|
-
- spec/router/start_message_spec.rb
|
146
|
+
- spec/dea_spec.rb
|
147
|
+
- spec/health_manager_spec.rb
|
148
|
+
- spec/router_spec.rb
|
169
149
|
- spec/spec_helper.rb
|
170
|
-
- spec/
|
171
|
-
- spec/staging/staging_spec.rb
|
150
|
+
- spec/staging_spec.rb
|
172
151
|
- spec/support/component_helpers.rb
|
173
152
|
- spec/support/helpers.rb
|
174
153
|
- spec/support/message_helpers.rb
|
@@ -198,10 +177,7 @@ signing_key:
|
|
198
177
|
specification_version: 3
|
199
178
|
summary: validation for cloundfoundry health manager messages
|
200
179
|
test_files:
|
201
|
-
- spec/
|
202
|
-
- spec/cloud_controller/droplet_updated_message_spec.rb
|
203
|
-
- spec/cloud_controller/hm_start_request_spec.rb
|
204
|
-
- spec/cloud_controller/hm_stop_request_spec.rb
|
180
|
+
- spec/cloud_controller_spec.rb
|
205
181
|
- spec/common/helpers_spec.rb
|
206
182
|
- spec/common/parsed_msg_spec.rb
|
207
183
|
- spec/component/aux_data_spec.rb
|
@@ -209,31 +185,11 @@ test_files:
|
|
209
185
|
- spec/component/component_foo_spec.rb
|
210
186
|
- spec/component/foo_spec.rb
|
211
187
|
- spec/component2/component2_bar_spec.rb
|
212
|
-
- spec/
|
213
|
-
- spec/
|
214
|
-
- spec/
|
215
|
-
- spec/dea/discover_request_spec.rb
|
216
|
-
- spec/dea/droplet_status_response_spec.rb
|
217
|
-
- spec/dea/exit_message_spec.rb
|
218
|
-
- spec/dea/find_droplet_request_spec.rb
|
219
|
-
- spec/dea/find_droplet_response_spec.rb
|
220
|
-
- spec/dea/heartbeat_response_spec.rb
|
221
|
-
- spec/dea/hello_message_spec.rb
|
222
|
-
- spec/dea/start_request_spec.rb
|
223
|
-
- spec/dea/stop_request_spec.rb
|
224
|
-
- spec/dea/update_request_spec.rb
|
225
|
-
- spec/health_manager/health_manager_spec.rb
|
226
|
-
- spec/health_manager/health_request_spec.rb
|
227
|
-
- spec/health_manager/health_response_spec.rb
|
228
|
-
- spec/health_manager/status_crashed_response_spec.rb
|
229
|
-
- spec/health_manager/status_flapping_response_spec.rb
|
230
|
-
- spec/health_manager/status_request_spec.rb
|
231
|
-
- spec/router/register_request_spec.rb
|
232
|
-
- spec/router/router_spec.rb
|
233
|
-
- spec/router/start_message_spec.rb
|
188
|
+
- spec/dea_spec.rb
|
189
|
+
- spec/health_manager_spec.rb
|
190
|
+
- spec/router_spec.rb
|
234
191
|
- spec/spec_helper.rb
|
235
|
-
- spec/
|
236
|
-
- spec/staging/staging_spec.rb
|
192
|
+
- spec/staging_spec.rb
|
237
193
|
- spec/support/component_helpers.rb
|
238
194
|
- spec/support/helpers.rb
|
239
195
|
- spec/support/message_helpers.rb
|
@@ -1,10 +0,0 @@
|
|
1
|
-
require 'schemata/cloud_controller'
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Schemata::CloudController::DropletUpdatedMessage do
|
5
|
-
it_behaves_like "a message type"
|
6
|
-
end
|
7
|
-
|
8
|
-
describe Schemata::CloudController::DropletUpdatedMessage::V1 do
|
9
|
-
it_behaves_like "a message"
|
10
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
require "schemata/cloud_controller"
|
2
|
-
|
3
|
-
describe Schemata::CloudController::HmStartRequest do
|
4
|
-
it_behaves_like "a message type"
|
5
|
-
end
|
6
|
-
|
7
|
-
Schemata::CloudController::HmStartRequest.versions.each do |v|
|
8
|
-
describe Schemata::CloudController::HmStartRequest::const_get("V#{v}") do
|
9
|
-
it_behaves_like "a message"
|
10
|
-
end
|
11
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'schemata/cloud_controller'
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Schemata::CloudController::HmStopRequest do
|
5
|
-
it_behaves_like "a message type"
|
6
|
-
end
|
7
|
-
|
8
|
-
Schemata::CloudController::HmStopRequest.versions.each do |v|
|
9
|
-
describe Schemata::CloudController::HmStopRequest::const_get("V#{v}") do
|
10
|
-
it_behaves_like "a message"
|
11
|
-
end
|
12
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'schemata/dea'
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Schemata::DEA::FindDropletRequest do
|
5
|
-
it_behaves_like "a message type"
|
6
|
-
end
|
7
|
-
|
8
|
-
describe Schemata::DEA::FindDropletRequest::V1 do
|
9
|
-
it_behaves_like "a message"
|
10
|
-
|
11
|
-
it "should stringify the 'states' field when it is given to the constructor as a symbol" do
|
12
|
-
hash = {
|
13
|
-
"droplet" => "deadbeef",
|
14
|
-
"states" => [:RUNNING],
|
15
|
-
"version" => "0.1.0",
|
16
|
-
}
|
17
|
-
|
18
|
-
msg_obj = Schemata::DEA::FindDropletRequest::V1.new(hash)
|
19
|
-
msg_obj.states.should =~ ["RUNNING"]
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should stringify the 'states' field when a symbold is passed ot the attr writer" do
|
23
|
-
msg_obj = Schemata::DEA.mock_find_droplet_request
|
24
|
-
msg_obj.states = [:RUNNING]
|
25
|
-
msg_obj.states.should =~ ["RUNNING"]
|
26
|
-
end
|
27
|
-
end
|
File without changes
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'schemata/health_manager'
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Schemata::HealthManager::HealthRequest do
|
5
|
-
it_behaves_like "a message type"
|
6
|
-
end
|
7
|
-
|
8
|
-
Schemata::HealthManager::HealthRequest.versions.each do |v|
|
9
|
-
describe Schemata::HealthManager::HealthRequest::const_get("V#{v}") do
|
10
|
-
it_behaves_like "a message"
|
11
|
-
end
|
12
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'schemata/health_manager'
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Schemata::HealthManager::HealthResponse do
|
5
|
-
it_behaves_like "a message type"
|
6
|
-
end
|
7
|
-
|
8
|
-
Schemata::HealthManager::HealthResponse.versions.each do |v|
|
9
|
-
describe Schemata::HealthManager::HealthResponse::const_get("V#{v}") do
|
10
|
-
it_behaves_like "a message"
|
11
|
-
end
|
12
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'schemata/health_manager'
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Schemata::HealthManager::StatusCrashedResponse do
|
5
|
-
it_behaves_like "a message type"
|
6
|
-
end
|
7
|
-
|
8
|
-
Schemata::HealthManager::StatusCrashedResponse.versions.each do |v|
|
9
|
-
describe Schemata::HealthManager::StatusCrashedResponse::const_get("V#{v}") do
|
10
|
-
it_behaves_like "a message"
|
11
|
-
end
|
12
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'schemata/health_manager'
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Schemata::HealthManager::StatusFlappingResponse do
|
5
|
-
it_behaves_like "a message type"
|
6
|
-
end
|
7
|
-
|
8
|
-
Schemata::HealthManager::StatusFlappingResponse.versions.each do |v|
|
9
|
-
describe Schemata::HealthManager::StatusFlappingResponse::const_get("V#{v}") do
|
10
|
-
it_behaves_like "a message"
|
11
|
-
end
|
12
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'schemata/health_manager'
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Schemata::HealthManager::StatusRequest do
|
5
|
-
it_behaves_like "a message type"
|
6
|
-
end
|
7
|
-
|
8
|
-
Schemata::HealthManager::StatusRequest.versions.each do |v|
|
9
|
-
describe Schemata::HealthManager::StatusRequest::const_get("V#{v}") do
|
10
|
-
it_behaves_like "a message"
|
11
|
-
end
|
12
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'schemata/staging'
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Schemata::Staging::Message do
|
5
|
-
it_behaves_like "a message type"
|
6
|
-
end
|
7
|
-
|
8
|
-
describe Schemata::Staging::Message::V1 do
|
9
|
-
it_behaves_like "a message"
|
10
|
-
end
|
11
|
-
|
12
|
-
describe Schemata::Staging::Message::V2 do
|
13
|
-
it_behaves_like "a message"
|
14
|
-
end
|