schemata-cloud_controller 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.
Files changed (48) hide show
  1. data/lib/schemata/cloud_controller.rb +2 -14
  2. data/lib/schemata/cloud_controller/bulk_credentials_response.rb +9 -0
  3. data/lib/schemata/cloud_controller/bulk_credentials_response/bulk_credentials_response_v1.rb +33 -0
  4. data/lib/schemata/cloud_controller/droplet_updated_message.rb +0 -4
  5. data/lib/schemata/cloud_controller/hm_start_request.rb +0 -4
  6. data/lib/schemata/cloud_controller/hm_stop_request.rb +0 -4
  7. data/lib/schemata/cloud_controller/version.rb +1 -1
  8. data/lib/schemata/common/componentbase.rb +42 -0
  9. data/lib/schemata/common/msgbase.rb +13 -11
  10. data/lib/schemata/common/msgtypebase.rb +20 -0
  11. data/lib/schemata/common/parsed_msg.rb +1 -1
  12. data/lib/schemata/helpers/decamelize.rb +23 -0
  13. data/lib/schemata/helpers/hash_copy.rb +1 -1
  14. data/lib/schemata/helpers/stringify.rb +1 -1
  15. data/spec/{cloud_controller/cloud_controller_spec.rb → cloud_controller_spec.rb} +0 -0
  16. data/spec/common/helpers_spec.rb +16 -16
  17. data/spec/{dea/dea_spec.rb → dea_spec.rb} +1 -1
  18. data/spec/{health_manager/health_manager_spec.rb → health_manager_spec.rb} +0 -0
  19. data/spec/{router/router_spec.rb → router_spec.rb} +0 -0
  20. data/spec/{staging/staging_spec.rb → staging_spec.rb} +0 -0
  21. data/spec/support/component_helpers.rb +16 -2
  22. data/spec/support/helpers.rb +0 -20
  23. data/spec/support/message_helpers.rb +23 -19
  24. data/spec/support/message_type_helpers.rb +59 -55
  25. metadata +25 -67
  26. data/spec/cloud_controller/droplet_updated_message_spec.rb +0 -10
  27. data/spec/cloud_controller/hm_start_request_spec.rb +0 -11
  28. data/spec/cloud_controller/hm_stop_request_spec.rb +0 -12
  29. data/spec/dea/advertise_message_spec.rb +0 -10
  30. data/spec/dea/dea_status_response_spec.rb +0 -10
  31. data/spec/dea/discover_request_spec.rb +0 -10
  32. data/spec/dea/droplet_status_response_spec.rb +0 -10
  33. data/spec/dea/exit_message_spec.rb +0 -10
  34. data/spec/dea/find_droplet_request_spec.rb +0 -27
  35. data/spec/dea/find_droplet_response_spec.rb +0 -10
  36. data/spec/dea/heartbeat_response_spec.rb +0 -10
  37. data/spec/dea/hello_message_spec.rb +0 -10
  38. data/spec/dea/start_request_spec.rb +0 -10
  39. data/spec/dea/stop_request_spec.rb +0 -10
  40. data/spec/dea/update_request_spec.rb +0 -0
  41. data/spec/health_manager/health_request_spec.rb +0 -12
  42. data/spec/health_manager/health_response_spec.rb +0 -12
  43. data/spec/health_manager/status_crashed_response_spec.rb +0 -12
  44. data/spec/health_manager/status_flapping_response_spec.rb +0 -12
  45. data/spec/health_manager/status_request_spec.rb +0 -12
  46. data/spec/router/register_request_spec.rb +0 -10
  47. data/spec/router/start_message_spec.rb +0 -10
  48. data/spec/staging/staging_message_spec.rb +0 -14
@@ -1,19 +1,7 @@
1
- require 'schemata/cloud_controller/droplet_updated_message'
2
- require 'schemata/cloud_controller/hm_start_request'
3
- require 'schemata/cloud_controller/hm_stop_request'
1
+ require 'schemata/common/componentbase'
4
2
 
5
3
  module Schemata
6
4
  module CloudController
7
- def self.mock_droplet_updated_message(version=DropletUpdatedMessage.current_version)
8
- DropletUpdatedMessage::const_get("V#{version}").mock
9
- end
10
-
11
- def self.mock_hm_start_request(version=HmStartRequest.current_version)
12
- HmStartRequest::const_get("V#{version}").mock
13
- end
14
-
15
- def self.mock_hm_stop_request(version=HmStopRequest.current_version)
16
- HmStopRequest::const_get("V#{version}").mock
17
- end
5
+ extend Schemata::ComponentBase
18
6
  end
19
7
  end
@@ -0,0 +1,9 @@
1
+ require 'schemata/common/msgtypebase'
2
+
3
+ module Schemata
4
+ module CloudController
5
+ module BulkCredentialsResponse
6
+ extend Schemata::MessageTypeBase
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,33 @@
1
+ module Schemata
2
+ module CloudController
3
+ module BulkCredentialsResponse
4
+ version 1 do
5
+ include_preschemata
6
+
7
+ define_schema do
8
+ {
9
+ "user" => String,
10
+ "password" => String,
11
+ }
12
+ end
13
+
14
+ define_min_version 1
15
+
16
+ define_upvert do |old_data|
17
+ raise NotImplementedError.new
18
+ end
19
+
20
+ define_generate_old_fields do |msg_obj|
21
+ raise NotImplementedError.new
22
+ end
23
+
24
+ define_mock_values do
25
+ {
26
+ "user" => "sre@vmware.com",
27
+ "password" => "the_admin_pw"
28
+ }
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -7,7 +7,3 @@ module Schemata
7
7
  end
8
8
  end
9
9
  end
10
-
11
- Dir[File.dirname(__FILE__) + '/droplet_updated_message/*.rb'].each do |file|
12
- require file
13
- end
@@ -7,7 +7,3 @@ module Schemata
7
7
  end
8
8
  end
9
9
  end
10
-
11
- Dir[File.dirname(__FILE__) + '/hm_start_request/*.rb'].each do |file|
12
- require file
13
- end
@@ -7,7 +7,3 @@ module Schemata
7
7
  end
8
8
  end
9
9
  end
10
-
11
- Dir[File.dirname(__FILE__) + '/hm_stop_request/*.rb'].each do |file|
12
- require file
13
- end
@@ -1,5 +1,5 @@
1
1
  module Schemata
2
2
  module CloudController
3
- VERSION = "0.0.1.beta5"
3
+ VERSION = "0.0.1.beta6"
4
4
  end
5
5
  end
@@ -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::HashCopyHelpers.stringify(key)
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::HashCopyHelpers.stringify(field_value)
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::HashCopyHelpers.deep_copy(field_value)
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::HashCopyHelpers.deep_copy(@contents[key])
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::HashCopyHelpers.stringify(field_value)
57
- begin
58
- field_schema.validate(field_value)
59
- rescue Membrane::SchemaValidationError => e
60
- raise Schemata::UpdateAttributeError.new(key, e.message)
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::HashCopyHelpers.deep_copy(field_value)
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::HashCopyHelpers.deep_copy(@contents)
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
@@ -37,7 +37,7 @@ module Schemata
37
37
  end
38
38
 
39
39
  def contents
40
- Schemata::HashCopyHelpers.deep_copy(@contents)
40
+ Schemata::Helpers.deep_copy(@contents)
41
41
  end
42
42
  end
43
43
  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
@@ -1,5 +1,5 @@
1
1
  module Schemata
2
- module HashCopyHelpers
2
+ module Helpers
3
3
  class CopyError < StandardError; end
4
4
 
5
5
  def self.deep_copy(node)
@@ -1,5 +1,5 @@
1
1
  module Schemata
2
- module HashCopyHelpers
2
+ module Helpers
3
3
 
4
4
  def self.stringify(node)
5
5
  case node
@@ -1,49 +1,49 @@
1
1
  require 'schemata/helpers/hash_copy'
2
2
  require 'schemata/helpers/stringify'
3
3
 
4
- describe Schemata::HashCopyHelpers do
4
+ describe Schemata::Helpers do
5
5
  describe "#deep_copy" do
6
6
  it "should deep copy nil" do
7
- copy = Schemata::HashCopyHelpers.deep_copy(nil)
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::HashCopyHelpers.deep_copy(original)
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::HashCopyHelpers.deep_copy(true).
20
+ Schemata::Helpers.deep_copy(true).
21
21
  should be_an_instance_of TrueClass
22
- Schemata::HashCopyHelpers.deep_copy(false).
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::HashCopyHelpers.deep_copy(original)
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::HashCopyHelpers.deep_copy(original)
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::HashCopyHelpers.deep_copy(original)
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::HashCopyHelpers.deep_copy(original)
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::HashCopyHelpers.deep_copy(original)
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::HashCopyHelpers.deep_copy(original)
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::HashCopyHelpers.deep_copy(klass.new)
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::HashCopyHelpers.stringify(nil)
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::HashCopyHelpers.stringify(original)
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::HashCopyHelpers.stringify(original)
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::HashCopyHelpers.stringify(original)
111
+ str = Schemata::Helpers.stringify(original)
112
112
  str.should == { "foo" => "foo" }
113
113
  end
114
114
  end
@@ -1,6 +1,6 @@
1
1
  require 'schemata/dea'
2
2
  require 'spec_helper'
3
3
 
4
- describe Schemata::DEA do
4
+ describe Schemata::Dea do
5
5
  it_behaves_like "a schemata component"
6
6
  end
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|
@@ -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 #{described_class} object with an incomplete hash" do
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::HashCopyHelpers.deep_copy(json_hash["V1"])
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::HashCopyHelpers.deep_copy(json_hash["V#{version}"])
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
- described_class.schema.schemas.keys.each do |attr|
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 described_class.schema.schemas[attr].kind_of? Membrane::Schema::Any
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 = described_class.constants.select {|x| x =~ /V[0-9]+/ }
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::HashCopyHelpers.deep_copy(data))
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
- 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
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
- after :each do
108
- reset_version(message_type)
109
- end
99
+ after :each do
100
+ reset_version(message_type)
101
+ end
110
102
 
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
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
- 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
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
- json = Yajl::Encoder.encode(msg_hash)
117
+ json = Yajl::Encoder.encode(msg_hash)
126
118
 
127
- msg_obj = message_type.decode(json)
128
- msg_obj.class.should == message_type::V2
119
+ msg_obj = message_type.decode(json)
120
+ msg_obj.class.should == message_type::V2
129
121
 
130
- message_type::V2.schema.schemas.keys.each do |key|
131
- msg_obj.send(key).should == v1_hash[key]
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
- 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}
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
- json = Yajl::Encoder.encode(msg_hash)
131
+ json = Yajl::Encoder.encode(msg_hash)
140
132
 
141
- msg_obj = message_type.decode(json)
142
- msg_obj.class.should == message_type::V2
133
+ msg_obj = message_type.decode(json)
134
+ msg_obj.class.should == message_type::V2
143
135
 
144
- message_type::V2.schema.schemas.keys.each do |key|
145
- msg_obj.send(key).should == v1_hash[key]
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
- 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}
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
- json = Yajl::Encoder.encode(msg_hash)
146
+ json = Yajl::Encoder.encode(msg_hash)
155
147
 
156
- msg_obj = message_type.decode(json)
157
- msg_obj.class.should == message_type::V2
148
+ msg_obj = message_type.decode(json)
149
+ msg_obj.class.should == message_type::V2
158
150
 
159
- message_type::V2.schema.schemas.keys.each do |key|
160
- msg_obj.send(key).should == data[key]
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-cloud_controller
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.beta5
4
+ version: 0.0.1.beta6
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -99,24 +99,25 @@ executables: []
99
99
  extensions: []
100
100
  extra_rdoc_files: []
101
101
  files:
102
- - lib/schemata/cloud_controller.rb
103
- - lib/schemata/common/msgtypebase.rb
104
- - lib/schemata/common/parsed_msg.rb
105
- - lib/schemata/common/msgbase.rb
106
- - lib/schemata/common/error.rb
102
+ - lib/schemata/cloud_controller/bulk_credentials_response/bulk_credentials_response_v1.rb
103
+ - lib/schemata/cloud_controller/bulk_credentials_response.rb
104
+ - lib/schemata/cloud_controller/droplet_updated_message/droplet_updated_message_v1.rb
105
+ - lib/schemata/cloud_controller/droplet_updated_message.rb
106
+ - lib/schemata/cloud_controller/hm_start_request/hm_start_request_v1.rb
107
107
  - lib/schemata/cloud_controller/hm_start_request.rb
108
- - lib/schemata/cloud_controller/version.rb
109
108
  - lib/schemata/cloud_controller/hm_stop_request/hm_stop_request_v1.rb
110
- - lib/schemata/cloud_controller/hm_start_request/hm_start_request_v1.rb
111
109
  - lib/schemata/cloud_controller/hm_stop_request.rb
112
- - lib/schemata/cloud_controller/droplet_updated_message/droplet_updated_message_v1.rb
113
- - lib/schemata/cloud_controller/droplet_updated_message.rb
114
- - lib/schemata/helpers/stringify.rb
110
+ - lib/schemata/cloud_controller/version.rb
111
+ - lib/schemata/cloud_controller.rb
112
+ - lib/schemata/common/componentbase.rb
113
+ - lib/schemata/common/error.rb
114
+ - lib/schemata/common/msgbase.rb
115
+ - lib/schemata/common/msgtypebase.rb
116
+ - lib/schemata/common/parsed_msg.rb
117
+ - lib/schemata/helpers/decamelize.rb
115
118
  - lib/schemata/helpers/hash_copy.rb
116
- - spec/cloud_controller/cloud_controller_spec.rb
117
- - spec/cloud_controller/droplet_updated_message_spec.rb
118
- - spec/cloud_controller/hm_start_request_spec.rb
119
- - spec/cloud_controller/hm_stop_request_spec.rb
119
+ - lib/schemata/helpers/stringify.rb
120
+ - spec/cloud_controller_spec.rb
120
121
  - spec/common/helpers_spec.rb
121
122
  - spec/common/parsed_msg_spec.rb
122
123
  - spec/component/aux_data_spec.rb
@@ -124,31 +125,11 @@ files:
124
125
  - spec/component/component_foo_spec.rb
125
126
  - spec/component/foo_spec.rb
126
127
  - spec/component2/component2_bar_spec.rb
127
- - spec/dea/advertise_message_spec.rb
128
- - spec/dea/dea_spec.rb
129
- - spec/dea/dea_status_response_spec.rb
130
- - spec/dea/discover_request_spec.rb
131
- - spec/dea/droplet_status_response_spec.rb
132
- - spec/dea/exit_message_spec.rb
133
- - spec/dea/find_droplet_request_spec.rb
134
- - spec/dea/find_droplet_response_spec.rb
135
- - spec/dea/heartbeat_response_spec.rb
136
- - spec/dea/hello_message_spec.rb
137
- - spec/dea/start_request_spec.rb
138
- - spec/dea/stop_request_spec.rb
139
- - spec/dea/update_request_spec.rb
140
- - spec/health_manager/health_manager_spec.rb
141
- - spec/health_manager/health_request_spec.rb
142
- - spec/health_manager/health_response_spec.rb
143
- - spec/health_manager/status_crashed_response_spec.rb
144
- - spec/health_manager/status_flapping_response_spec.rb
145
- - spec/health_manager/status_request_spec.rb
146
- - spec/router/register_request_spec.rb
147
- - spec/router/router_spec.rb
148
- - spec/router/start_message_spec.rb
128
+ - spec/dea_spec.rb
129
+ - spec/health_manager_spec.rb
130
+ - spec/router_spec.rb
149
131
  - spec/spec_helper.rb
150
- - spec/staging/staging_message_spec.rb
151
- - spec/staging/staging_spec.rb
132
+ - spec/staging_spec.rb
152
133
  - spec/support/component_helpers.rb
153
134
  - spec/support/helpers.rb
154
135
  - spec/support/message_helpers.rb
@@ -178,10 +159,7 @@ signing_key:
178
159
  specification_version: 3
179
160
  summary: validation for cloundfoundry cloud controller messages
180
161
  test_files:
181
- - spec/cloud_controller/cloud_controller_spec.rb
182
- - spec/cloud_controller/droplet_updated_message_spec.rb
183
- - spec/cloud_controller/hm_start_request_spec.rb
184
- - spec/cloud_controller/hm_stop_request_spec.rb
162
+ - spec/cloud_controller_spec.rb
185
163
  - spec/common/helpers_spec.rb
186
164
  - spec/common/parsed_msg_spec.rb
187
165
  - spec/component/aux_data_spec.rb
@@ -189,31 +167,11 @@ test_files:
189
167
  - spec/component/component_foo_spec.rb
190
168
  - spec/component/foo_spec.rb
191
169
  - spec/component2/component2_bar_spec.rb
192
- - spec/dea/advertise_message_spec.rb
193
- - spec/dea/dea_spec.rb
194
- - spec/dea/dea_status_response_spec.rb
195
- - spec/dea/discover_request_spec.rb
196
- - spec/dea/droplet_status_response_spec.rb
197
- - spec/dea/exit_message_spec.rb
198
- - spec/dea/find_droplet_request_spec.rb
199
- - spec/dea/find_droplet_response_spec.rb
200
- - spec/dea/heartbeat_response_spec.rb
201
- - spec/dea/hello_message_spec.rb
202
- - spec/dea/start_request_spec.rb
203
- - spec/dea/stop_request_spec.rb
204
- - spec/dea/update_request_spec.rb
205
- - spec/health_manager/health_manager_spec.rb
206
- - spec/health_manager/health_request_spec.rb
207
- - spec/health_manager/health_response_spec.rb
208
- - spec/health_manager/status_crashed_response_spec.rb
209
- - spec/health_manager/status_flapping_response_spec.rb
210
- - spec/health_manager/status_request_spec.rb
211
- - spec/router/register_request_spec.rb
212
- - spec/router/router_spec.rb
213
- - spec/router/start_message_spec.rb
170
+ - spec/dea_spec.rb
171
+ - spec/health_manager_spec.rb
172
+ - spec/router_spec.rb
214
173
  - spec/spec_helper.rb
215
- - spec/staging/staging_message_spec.rb
216
- - spec/staging/staging_spec.rb
174
+ - spec/staging_spec.rb
217
175
  - spec/support/component_helpers.rb
218
176
  - spec/support/helpers.rb
219
177
  - 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,10 +0,0 @@
1
- require 'schemata/dea'
2
- require 'spec_helper'
3
-
4
- describe Schemata::DEA::AdvertiseMessage do
5
- it_behaves_like "a message type"
6
- end
7
-
8
- describe Schemata::DEA::AdvertiseMessage::V1 do
9
- it_behaves_like "a message"
10
- end
@@ -1,10 +0,0 @@
1
- require 'schemata/dea'
2
- require 'spec_helper'
3
-
4
- describe Schemata::DEA::DropletStatusResponse do
5
- it_behaves_like "a message type"
6
- end
7
-
8
- describe Schemata::DEA::DropletStatusResponse::V1 do
9
- it_behaves_like "a message"
10
- end
@@ -1,10 +0,0 @@
1
- require 'schemata/dea'
2
- require 'spec_helper'
3
-
4
- describe Schemata::DEA::DiscoverRequest do
5
- it_behaves_like "a message type"
6
- end
7
-
8
- describe Schemata::DEA::DiscoverRequest::V1 do
9
- it_behaves_like "a message"
10
- end
@@ -1,10 +0,0 @@
1
- require 'schemata/dea'
2
- require 'spec_helper'
3
-
4
- describe Schemata::DEA::DropletStatusResponse do
5
- it_behaves_like "a message type"
6
- end
7
-
8
- describe Schemata::DEA::DropletStatusResponse::V1 do
9
- it_behaves_like "a message"
10
- end
@@ -1,10 +0,0 @@
1
- require 'schemata/dea'
2
- require 'spec_helper'
3
-
4
- describe Schemata::DEA::ExitMessage do
5
- it_behaves_like "a message type"
6
- end
7
-
8
- describe Schemata::DEA::ExitMessage::V1 do
9
- it_behaves_like "a message"
10
- 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
@@ -1,10 +0,0 @@
1
- require 'schemata/dea'
2
- require 'spec_helper'
3
-
4
- describe Schemata::DEA::FindDropletResponse do
5
- it_behaves_like "a message type"
6
- end
7
-
8
- describe Schemata::DEA::FindDropletResponse::V1 do
9
- it_behaves_like "a message"
10
- end
@@ -1,10 +0,0 @@
1
- require 'schemata/dea'
2
- require 'spec_helper'
3
-
4
- describe Schemata::DEA::HeartbeatResponse do
5
- it_behaves_like "a message type"
6
- end
7
-
8
- describe Schemata::DEA::HeartbeatResponse::V1 do
9
- it_behaves_like "a message"
10
- end
@@ -1,10 +0,0 @@
1
- require 'schemata/dea'
2
- require 'spec_helper'
3
-
4
- describe Schemata::DEA::HelloMessage do
5
- it_behaves_like "a message type"
6
- end
7
-
8
- describe Schemata::DEA::HelloMessage::V1 do
9
- it_behaves_like "a message"
10
- end
@@ -1,10 +0,0 @@
1
- require 'schemata/dea'
2
- require 'spec_helper'
3
-
4
- describe Schemata::DEA::StartRequest do
5
- it_behaves_like "a message type"
6
- end
7
-
8
- describe Schemata::DEA::StartRequest::V1 do
9
- it_behaves_like "a message"
10
- end
@@ -1,10 +0,0 @@
1
- require 'schemata/dea'
2
- require 'spec_helper'
3
-
4
- describe Schemata::DEA::StopRequest do
5
- it_behaves_like "a message type"
6
- end
7
-
8
- describe Schemata::DEA::StopRequest::V1 do
9
- it_behaves_like "a message"
10
- 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,10 +0,0 @@
1
- require 'schemata/router'
2
- require 'spec_helper'
3
-
4
- describe Schemata::Router::RegisterRequest do
5
- it_behaves_like "a message type"
6
- end
7
-
8
- describe Schemata::Router::RegisterRequest::V1 do
9
- it_behaves_like "a message"
10
- end
@@ -1,10 +0,0 @@
1
- require 'schemata/router'
2
- require 'spec_helper'
3
-
4
- describe Schemata::Router::StartMessage do
5
- it_behaves_like "a message type"
6
- end
7
-
8
- describe Schemata::Router::StartMessage::V1 do
9
- it_behaves_like "a message"
10
- 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