schemata-cloud_controller 0.0.1.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/lib/schemata/cloud_controller/droplet_updated_message/droplet_updated_message_v1.rb +35 -0
  2. data/lib/schemata/cloud_controller/droplet_updated_message.rb +13 -0
  3. data/lib/schemata/cloud_controller/hm_start_request/hm_start_request_v1.rb +41 -0
  4. data/lib/schemata/cloud_controller/hm_start_request.rb +13 -0
  5. data/lib/schemata/cloud_controller/hm_stop_request/hm_stop_request_v1.rb +39 -0
  6. data/lib/schemata/cloud_controller/hm_stop_request.rb +13 -0
  7. data/lib/schemata/cloud_controller/version.rb +5 -0
  8. data/lib/schemata/cloud_controller.rb +19 -0
  9. data/lib/schemata/common/error.rb +18 -0
  10. data/lib/schemata/common/msgbase.rb +282 -0
  11. data/lib/schemata/common/msgtypebase.rb +144 -0
  12. data/lib/schemata/common/parsed_msg.rb +43 -0
  13. data/lib/schemata/helpers/hash_copy.rb +28 -0
  14. data/lib/schemata/helpers/stringify.rb +26 -0
  15. data/spec/cloud_controller/cloud_controller_spec.rb +6 -0
  16. data/spec/cloud_controller/droplet_updated_message_spec.rb +10 -0
  17. data/spec/cloud_controller/hm_start_request_spec.rb +11 -0
  18. data/spec/cloud_controller/hm_stop_request_spec.rb +12 -0
  19. data/spec/common/helpers_spec.rb +115 -0
  20. data/spec/common/parsed_msg_spec.rb +46 -0
  21. data/spec/component/aux_data_spec.rb +37 -0
  22. data/spec/component/component_bar_spec.rb +140 -0
  23. data/spec/component/component_foo_spec.rb +630 -0
  24. data/spec/component/foo_spec.rb +214 -0
  25. data/spec/component2/component2_bar_spec.rb +140 -0
  26. data/spec/dea/advertise_message_spec.rb +10 -0
  27. data/spec/dea/dea_spec.rb +6 -0
  28. data/spec/dea/dea_status_response_spec.rb +10 -0
  29. data/spec/dea/discover_request_spec.rb +10 -0
  30. data/spec/dea/droplet_status_response_spec.rb +10 -0
  31. data/spec/dea/exit_message_spec.rb +10 -0
  32. data/spec/dea/find_droplet_request_spec.rb +27 -0
  33. data/spec/dea/find_droplet_response_spec.rb +10 -0
  34. data/spec/dea/heartbeat_response_spec.rb +10 -0
  35. data/spec/dea/hello_message_spec.rb +10 -0
  36. data/spec/dea/start_request_spec.rb +10 -0
  37. data/spec/dea/stop_request_spec.rb +10 -0
  38. data/spec/dea/update_request_spec.rb +0 -0
  39. data/spec/health_manager/health_manager_spec.rb +6 -0
  40. data/spec/health_manager/health_request_spec.rb +12 -0
  41. data/spec/health_manager/health_response_spec.rb +12 -0
  42. data/spec/health_manager/status_crashed_response_spec.rb +12 -0
  43. data/spec/health_manager/status_flapping_response_spec.rb +12 -0
  44. data/spec/health_manager/status_request_spec.rb +12 -0
  45. data/spec/router/register_request_spec.rb +10 -0
  46. data/spec/router/router_spec.rb +6 -0
  47. data/spec/router/start_message_spec.rb +10 -0
  48. data/spec/spec_helper.rb +1 -0
  49. data/spec/staging/staging_message_spec.rb +14 -0
  50. data/spec/staging/staging_spec.rb +6 -0
  51. data/spec/support/component_helpers.rb +51 -0
  52. data/spec/support/helpers.rb +102 -0
  53. data/spec/support/message_helpers.rb +135 -0
  54. data/spec/support/message_type_helpers.rb +171 -0
  55. metadata +220 -0
@@ -0,0 +1,26 @@
1
+ module Schemata
2
+ module HashCopyHelpers
3
+
4
+ def self.stringify(node)
5
+ case node
6
+ when String
7
+ return node
8
+ when Numeric, TrueClass, FalseClass
9
+ return node
10
+ when Hash
11
+ copy = {}
12
+ node.each { |k, v| copy[k.to_s] = stringify(v) }
13
+ return copy
14
+ when Array
15
+ return node.map { |v| stringify(v) }
16
+ when NilClass
17
+ return nil
18
+ when Symbol
19
+ return node.to_s
20
+ else
21
+ raise CopyError.new("Unexpected class: #{node.class}")
22
+ end
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,6 @@
1
+ require 'schemata/cloud_controller'
2
+ require 'spec_helper'
3
+
4
+ describe Schemata::CloudController do
5
+ it_behaves_like "a schemata component"
6
+ end
@@ -0,0 +1,10 @@
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
@@ -0,0 +1,11 @@
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
@@ -0,0 +1,12 @@
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
@@ -0,0 +1,115 @@
1
+ require 'schemata/helpers/hash_copy'
2
+ require 'schemata/helpers/stringify'
3
+
4
+ describe Schemata::HashCopyHelpers do
5
+ describe "#deep_copy" do
6
+ it "should deep copy nil" do
7
+ copy = Schemata::HashCopyHelpers.deep_copy(nil)
8
+ copy.should == nil
9
+ end
10
+
11
+ it "should deep copy a given string" do
12
+ original = "foo"
13
+ copy = Schemata::HashCopyHelpers.deep_copy(original)
14
+ copy.should be_instance_of String
15
+ copy.should == original
16
+ copy.object_id.should_not == original.object_id
17
+ end
18
+
19
+ it "should deep copy a given boolean" do
20
+ Schemata::HashCopyHelpers.deep_copy(true).
21
+ should be_an_instance_of TrueClass
22
+ Schemata::HashCopyHelpers.deep_copy(false).
23
+ should be_an_instance_of FalseClass
24
+ end
25
+
26
+ it "should deep copy a given numeric type" do
27
+ original = 0
28
+ copy = Schemata::HashCopyHelpers.deep_copy(original)
29
+ copy.should == original
30
+ copy.should be_an_instance_of Fixnum
31
+
32
+ # set original to be max fixnum + 1
33
+ original = 2**(0.size * 8 - 2)
34
+ copy = Schemata::HashCopyHelpers.deep_copy(original)
35
+ copy.should == original
36
+ copy.should be_an_instance_of Bignum
37
+
38
+ original = 0.0
39
+ copy = Schemata::HashCopyHelpers.deep_copy(original)
40
+ copy.should == original
41
+ copy.should be_an_instance_of Float
42
+ end
43
+
44
+ it "should deep copy a given hash" do
45
+ original = {"foo" => "bar"}
46
+ copy = Schemata::HashCopyHelpers.deep_copy(original)
47
+ copy.should be_instance_of Hash
48
+ copy.should == original
49
+
50
+ copy.object_id.should_not == original.object_id
51
+ copy["foo"].object_id.should_not == original["foo"].object_id
52
+ end
53
+
54
+ it "should deep copy a given array" do
55
+ original = [1, 2, "hello"]
56
+ copy = Schemata::HashCopyHelpers.deep_copy(original)
57
+ copy.should be_instance_of Array
58
+ copy.should == original
59
+
60
+ copy.object_id.should_not == original.object_id
61
+ # only check object_id of String object
62
+ copy[2].object_id.should_not == original[2].object_id
63
+ end
64
+
65
+ it "should deep copy nested types" do
66
+ original = {
67
+ "foo" => "bar",
68
+ "inner" => {
69
+ "hello" => "goodbye",
70
+ },
71
+ }
72
+ copy = Schemata::HashCopyHelpers.deep_copy(original)
73
+ copy.should be_instance_of Hash
74
+ copy.should == original
75
+
76
+ copy.object_id.should_not == original.object_id
77
+ copy["foo"].object_id.should_not == original["foo"].object_id
78
+ copy["inner"].object_id.should_not == original["inner"].object_id
79
+ copy["inner"]["hello"].object_id.
80
+ should_not == original["inner"]["hello"].object_id
81
+ end
82
+
83
+ it "should raise error for unknown type" do
84
+ klass = Class.new
85
+ expect do
86
+ Schemata::HashCopyHelpers.deep_copy(klass.new)
87
+ end.to raise_error(described_class::CopyError, /Unexpected class: /)
88
+ end
89
+ end
90
+
91
+ describe "#stringify" do
92
+ it "should stringify nil" do
93
+ str = Schemata::HashCopyHelpers.stringify(nil)
94
+ str.should == nil
95
+ end
96
+
97
+ it "should stringify a string" do
98
+ original = "foo"
99
+ str = Schemata::HashCopyHelpers.stringify(original)
100
+ str.should == "foo"
101
+ end
102
+
103
+ it "should stringify a symbol" do
104
+ original = :foo
105
+ str = Schemata::HashCopyHelpers.stringify(original)
106
+ str.should == "foo"
107
+ end
108
+
109
+ it "should stringify a hash" do
110
+ original = { "foo" => :foo }
111
+ str = Schemata::HashCopyHelpers.stringify(original)
112
+ str.should == { "foo" => "foo" }
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,46 @@
1
+ require 'schemata/common/parsed_msg'
2
+
3
+ describe Schemata::ParsedMessage do
4
+ describe "#new" do
5
+ it "should raise an error if 'min_version' is missing" do
6
+ json = '{
7
+ "V10" : { "foo" : "bar" }
8
+ }'
9
+ expect {
10
+ msg = Schemata::ParsedMessage.new(json)
11
+ }.to raise_error(Schemata::DecodeError)
12
+ end
13
+
14
+ it "should raise an error if there are non-Vxx hashes" do
15
+ json = '{
16
+ "min_version" : 10,
17
+ "foo" : "bar"
18
+ }'
19
+ expect {
20
+ msg = Schemata::ParsedMessage.new(json)
21
+ }.to raise_error(Schemata::DecodeError)
22
+ end
23
+
24
+ it "should raise an error if there are no Vxx hashes" do
25
+ json = '{
26
+ "min_version" : 10
27
+ }'
28
+ expect {
29
+ msg = Schemata::ParsedMessage.new(json)
30
+ }.to raise_error(Schemata::DecodeError)
31
+ end
32
+
33
+ it "should return a new Schemata::ParsedMessage if the hash is valid" do
34
+ json = '{
35
+ "min_version" : 10,
36
+ "V10" : { "foo" : "bar" },
37
+ "V11" : { "foo" : "bar"}
38
+ }'
39
+ msg = Schemata::ParsedMessage.new(json)
40
+ msg.min_version.should == 10
41
+ msg.version.should == 11
42
+ msg.contents["V10"]["foo"].should == "bar"
43
+ msg.contents["V11"]["foo"].should == "bar"
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,37 @@
1
+ require 'schemata/component/foo'
2
+
3
+ describe Schemata::Component::Foo::V14 do
4
+ describe "#new" do
5
+ it "should define accessors for aux schema fields" do
6
+ v14_obj = Schemata::Component::Foo::V14.new
7
+ v14_obj.aux_data.respond_to?(:foo4).should be_true
8
+ v14_obj.aux_data.respond_to?(:foo4=).should be_true
9
+ end
10
+ end
11
+
12
+ describe "#generate_old_fields" do
13
+ it "should emit correct fields if the object was constructed with aux_data" do
14
+ v14_hash = {
15
+ "foo1" => "hello",
16
+ "foo3" => [3]
17
+ }
18
+ aux_data = { "foo4" => "foo" }
19
+ v14_obj = Schemata::Component::Foo::V14.new(v14_hash, aux_data)
20
+ downverted, old_fields = v14_obj.generate_old_fields
21
+
22
+ old_fields.keys.should =~ ["foo4"]
23
+ old_fields["foo4"].should == "foo"
24
+ end
25
+
26
+ it "should raise an error if the object was constructed without aux_data" do
27
+ v14_hash = {
28
+ "foo1" => "hello",
29
+ "foo3" => [3]
30
+ }
31
+ v14_obj = Schemata::Component::Foo::V14.new(v14_hash)
32
+ expect {
33
+ v14_obj.generate_old_fields
34
+ }.to raise_error(Schemata::DecodeError)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,140 @@
1
+ require 'schemata/component/component'
2
+ require 'support/helpers'
3
+
4
+ describe Schemata::Component do
5
+ before :each do
6
+ @v10_msg = '{
7
+ "min_version": 10,
8
+ "V10": {
9
+ "bar1": "first",
10
+ "bar2": "second"
11
+ }
12
+ }'
13
+
14
+ @v11_msg = '{
15
+ "min_version": 10,
16
+ "V11": {
17
+ "bar1": 1,
18
+ "bar3": "third"
19
+ },
20
+ "V10": {
21
+ "bar1": "1",
22
+ "bar2": "second"
23
+ }
24
+ }'
25
+
26
+ @v10_hash = {
27
+ "bar1" => "1",
28
+ "bar2" => "second"
29
+ }
30
+
31
+ @v11_hash = {
32
+ "bar1" => 1,
33
+ "bar3" => "third"
34
+ }
35
+ end
36
+
37
+ describe "#decode" do
38
+ describe "(current version is 10)" do
39
+ before :each do
40
+ set_current_version(Schemata::Component::Bar, 10)
41
+ end
42
+
43
+ after :each do
44
+ reset_version(Schemata::Component::Bar)
45
+ end
46
+
47
+ it "should take a v10 msg and create a v10 obj" do
48
+ msg_obj = Schemata::Component::Bar.decode(@v10_msg)
49
+ msg_obj.bar1.should == "first"
50
+ msg_obj.bar2.should == "second"
51
+ end
52
+
53
+ it "should take a v11 msg and create a v10 obj" do
54
+ msg_obj = Schemata::Component::Bar.decode(@v11_msg)
55
+ msg_obj.bar1.should == "1"
56
+ msg_obj.bar2.should == "second"
57
+ end
58
+ end
59
+
60
+ describe "(current version is 11)" do
61
+ before :each do
62
+ set_current_version(Schemata::Component::Bar, 11)
63
+ end
64
+
65
+ after :each do
66
+ reset_version(Schemata::Component::Bar)
67
+ end
68
+
69
+ it "should take a v10 msg and create a v11 obj" do
70
+ msg_obj = Schemata::Component::Bar.decode(@v10_msg)
71
+ msg_obj.bar1.should == 5
72
+ msg_obj.bar3.should == "third"
73
+ end
74
+
75
+ it "should take a v11 msg and create a v11 obj" do
76
+ msg_obj = Schemata::Component::Bar.decode(@v11_msg)
77
+ msg_obj.bar1.should == 1
78
+ msg_obj.bar3.should == "third"
79
+ end
80
+ end
81
+ end
82
+
83
+ describe "#encode" do
84
+ describe "(current version is 10)" do
85
+ before :each do
86
+ set_current_version(Schemata::Component::Bar, 10)
87
+ end
88
+
89
+ after :each do
90
+ reset_version(Schemata::Component::Bar)
91
+ end
92
+
93
+ it "should take a v10 obj and encode a json msg" do
94
+ v10_obj = Schemata::Component::Bar::V10.new(@v10_hash)
95
+ json_msg = v10_obj.encode
96
+ returned_hash = Yajl::Parser.parse(json_msg)
97
+
98
+ returned_hash.keys.should =~ ['min_version', 'V10']
99
+ returned_hash['min_version'].should ==
100
+ @curr_class::MIN_VERSION_ALLOWED
101
+
102
+ v10 = returned_hash['V10']
103
+ v10.each do |k, v|
104
+ v10[k].should == @v10_hash[k]
105
+ end
106
+ end
107
+ end
108
+
109
+ describe "(current version is 11)" do
110
+ before :each do
111
+ set_current_version(Schemata::Component::Bar, 11)
112
+ end
113
+
114
+ it "should take a v11 obj and encode a json msg" do
115
+ aux_data = {"bar2" => "second" }
116
+ v11_obj = Schemata::Component::Bar::V11.new(@v11_hash, aux_data)
117
+ json_msg = v11_obj.encode
118
+ returned_hash = Yajl::Parser.parse(json_msg)
119
+
120
+ returned_hash.keys.should =~ ['min_version', 'V10', 'V11']
121
+ returned_hash['min_version'].should ==
122
+ @curr_class::MIN_VERSION_ALLOWED
123
+
124
+ v10 = returned_hash['V10']
125
+ v10.each do |k, v|
126
+ v10[k].should == @v10_hash[k]
127
+ end
128
+
129
+ v11 = returned_hash['V11']
130
+ v11.each do |k, v|
131
+ v11[k].should == @v11_hash[k]
132
+ end
133
+ end
134
+
135
+ after :each do
136
+ reset_version(Schemata::Component::Bar)
137
+ end
138
+ end
139
+ end
140
+ end