schemata-staging 0.0.1.1 → 0.0.3.beta2
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/error.rb +8 -2
- data/lib/schemata/common/msgbase.rb +35 -10
- data/lib/schemata/common/msgtypebase.rb +45 -3
- data/lib/schemata/common/parsed_msg.rb +1 -1
- data/lib/schemata/helpers/decamelize.rb +23 -0
- data/lib/schemata/helpers/hash_copy.rb +1 -1
- data/lib/schemata/helpers/stringify.rb +26 -0
- data/lib/schemata/staging/message/message_v1.rb +1 -1
- data/lib/schemata/staging/message/message_v2.rb +148 -0
- data/lib/schemata/staging/message.rb +0 -4
- data/lib/schemata/staging/version.rb +1 -1
- data/lib/schemata/staging.rb +2 -4
- data/spec/cloud_controller_spec.rb +6 -0
- data/spec/common/helpers_spec.rb +39 -13
- data/spec/{cloud_controller/cc_bar_spec.rb → component2/component2_bar_spec.rb} +16 -16
- data/spec/dea_spec.rb +6 -0
- data/spec/health_manager_spec.rb +6 -0
- data/spec/router_spec.rb +6 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/staging_spec.rb +6 -0
- data/spec/support/component_helpers.rb +65 -0
- data/spec/support/helpers.rb +55 -0
- data/spec/support/message_helpers.rb +151 -0
- data/spec/support/message_type_helpers.rb +175 -0
- metadata +34 -14
- data/spec/staging/staging_message_spec.rb +0 -186
@@ -1,7 +1,7 @@
|
|
1
|
-
require 'schemata/
|
1
|
+
require 'schemata/component2/component2'
|
2
2
|
require 'support/helpers'
|
3
3
|
|
4
|
-
describe Schemata::
|
4
|
+
describe Schemata::Component2 do
|
5
5
|
before :each do
|
6
6
|
@v10_msg = '{
|
7
7
|
"min_version": 10,
|
@@ -37,21 +37,21 @@ describe Schemata::CloudController do
|
|
37
37
|
describe "#decode" do
|
38
38
|
describe "(current version is 10)" do
|
39
39
|
before :each do
|
40
|
-
set_current_version(Schemata::
|
40
|
+
set_current_version(Schemata::Component2::Bar, 10)
|
41
41
|
end
|
42
42
|
|
43
43
|
after :each do
|
44
|
-
reset_version(Schemata::
|
44
|
+
reset_version(Schemata::Component2::Bar)
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should take a v10 msg and create a v10 obj" do
|
48
|
-
msg_obj = Schemata::
|
48
|
+
msg_obj = Schemata::Component2::Bar.decode(@v10_msg)
|
49
49
|
msg_obj.bar1.should == "first"
|
50
50
|
msg_obj.bar2.should == "second"
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should take a v11 msg and create a v10 obj" do
|
54
|
-
msg_obj = Schemata::
|
54
|
+
msg_obj = Schemata::Component2::Bar.decode(@v11_msg)
|
55
55
|
msg_obj.bar1.should == "1"
|
56
56
|
msg_obj.bar2.should == "second"
|
57
57
|
end
|
@@ -59,21 +59,21 @@ describe Schemata::CloudController do
|
|
59
59
|
|
60
60
|
describe "(current version is 11)" do
|
61
61
|
before :each do
|
62
|
-
set_current_version(Schemata::
|
62
|
+
set_current_version(Schemata::Component2::Bar, 11)
|
63
63
|
end
|
64
64
|
|
65
65
|
after :each do
|
66
|
-
reset_version(Schemata::
|
66
|
+
reset_version(Schemata::Component2::Bar)
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should take a v10 msg and create a v11 obj" do
|
70
|
-
msg_obj = Schemata::
|
70
|
+
msg_obj = Schemata::Component2::Bar.decode(@v10_msg)
|
71
71
|
msg_obj.bar1.should == 5
|
72
72
|
msg_obj.bar3.should == "third"
|
73
73
|
end
|
74
74
|
|
75
75
|
it "should take a v11 msg and create a v11 obj" do
|
76
|
-
msg_obj = Schemata::
|
76
|
+
msg_obj = Schemata::Component2::Bar.decode(@v11_msg)
|
77
77
|
msg_obj.bar1.should == 1
|
78
78
|
msg_obj.bar3.should == "third"
|
79
79
|
end
|
@@ -83,15 +83,15 @@ describe Schemata::CloudController do
|
|
83
83
|
describe "#encode" do
|
84
84
|
describe "(current version is 10)" do
|
85
85
|
before :each do
|
86
|
-
set_current_version(Schemata::
|
86
|
+
set_current_version(Schemata::Component2::Bar, 10)
|
87
87
|
end
|
88
88
|
|
89
89
|
after :each do
|
90
|
-
reset_version(Schemata::
|
90
|
+
reset_version(Schemata::Component2::Bar)
|
91
91
|
end
|
92
92
|
|
93
93
|
it "should take a v10 obj and encode a json msg" do
|
94
|
-
v10_obj = Schemata::
|
94
|
+
v10_obj = Schemata::Component2::Bar::V10.new(@v10_hash)
|
95
95
|
json_msg = v10_obj.encode
|
96
96
|
returned_hash = Yajl::Parser.parse(json_msg)
|
97
97
|
|
@@ -108,12 +108,12 @@ describe Schemata::CloudController do
|
|
108
108
|
|
109
109
|
describe "(current version is 11)" do
|
110
110
|
before :each do
|
111
|
-
set_current_version(Schemata::
|
111
|
+
set_current_version(Schemata::Component2::Bar, 11)
|
112
112
|
end
|
113
113
|
|
114
114
|
it "should take a v11 obj and encode a json msg" do
|
115
115
|
aux_data = {"bar2" => "second" }
|
116
|
-
v11_obj = Schemata::
|
116
|
+
v11_obj = Schemata::Component2::Bar::V11.new(@v11_hash, aux_data)
|
117
117
|
json_msg = v11_obj.encode
|
118
118
|
returned_hash = Yajl::Parser.parse(json_msg)
|
119
119
|
|
@@ -133,7 +133,7 @@ describe Schemata::CloudController do
|
|
133
133
|
end
|
134
134
|
|
135
135
|
after :each do
|
136
|
-
reset_version(Schemata::
|
136
|
+
reset_version(Schemata::Component2::Bar)
|
137
137
|
end
|
138
138
|
end
|
139
139
|
end
|
data/spec/dea_spec.rb
ADDED
data/spec/router_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Dir["./spec/support/**/*.rb"].sort.each { |f| require f }
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'support/helpers'
|
2
|
+
require 'schemata/helpers/decamelize'
|
3
|
+
|
4
|
+
shared_examples "a schemata component" do
|
5
|
+
|
6
|
+
described_class.constants.select { |x| x != :VERSION }.each do |msg_type|
|
7
|
+
describe ".mock_#{Schemata::Helpers.decamelize(msg_type.to_s)}" do
|
8
|
+
versions = described_class::const_get(msg_type).constants.select { |x| x =~ /V[0-9]+/ }
|
9
|
+
versions.map { |x| x = x.to_s[1..-1].to_i }.each do |version|
|
10
|
+
it_behaves_like "a mocking method", version do
|
11
|
+
let(:message_type) { described_class::const_get(msg_type) }
|
12
|
+
let(:message_type_name) { msg_type.to_s }
|
13
|
+
let(:component) { described_class }
|
14
|
+
let(:component_name) { component.name.split("::")[1] }
|
15
|
+
|
16
|
+
let(:mock_method) { "mock_#{Schemata::Helpers.decamelize(msg_type)}"}
|
17
|
+
end
|
18
|
+
end
|
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
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
shared_examples "a mocking method" do |version|
|
37
|
+
|
38
|
+
context "when current_version is #{version}" do
|
39
|
+
before :each do
|
40
|
+
set_current_version(message_type, version)
|
41
|
+
end
|
42
|
+
|
43
|
+
after :each do
|
44
|
+
reset_version(message_type)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should return a V#{version} object if called with no argument" do
|
48
|
+
msg_obj = component.send(mock_method)
|
49
|
+
msg_obj.class.should == message_type::const_get("V#{version}")
|
50
|
+
end
|
51
|
+
|
52
|
+
1.upto(version) do |i|
|
53
|
+
it "should return a V#{i} object if called with input #{i}" do
|
54
|
+
msg_obj = component.send(mock_method, i)
|
55
|
+
msg_obj.class.should == message_type::const_get("V#{i}")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should raise an error if called with input > #{version}" do
|
60
|
+
expect {
|
61
|
+
msg_obj = component.send(mock_method, version + 1)
|
62
|
+
}.to raise_error(NameError)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/spec/support/helpers.rb
CHANGED
@@ -25,3 +25,58 @@ def greater_version?(version, benchmark)
|
|
25
25
|
version = version[1..-1].to_i
|
26
26
|
version > benchmark
|
27
27
|
end
|
28
|
+
|
29
|
+
def num_mandatory_fields(msg_obj)
|
30
|
+
optional = msg_obj.class.schema.optional_keys
|
31
|
+
mandatory = Set.new(msg_obj.class.schema.schemas.keys)
|
32
|
+
diff = mandatory - optional
|
33
|
+
return diff.size
|
34
|
+
end
|
35
|
+
|
36
|
+
def all_classes
|
37
|
+
all_classes = Set.new([Integer, String, Float, TrueClass, FalseClass, NilClass, Hash, Array])
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_allowed_classes(schema)
|
41
|
+
case schema
|
42
|
+
when Membrane::Schema::Bool
|
43
|
+
return Set.new([TrueClass, FalseClass])
|
44
|
+
when Membrane::Schema::Enum
|
45
|
+
return Set.new(schema.elem_schemas.map {|x| get_allowed_classes(x)}).flatten
|
46
|
+
when Membrane::Schema::Class
|
47
|
+
return Set.new([schema.klass])
|
48
|
+
when Membrane::Schema::Record
|
49
|
+
return Set.new([Hash])
|
50
|
+
when Membrane::Schema::List
|
51
|
+
return Set.new([Array])
|
52
|
+
when Membrane::Schema::Value
|
53
|
+
return Set.new([schema.value.class])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def get_unallowed_classes(schema)
|
58
|
+
allowed_classes = get_allowed_classes(schema)
|
59
|
+
all_classes - allowed_classes
|
60
|
+
end
|
61
|
+
|
62
|
+
def default_value(klass)
|
63
|
+
# Yes this is silly
|
64
|
+
if klass == Integer
|
65
|
+
return 0
|
66
|
+
elsif klass == String
|
67
|
+
return "foo"
|
68
|
+
elsif klass == Float
|
69
|
+
return 3.14
|
70
|
+
elsif klass == TrueClass
|
71
|
+
return true
|
72
|
+
elsif klass == FalseClass
|
73
|
+
return false
|
74
|
+
elsif klass == NilClass
|
75
|
+
return nil
|
76
|
+
elsif klass == Hash
|
77
|
+
return {}
|
78
|
+
elsif klass == Array
|
79
|
+
return []
|
80
|
+
else
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
shared_examples "a message" do |msg|
|
2
|
+
version = msg.version
|
3
|
+
|
4
|
+
before :each do
|
5
|
+
set_current_version(message_type, version)
|
6
|
+
end
|
7
|
+
|
8
|
+
after :each do
|
9
|
+
reset_version(message_type)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#new" do
|
13
|
+
it "should create a #{msg} object with an incomplete hash" do
|
14
|
+
mock_hash = component.send(mock_method, 1).contents
|
15
|
+
first_key = mock_hash.keys[0]
|
16
|
+
first_value = mock_hash[first_key]
|
17
|
+
|
18
|
+
msg_obj = message.new({first_key => first_value})
|
19
|
+
msg_obj.class.should == message
|
20
|
+
msg_obj.send(first_key).should == first_value
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should raise an error if the hash contains incorrect types" do
|
24
|
+
mock_hash = component.send(mock_method, 1).contents
|
25
|
+
first_key = mock_hash.keys[0]
|
26
|
+
first_value = mock_hash[first_key]
|
27
|
+
|
28
|
+
schema = message.schema.schemas[first_key]
|
29
|
+
unallowed_classes = get_unallowed_classes(schema)
|
30
|
+
bad_value = default_value(unallowed_classes.to_a[0])
|
31
|
+
|
32
|
+
expect {
|
33
|
+
msg_obj = message.new({first_key => bad_value})
|
34
|
+
}.to raise_error(Schemata::UpdateAttributeError)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should stringify keys when they are symbols" do
|
38
|
+
mock_hash = component.send(mock_method, 1).contents
|
39
|
+
first_key = mock_hash.keys[0]
|
40
|
+
first_value = mock_hash[first_key]
|
41
|
+
|
42
|
+
input_hash = {
|
43
|
+
first_key.to_sym => first_value
|
44
|
+
}
|
45
|
+
msg_obj = message.new(input_hash)
|
46
|
+
msg_obj.send(first_key).should_not be_nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#encode" do
|
51
|
+
if version == 1
|
52
|
+
it "should return a Schemata-encoded json string, with a V1 hash also in the raw payload" do
|
53
|
+
msg_obj = component.send(mock_method, 1)
|
54
|
+
json = msg_obj.encode
|
55
|
+
json_hash = Yajl::Parser.parse(json)
|
56
|
+
|
57
|
+
json_hash.should have_key "V1"
|
58
|
+
json_hash.should have_key "min_version"
|
59
|
+
|
60
|
+
data = Schemata::Helpers.deep_copy(json_hash["V1"])
|
61
|
+
|
62
|
+
json_hash.delete("V1")
|
63
|
+
json_hash.delete("min_version")
|
64
|
+
|
65
|
+
json_hash.should == data
|
66
|
+
end
|
67
|
+
else
|
68
|
+
it "should return a Schemata-encoded json string, with no raw payload" do
|
69
|
+
msg_obj = component.send(mock_method, version)
|
70
|
+
json = msg_obj.encode
|
71
|
+
json_hash = Yajl::Parser.parse(json)
|
72
|
+
|
73
|
+
1.upto(version) do |i|
|
74
|
+
json_hash.should have_key "V#{i}"
|
75
|
+
end
|
76
|
+
json_hash.should have_key "min_version"
|
77
|
+
|
78
|
+
data = Schemata::Helpers.deep_copy(json_hash["V#{version}"])
|
79
|
+
1.upto(version) do |i|
|
80
|
+
json_hash.delete("V#{i}")
|
81
|
+
end
|
82
|
+
json_hash.delete("min_version")
|
83
|
+
|
84
|
+
json_hash.should be_empty
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
msg.schema.schemas.keys.each do |attr|
|
90
|
+
describe "##{attr}" do
|
91
|
+
it "should return the attribute if it was specified at instantiation" do
|
92
|
+
mock_value = component.send(mock_method, version).contents[attr]
|
93
|
+
msg_obj = message.new({ attr => mock_value })
|
94
|
+
msg_obj.send(attr).should == mock_value
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should return the attribute if it was set with an attr writer" do
|
98
|
+
mock_value = component.send(mock_method, version).contents[attr]
|
99
|
+
msg_obj = message.new
|
100
|
+
msg_obj.send("#{attr}=", mock_value)
|
101
|
+
msg_obj.send(attr).should == mock_value
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should return nil if the attribute was never set" do
|
105
|
+
msg_obj = message.new
|
106
|
+
msg_obj.send(attr).should be_nil
|
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
|
123
|
+
end
|
124
|
+
|
125
|
+
describe "##{attr}=" do
|
126
|
+
it "should change the attribute and return the new value" do
|
127
|
+
mock_value = component.send(mock_method, version).contents[attr]
|
128
|
+
msg_obj = message.new({ attr => mock_value })
|
129
|
+
ret = (msg_obj.send("#{attr}=", mock_value))
|
130
|
+
msg_obj.send(attr).should == mock_value
|
131
|
+
ret.should == mock_value
|
132
|
+
end
|
133
|
+
|
134
|
+
unless msg.schema.schemas[attr].kind_of? Membrane::Schema::Any
|
135
|
+
it "should raise an error if the wrong type is written" do
|
136
|
+
mock_value = component.send(mock_method, version).contents[attr]
|
137
|
+
|
138
|
+
schema = message.schema.schemas[attr]
|
139
|
+
unallowed_classes = get_unallowed_classes(schema)
|
140
|
+
bad_value = default_value(unallowed_classes.to_a[0])
|
141
|
+
|
142
|
+
msg_obj = message.new
|
143
|
+
|
144
|
+
expect {
|
145
|
+
msg_obj.send("#{attr}=", bad_value)
|
146
|
+
}.to raise_error(Schemata::UpdateAttributeError)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,175 @@
|
|
1
|
+
shared_examples "a message type" do |msg_type|
|
2
|
+
|
3
|
+
versions = msg_type.constants.select {|x| x =~ /V[0-9]+/ }
|
4
|
+
.map {|x| x.to_s[1..-1].to_i}
|
5
|
+
|
6
|
+
describe ".decode" do
|
7
|
+
context "when the current version is 1" do
|
8
|
+
before :each do
|
9
|
+
set_current_version(message_type, 1)
|
10
|
+
end
|
11
|
+
|
12
|
+
after :each do
|
13
|
+
reset_version(message_type)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return a V1 object given a flat hash" do
|
17
|
+
data = component.send(mock_method, 1).contents
|
18
|
+
json = Yajl::Encoder.encode(data)
|
19
|
+
msg_obj = message_type.decode(json)
|
20
|
+
msg_obj.class.should == message_type::V1
|
21
|
+
|
22
|
+
message_type::V1.schema.schemas.keys do |key|
|
23
|
+
msg_obj.send(key).should == data[key]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return a V1 object given a V1-encoded json" do
|
28
|
+
data = component.send(mock_method, 1).contents
|
29
|
+
|
30
|
+
msg_hash = {"V1" => data, "min_version" => 1}
|
31
|
+
json = Yajl::Encoder.encode(msg_hash)
|
32
|
+
|
33
|
+
msg_obj = message_type.decode(json)
|
34
|
+
msg_obj.class.should == message_type::V1
|
35
|
+
|
36
|
+
message_type::V1.schema.schemas.keys do |key|
|
37
|
+
msg_obj.send(key).should == data[key]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should return a V1 object given a mixed (V1-encoded + flat hash) json" do
|
42
|
+
data = component.send(mock_method, 1).contents
|
43
|
+
msg_hash = {
|
44
|
+
"V1" => data,
|
45
|
+
"min_version" => 1
|
46
|
+
}.merge(Schemata::Helpers.deep_copy(data))
|
47
|
+
json = Yajl::Encoder.encode(msg_hash)
|
48
|
+
|
49
|
+
msg_obj = message_type.decode(json)
|
50
|
+
msg_obj.class.should == message_type::V1
|
51
|
+
|
52
|
+
message_type::V1.schema.schemas.keys do |key|
|
53
|
+
msg_obj.send(key).should == data[key]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should return a V1 object when given a V2-encoded json" do
|
58
|
+
v2_hash = component.send(mock_method, 1).contents
|
59
|
+
msg_hash = {
|
60
|
+
"V2" => v2_hash,
|
61
|
+
"V1" => {},
|
62
|
+
"min_version" => 1
|
63
|
+
}
|
64
|
+
json = Yajl::Encoder.encode(msg_hash)
|
65
|
+
|
66
|
+
msg_obj = message_type.decode(json)
|
67
|
+
msg_obj.class.should == message_type::V1
|
68
|
+
|
69
|
+
message_type::V1.schema.schemas.keys do |key|
|
70
|
+
msg_obj.send(key).should == data[key]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should raise an error if the input does not have the valid Schemata \
|
75
|
+
structure or a complete flash hash" do
|
76
|
+
mock_obj = component.send(mock_method, 1)
|
77
|
+
mock_hash = mock_obj.contents
|
78
|
+
|
79
|
+
if num_mandatory_fields(mock_obj) > 1
|
80
|
+
first_key = mock_hash.keys[0]
|
81
|
+
first_value = mock_hash[first_key]
|
82
|
+
|
83
|
+
json = Yajl::Encoder.encode({ first_key => first_value})
|
84
|
+
else
|
85
|
+
json = Yajl::Encoder.encode({})
|
86
|
+
end
|
87
|
+
expect {
|
88
|
+
msg_obj = message_type.decode(json)
|
89
|
+
}.to raise_error(Schemata::DecodeError)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
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
|
98
|
+
|
99
|
+
after :each do
|
100
|
+
reset_version(message_type)
|
101
|
+
end
|
102
|
+
|
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
|
110
|
+
|
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
|
116
|
+
|
117
|
+
json = Yajl::Encoder.encode(msg_hash)
|
118
|
+
|
119
|
+
msg_obj = message_type.decode(json)
|
120
|
+
msg_obj.class.should == message_type::V2
|
121
|
+
|
122
|
+
message_type::V2.schema.schemas.keys.each do |key|
|
123
|
+
msg_obj.send(key).should == v1_hash[key]
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
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}
|
130
|
+
|
131
|
+
json = Yajl::Encoder.encode(msg_hash)
|
132
|
+
|
133
|
+
msg_obj = message_type.decode(json)
|
134
|
+
msg_obj.class.should == message_type::V2
|
135
|
+
|
136
|
+
message_type::V2.schema.schemas.keys.each do |key|
|
137
|
+
msg_obj.send(key).should == v1_hash[key]
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
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}
|
145
|
+
|
146
|
+
json = Yajl::Encoder.encode(msg_hash)
|
147
|
+
|
148
|
+
msg_obj = message_type.decode(json)
|
149
|
+
msg_obj.class.should == message_type::V2
|
150
|
+
|
151
|
+
message_type::V2.schema.schemas.keys.each do |key|
|
152
|
+
msg_obj.send(key).should == data[key]
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# The first two versions have exceptional behavior, starting from
|
160
|
+
# version 3, all versions should have the same unit tests
|
161
|
+
versions.select { |x| x > 2 }.each do |version|
|
162
|
+
|
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
|
175
|
+
end
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schemata-staging
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.3.beta2
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- dsabeti
|
@@ -99,24 +99,36 @@ executables: []
|
|
99
99
|
extensions: []
|
100
100
|
extra_rdoc_files: []
|
101
101
|
files:
|
102
|
-
- lib/schemata/
|
103
|
-
- lib/schemata/
|
104
|
-
- lib/schemata/
|
102
|
+
- lib/schemata/common/componentbase.rb
|
103
|
+
- lib/schemata/common/error.rb
|
104
|
+
- lib/schemata/common/msgbase.rb
|
105
105
|
- lib/schemata/common/msgtypebase.rb
|
106
106
|
- lib/schemata/common/parsed_msg.rb
|
107
|
-
- lib/schemata/
|
108
|
-
- lib/schemata/common/error.rb
|
109
|
-
- lib/schemata/staging.rb
|
107
|
+
- lib/schemata/helpers/decamelize.rb
|
110
108
|
- lib/schemata/helpers/hash_copy.rb
|
111
|
-
-
|
109
|
+
- lib/schemata/helpers/stringify.rb
|
110
|
+
- lib/schemata/staging/message/message_v1.rb
|
111
|
+
- lib/schemata/staging/message/message_v2.rb
|
112
|
+
- lib/schemata/staging/message.rb
|
113
|
+
- lib/schemata/staging/version.rb
|
114
|
+
- lib/schemata/staging.rb
|
115
|
+
- spec/cloud_controller_spec.rb
|
112
116
|
- spec/common/helpers_spec.rb
|
113
117
|
- spec/common/parsed_msg_spec.rb
|
114
118
|
- spec/component/aux_data_spec.rb
|
115
119
|
- spec/component/component_bar_spec.rb
|
116
120
|
- spec/component/component_foo_spec.rb
|
117
121
|
- spec/component/foo_spec.rb
|
118
|
-
- spec/
|
122
|
+
- spec/component2/component2_bar_spec.rb
|
123
|
+
- spec/dea_spec.rb
|
124
|
+
- spec/health_manager_spec.rb
|
125
|
+
- spec/router_spec.rb
|
126
|
+
- spec/spec_helper.rb
|
127
|
+
- spec/staging_spec.rb
|
128
|
+
- spec/support/component_helpers.rb
|
119
129
|
- spec/support/helpers.rb
|
130
|
+
- spec/support/message_helpers.rb
|
131
|
+
- spec/support/message_type_helpers.rb
|
120
132
|
homepage: http://www.cloudfoundry.org
|
121
133
|
licenses: []
|
122
134
|
post_install_message:
|
@@ -132,9 +144,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
132
144
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
145
|
none: false
|
134
146
|
requirements:
|
135
|
-
- - ! '
|
147
|
+
- - ! '>'
|
136
148
|
- !ruby/object:Gem::Version
|
137
|
-
version:
|
149
|
+
version: 1.3.1
|
138
150
|
requirements: []
|
139
151
|
rubyforge_project:
|
140
152
|
rubygems_version: 1.8.24
|
@@ -142,12 +154,20 @@ signing_key:
|
|
142
154
|
specification_version: 3
|
143
155
|
summary: validation for cloundfoundry stager messages
|
144
156
|
test_files:
|
145
|
-
- spec/
|
157
|
+
- spec/cloud_controller_spec.rb
|
146
158
|
- spec/common/helpers_spec.rb
|
147
159
|
- spec/common/parsed_msg_spec.rb
|
148
160
|
- spec/component/aux_data_spec.rb
|
149
161
|
- spec/component/component_bar_spec.rb
|
150
162
|
- spec/component/component_foo_spec.rb
|
151
163
|
- spec/component/foo_spec.rb
|
152
|
-
- spec/
|
164
|
+
- spec/component2/component2_bar_spec.rb
|
165
|
+
- spec/dea_spec.rb
|
166
|
+
- spec/health_manager_spec.rb
|
167
|
+
- spec/router_spec.rb
|
168
|
+
- spec/spec_helper.rb
|
169
|
+
- spec/staging_spec.rb
|
170
|
+
- spec/support/component_helpers.rb
|
153
171
|
- spec/support/helpers.rb
|
172
|
+
- spec/support/message_helpers.rb
|
173
|
+
- spec/support/message_type_helpers.rb
|