schemata-dea 0.0.1.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/schemata/common/error.rb +12 -0
- data/lib/schemata/common/msgbase.rb +281 -0
- data/lib/schemata/common/msgtypebase.rb +144 -0
- data/lib/schemata/common/parsed_msg.rb +43 -0
- data/lib/schemata/dea/advertise_message/advertise_message_v1.rb +40 -0
- data/lib/schemata/dea/advertise_message.rb +13 -0
- data/lib/schemata/dea/dea_status_response/dea_status_response_v1.rb +48 -0
- data/lib/schemata/dea/dea_status_response.rb +13 -0
- data/lib/schemata/dea/discover_request/discover_request_v1.rb +93 -0
- data/lib/schemata/dea/discover_request.rb +13 -0
- data/lib/schemata/dea/droplet_status_response/droplet_status_response_v1.rb +38 -0
- data/lib/schemata/dea/droplet_status_response.rb +13 -0
- data/lib/schemata/dea/exit_message/exit_message_v1.rb +48 -0
- data/lib/schemata/dea/exit_message.rb +13 -0
- data/lib/schemata/dea/find_droplet_request/find_droplet_request_v1.rb +52 -0
- data/lib/schemata/dea/find_droplet_request.rb +13 -0
- data/lib/schemata/dea/find_droplet_response/find_droplet_response_v1.rb +107 -0
- data/lib/schemata/dea/find_droplet_response.rb +13 -0
- data/lib/schemata/dea/heartbeat_response/heartbeat_response_v1.rb +58 -0
- data/lib/schemata/dea/heartbeat_response.rb +13 -0
- data/lib/schemata/dea/hello_message/hello_message_v1.rb +40 -0
- data/lib/schemata/dea/hello_message.rb +13 -0
- data/lib/schemata/dea/start_request/start_request_v1.rb +141 -0
- data/lib/schemata/dea/start_request.rb +13 -0
- data/lib/schemata/dea/stop_request/stop_request_v1.rb +39 -0
- data/lib/schemata/dea/stop_request.rb +13 -0
- data/lib/schemata/dea/update_request/update_request_v1.rb +33 -0
- data/lib/schemata/dea/update_request.rb +13 -0
- data/lib/schemata/dea/version.rb +5 -0
- data/lib/schemata/dea.rb +64 -0
- data/lib/schemata/helpers/hash_copy.rb +28 -0
- data/lib/schemata/helpers/stringify.rb +26 -0
- data/spec/cloud_controller/cc_bar_spec.rb +140 -0
- data/spec/common/helpers_spec.rb +115 -0
- data/spec/common/parsed_msg_spec.rb +46 -0
- data/spec/component/aux_data_spec.rb +37 -0
- data/spec/component/component_bar_spec.rb +140 -0
- data/spec/component/component_foo_spec.rb +630 -0
- data/spec/component/foo_spec.rb +214 -0
- data/spec/dea/advertise_message_spec.rb +10 -0
- data/spec/dea/dea_spec.rb +6 -0
- data/spec/dea/dea_status_response_spec.rb +10 -0
- data/spec/dea/discover_request_spec.rb +10 -0
- data/spec/dea/droplet_status_response_spec.rb +10 -0
- data/spec/dea/exit_message_spec.rb +10 -0
- data/spec/dea/find_droplet_request_spec.rb +27 -0
- data/spec/dea/find_droplet_response_spec.rb +10 -0
- data/spec/dea/heartbeat_response_spec.rb +10 -0
- data/spec/dea/hello_message_spec.rb +10 -0
- data/spec/dea/start_request_spec.rb +10 -0
- data/spec/dea/stop_request_spec.rb +10 -0
- data/spec/dea/update_request_spec.rb +0 -0
- data/spec/router/register_request_spec.rb +10 -0
- data/spec/router/router_spec.rb +6 -0
- data/spec/router/start_message_spec.rb +10 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/staging/staging_message_spec.rb +14 -0
- data/spec/staging/staging_spec.rb +6 -0
- data/spec/support/component_helpers.rb +51 -0
- data/spec/support/helpers.rb +54 -0
- data/spec/support/message_helpers.rb +138 -0
- data/spec/support/message_type_helpers.rb +171 -0
- metadata +234 -0
@@ -0,0 +1,171 @@
|
|
1
|
+
shared_examples "a message type" do
|
2
|
+
|
3
|
+
versions = described_class.constants.select {|x| x =~ /V[0-9]+/ }
|
4
|
+
.map {|x| x.to_s[1..-1].to_i}
|
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
|
+
describe ".decode" do
|
14
|
+
context "when the current version is 1" do
|
15
|
+
before :each do
|
16
|
+
set_current_version(message_type, 1)
|
17
|
+
end
|
18
|
+
|
19
|
+
after :each do
|
20
|
+
reset_version(message_type)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return a V1 object given a flat hash" do
|
24
|
+
data = component.send(mock_method, 1).contents
|
25
|
+
json = Yajl::Encoder.encode(data)
|
26
|
+
msg_obj = message_type.decode(json)
|
27
|
+
msg_obj.class.should == message_type::V1
|
28
|
+
|
29
|
+
message_type::V1.schema.schemas.keys do |key|
|
30
|
+
msg_obj.send(key).should == data[key]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return a V1 object given a V1-encoded json" do
|
35
|
+
data = component.send(mock_method, 1).contents
|
36
|
+
|
37
|
+
msg_hash = {"V1" => data, "min_version" => 1}
|
38
|
+
json = Yajl::Encoder.encode(msg_hash)
|
39
|
+
|
40
|
+
msg_obj = message_type.decode(json)
|
41
|
+
msg_obj.class.should == message_type::V1
|
42
|
+
|
43
|
+
message_type::V1.schema.schemas.keys do |key|
|
44
|
+
msg_obj.send(key).should == data[key]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return a V1 object given a mixed (V1-encoded + flat hash) json" do
|
49
|
+
data = component.send(mock_method, 1).contents
|
50
|
+
msg_hash = {
|
51
|
+
"V1" => data,
|
52
|
+
"min_version" => 1
|
53
|
+
}.merge(Schemata::HashCopyHelpers.deep_copy(data))
|
54
|
+
json = Yajl::Encoder.encode(msg_hash)
|
55
|
+
|
56
|
+
msg_obj = message_type.decode(json)
|
57
|
+
msg_obj.class.should == message_type::V1
|
58
|
+
|
59
|
+
message_type::V1.schema.schemas.keys do |key|
|
60
|
+
msg_obj.send(key).should == data[key]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should return a V1 object when given a V2-encoded json" do
|
65
|
+
v2_hash = component.send(mock_method, 1).contents
|
66
|
+
msg_hash = {
|
67
|
+
"V2" => v2_hash,
|
68
|
+
"V1" => {},
|
69
|
+
"min_version" => 1
|
70
|
+
}
|
71
|
+
json = Yajl::Encoder.encode(msg_hash)
|
72
|
+
|
73
|
+
msg_obj = message_type.decode(json)
|
74
|
+
msg_obj.class.should == message_type::V1
|
75
|
+
|
76
|
+
message_type::V1.schema.schemas.keys do |key|
|
77
|
+
msg_obj.send(key).should == data[key]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should raise an error if the input does not have the valid Schemata \
|
82
|
+
structure or a complete flash hash" do
|
83
|
+
mock_obj = component.send(mock_method, 1)
|
84
|
+
mock_hash = mock_obj.contents
|
85
|
+
|
86
|
+
if num_mandatory_fields(mock_obj) > 1
|
87
|
+
first_key = mock_hash.keys[0]
|
88
|
+
first_value = mock_hash[first_key]
|
89
|
+
|
90
|
+
json = Yajl::Encoder.encode({ first_key => first_value})
|
91
|
+
else
|
92
|
+
json = Yajl::Encoder.encode({})
|
93
|
+
end
|
94
|
+
expect {
|
95
|
+
msg_obj = message_type.decode(json)
|
96
|
+
}.to raise_error(Schemata::DecodeError)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
if versions.include?(2)
|
102
|
+
context "when current version is 2" do
|
103
|
+
before :each do
|
104
|
+
set_current_version(message_type, 2)
|
105
|
+
end
|
106
|
+
|
107
|
+
after :each do
|
108
|
+
reset_version(message_type)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should raise an error given a flat hash" do
|
112
|
+
data = component.send(mock_method, 2).contents
|
113
|
+
json = Yajl::Encoder.encode(data)
|
114
|
+
expect {
|
115
|
+
msg_obj = message_type.decode(json)
|
116
|
+
}.to raise_error(Schemata::DecodeError)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should return a V2 object a given a mixed (flat hash + V1-encoded) json" do
|
120
|
+
msg_hash = component.send(mock_method, 2).contents
|
121
|
+
v1_hash = Schemata::HashCopyHelpers.deep_copy(msg_hash)
|
122
|
+
msg_hash["V1"] = v1_hash
|
123
|
+
msg_hash["min_version"] = 1
|
124
|
+
|
125
|
+
json = Yajl::Encoder.encode(msg_hash)
|
126
|
+
|
127
|
+
msg_obj = message_type.decode(json)
|
128
|
+
msg_obj.class.should == message_type::V2
|
129
|
+
|
130
|
+
message_type::V2.schema.schemas.keys.each do |key|
|
131
|
+
msg_obj.send(key).should == v1_hash[key]
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should return a V2 object given a V1-encoded json" do
|
136
|
+
v1_hash = component.send(mock_method, 1).contents
|
137
|
+
msg_hash = {"V1" => v1_hash, 'min_version' => 1}
|
138
|
+
|
139
|
+
json = Yajl::Encoder.encode(msg_hash)
|
140
|
+
|
141
|
+
msg_obj = message_type.decode(json)
|
142
|
+
msg_obj.class.should == message_type::V2
|
143
|
+
|
144
|
+
message_type::V2.schema.schemas.keys.each do |key|
|
145
|
+
msg_obj.send(key).should == v1_hash[key]
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should return a V2 object given a V2-encoded object" do
|
150
|
+
data = component.send(mock_method, 2).contents
|
151
|
+
v2_hash = Schemata::HashCopyHelpers.deep_copy(data)
|
152
|
+
msg_hash = {"V2" => v2_hash, "V1" => {}, "min_version" => 1}
|
153
|
+
|
154
|
+
json = Yajl::Encoder.encode(msg_hash)
|
155
|
+
|
156
|
+
msg_obj = message_type.decode(json)
|
157
|
+
msg_obj.class.should == message_type::V2
|
158
|
+
|
159
|
+
message_type::V2.schema.schemas.keys.each do |key|
|
160
|
+
msg_obj.send(key).should == data[key]
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
# The first two versions have exceptional behavior, starting from
|
167
|
+
# version 3, all versions should have the same unit tests
|
168
|
+
versions.select { |x| x > 2 }.each do |version|
|
169
|
+
|
170
|
+
end
|
171
|
+
end
|
metadata
ADDED
@@ -0,0 +1,234 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: schemata-dea
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.beta1
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- dsabeti
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: membrane
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: yajl-ruby
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: vcap_common
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: ci_reporter
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rake
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rspec
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: ! " Specify schema for DEA messages and validate messages\n against
|
111
|
+
defined schema\n"
|
112
|
+
email:
|
113
|
+
- support@cloudfoundry.org
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- lib/schemata/dea/find_droplet_response.rb
|
119
|
+
- lib/schemata/dea/exit_message/exit_message_v1.rb
|
120
|
+
- lib/schemata/dea/droplet_status_response.rb
|
121
|
+
- lib/schemata/dea/find_droplet_request/find_droplet_request_v1.rb
|
122
|
+
- lib/schemata/dea/heartbeat_response.rb
|
123
|
+
- lib/schemata/dea/find_droplet_request.rb
|
124
|
+
- lib/schemata/dea/start_request/start_request_v1.rb
|
125
|
+
- lib/schemata/dea/hello_message.rb
|
126
|
+
- lib/schemata/dea/update_request/update_request_v1.rb
|
127
|
+
- lib/schemata/dea/dea_status_response.rb
|
128
|
+
- lib/schemata/dea/droplet_status_response/droplet_status_response_v1.rb
|
129
|
+
- lib/schemata/dea/discover_request/discover_request_v1.rb
|
130
|
+
- lib/schemata/dea/stop_request/stop_request_v1.rb
|
131
|
+
- lib/schemata/dea/advertise_message/advertise_message_v1.rb
|
132
|
+
- lib/schemata/dea/dea_status_response/dea_status_response_v1.rb
|
133
|
+
- lib/schemata/dea/hello_message/hello_message_v1.rb
|
134
|
+
- lib/schemata/dea/version.rb
|
135
|
+
- lib/schemata/dea/heartbeat_response/heartbeat_response_v1.rb
|
136
|
+
- lib/schemata/dea/stop_request.rb
|
137
|
+
- lib/schemata/dea/start_request.rb
|
138
|
+
- lib/schemata/dea/update_request.rb
|
139
|
+
- lib/schemata/dea/advertise_message.rb
|
140
|
+
- lib/schemata/dea/find_droplet_response/find_droplet_response_v1.rb
|
141
|
+
- lib/schemata/dea/discover_request.rb
|
142
|
+
- lib/schemata/dea/exit_message.rb
|
143
|
+
- lib/schemata/dea.rb
|
144
|
+
- lib/schemata/common/msgtypebase.rb
|
145
|
+
- lib/schemata/common/parsed_msg.rb
|
146
|
+
- lib/schemata/common/msgbase.rb
|
147
|
+
- lib/schemata/common/error.rb
|
148
|
+
- lib/schemata/helpers/stringify.rb
|
149
|
+
- lib/schemata/helpers/hash_copy.rb
|
150
|
+
- spec/cloud_controller/cc_bar_spec.rb
|
151
|
+
- spec/common/helpers_spec.rb
|
152
|
+
- spec/common/parsed_msg_spec.rb
|
153
|
+
- spec/component/aux_data_spec.rb
|
154
|
+
- spec/component/component_bar_spec.rb
|
155
|
+
- spec/component/component_foo_spec.rb
|
156
|
+
- spec/component/foo_spec.rb
|
157
|
+
- spec/dea/advertise_message_spec.rb
|
158
|
+
- spec/dea/dea_spec.rb
|
159
|
+
- spec/dea/dea_status_response_spec.rb
|
160
|
+
- spec/dea/discover_request_spec.rb
|
161
|
+
- spec/dea/droplet_status_response_spec.rb
|
162
|
+
- spec/dea/exit_message_spec.rb
|
163
|
+
- spec/dea/find_droplet_request_spec.rb
|
164
|
+
- spec/dea/find_droplet_response_spec.rb
|
165
|
+
- spec/dea/heartbeat_response_spec.rb
|
166
|
+
- spec/dea/hello_message_spec.rb
|
167
|
+
- spec/dea/start_request_spec.rb
|
168
|
+
- spec/dea/stop_request_spec.rb
|
169
|
+
- spec/dea/update_request_spec.rb
|
170
|
+
- spec/router/register_request_spec.rb
|
171
|
+
- spec/router/router_spec.rb
|
172
|
+
- spec/router/start_message_spec.rb
|
173
|
+
- spec/spec_helper.rb
|
174
|
+
- spec/staging/staging_message_spec.rb
|
175
|
+
- spec/staging/staging_spec.rb
|
176
|
+
- spec/support/component_helpers.rb
|
177
|
+
- spec/support/helpers.rb
|
178
|
+
- spec/support/message_helpers.rb
|
179
|
+
- spec/support/message_type_helpers.rb
|
180
|
+
homepage: http://www.cloudfoundry.org
|
181
|
+
licenses: []
|
182
|
+
post_install_message:
|
183
|
+
rdoc_options: []
|
184
|
+
require_paths:
|
185
|
+
- lib
|
186
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
187
|
+
none: false
|
188
|
+
requirements:
|
189
|
+
- - ! '>='
|
190
|
+
- !ruby/object:Gem::Version
|
191
|
+
version: '0'
|
192
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
193
|
+
none: false
|
194
|
+
requirements:
|
195
|
+
- - ! '>'
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
version: 1.3.1
|
198
|
+
requirements: []
|
199
|
+
rubyforge_project:
|
200
|
+
rubygems_version: 1.8.24
|
201
|
+
signing_key:
|
202
|
+
specification_version: 3
|
203
|
+
summary: validation for cloundfoundry DEA messages
|
204
|
+
test_files:
|
205
|
+
- spec/cloud_controller/cc_bar_spec.rb
|
206
|
+
- spec/common/helpers_spec.rb
|
207
|
+
- spec/common/parsed_msg_spec.rb
|
208
|
+
- spec/component/aux_data_spec.rb
|
209
|
+
- spec/component/component_bar_spec.rb
|
210
|
+
- spec/component/component_foo_spec.rb
|
211
|
+
- spec/component/foo_spec.rb
|
212
|
+
- spec/dea/advertise_message_spec.rb
|
213
|
+
- spec/dea/dea_spec.rb
|
214
|
+
- spec/dea/dea_status_response_spec.rb
|
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/router/register_request_spec.rb
|
226
|
+
- spec/router/router_spec.rb
|
227
|
+
- spec/router/start_message_spec.rb
|
228
|
+
- spec/spec_helper.rb
|
229
|
+
- spec/staging/staging_message_spec.rb
|
230
|
+
- spec/staging/staging_spec.rb
|
231
|
+
- spec/support/component_helpers.rb
|
232
|
+
- spec/support/helpers.rb
|
233
|
+
- spec/support/message_helpers.rb
|
234
|
+
- spec/support/message_type_helpers.rb
|