schemata-staging 0.0.1.1
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 +260 -0
- data/lib/schemata/common/msgtypebase.rb +122 -0
- data/lib/schemata/common/parsed_msg.rb +43 -0
- data/lib/schemata/helpers/hash_copy.rb +28 -0
- data/lib/schemata/staging.rb +9 -0
- data/lib/schemata/staging/message.rb +13 -0
- data/lib/schemata/staging/message/message_v1.rb +148 -0
- data/lib/schemata/staging/version.rb +5 -0
- data/spec/cloud_controller/cc_bar_spec.rb +140 -0
- data/spec/common/helpers_spec.rb +89 -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/staging/staging_message_spec.rb +186 -0
- data/spec/support/helpers.rb +27 -0
- metadata +153 -0
@@ -0,0 +1,148 @@
|
|
1
|
+
require 'membrane'
|
2
|
+
require 'schemata/helpers/hash_copy'
|
3
|
+
require 'schemata/common/msgtypebase'
|
4
|
+
|
5
|
+
module Schemata
|
6
|
+
module Staging
|
7
|
+
module Message
|
8
|
+
|
9
|
+
version 1 do
|
10
|
+
include_preschemata
|
11
|
+
|
12
|
+
define_schema do
|
13
|
+
{
|
14
|
+
"app_id" => Integer,
|
15
|
+
"download_uri" => String,
|
16
|
+
"upload_uri" => String,
|
17
|
+
"properties" => {
|
18
|
+
"services" => [ {
|
19
|
+
"label" => String,
|
20
|
+
"tags" => [String],
|
21
|
+
"name" => String,
|
22
|
+
"credentials" => {
|
23
|
+
# XXX Does this schema vary by service?
|
24
|
+
"hostname" => String,
|
25
|
+
"host" => String,
|
26
|
+
"port" => Integer,
|
27
|
+
"password" => String,
|
28
|
+
"name" => String,
|
29
|
+
|
30
|
+
},
|
31
|
+
"options" => any,
|
32
|
+
"plan" => String,
|
33
|
+
"plan_option" => any,
|
34
|
+
"type" => String,
|
35
|
+
"version" => String,
|
36
|
+
"vendor" => String,
|
37
|
+
} ],
|
38
|
+
"environment" => [String],
|
39
|
+
"framework" => String,
|
40
|
+
"framework_info" => {
|
41
|
+
"name" => String,
|
42
|
+
optional("detection") => [Hash],
|
43
|
+
optional("runtimes") => [Hash],
|
44
|
+
},
|
45
|
+
"meta" => {
|
46
|
+
optional("debug") => any,
|
47
|
+
optional("console") => any,
|
48
|
+
optional("command") => String,
|
49
|
+
},
|
50
|
+
"resources" => {
|
51
|
+
"memory" => Integer,
|
52
|
+
"disk" => Integer,
|
53
|
+
"fds" => Integer,
|
54
|
+
},
|
55
|
+
"runtime" => String,
|
56
|
+
"runtime_info" => Hash,
|
57
|
+
},
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
define_min_version 1
|
62
|
+
|
63
|
+
define_upvert do |old_data|
|
64
|
+
raise NotImplementedError.new
|
65
|
+
end
|
66
|
+
|
67
|
+
define_generate_old_fields do |msg_obj|
|
68
|
+
raise NotImplementedError.new
|
69
|
+
end
|
70
|
+
|
71
|
+
define_mock_values({
|
72
|
+
"app_id" => 1,
|
73
|
+
"download_uri" => "http://foobar@172.0.0.0:100/download",
|
74
|
+
"upload_uri" => "http://foobar@172.0.0.0:100/upload",
|
75
|
+
"properties" => {
|
76
|
+
"services" => [ {
|
77
|
+
"label" => "mongodb-1.8",
|
78
|
+
"tags" => ["mongodb"],
|
79
|
+
"name" => "mongodb-685a",
|
80
|
+
"credentials" => {
|
81
|
+
"hostname" => "172.20.208.40",
|
82
|
+
"host" => "172.20.208.40",
|
83
|
+
"port" => 25001,
|
84
|
+
"password" => "a2ee7245-cdee-4a4a-b426-a8258ff1b39a",
|
85
|
+
"name" => "2eaa7336-2696-43cd-bb96-a614740b3511",
|
86
|
+
"username" => "aaf31edf-b2bc-4f97-a033-7021c2528ce8",
|
87
|
+
"db" => "db",
|
88
|
+
"url" => "mongodb://aaf31edf-b2bc-4f97-a033-7021c2528ce8:a2ee7245-cdee-4a4a-b426-a8258ff1b39a@172.20.208.40:25001/db",
|
89
|
+
},
|
90
|
+
"options" => {},
|
91
|
+
"plan" => "free",
|
92
|
+
"plan_option" => nil,
|
93
|
+
"type" => "document",
|
94
|
+
"version" => "1.8",
|
95
|
+
"vendor" => "mongodb",
|
96
|
+
} ],
|
97
|
+
"environment" => [],
|
98
|
+
"framework" => "sinatra",
|
99
|
+
"framework_info" => {
|
100
|
+
"name" => "sinatra",
|
101
|
+
"runtimes" => [
|
102
|
+
{"ruby18" => {
|
103
|
+
"default" => true}},
|
104
|
+
{"ruby19" => {
|
105
|
+
"default" => false}},
|
106
|
+
],
|
107
|
+
"detection" => [
|
108
|
+
{"*.rb" => "\\s*require[\\s\\(]*['\"]sinatra(/base)?['\"]"},
|
109
|
+
{"config/environment.rb" => false}
|
110
|
+
],
|
111
|
+
},
|
112
|
+
"meta" => {
|
113
|
+
"debug" => nil,
|
114
|
+
"console" => nil,
|
115
|
+
},
|
116
|
+
"resources" => {
|
117
|
+
"memory" => 64,
|
118
|
+
"disk" => 2048,
|
119
|
+
"fds" => 256,
|
120
|
+
},
|
121
|
+
"runtime" => "ruby19",
|
122
|
+
"runtime_info" => {
|
123
|
+
"description" => "Ruby 1.9",
|
124
|
+
"version" => "1.9.2p180",
|
125
|
+
"executable" => "/var/vcap/packages/dea_ruby19/bin/ruby",
|
126
|
+
"staging" => "/var/vcap/packages/ruby/bin/ruby stage",
|
127
|
+
"version_output" => "1.9.2",
|
128
|
+
"version_flag" => "-e 'puts RUBY_VERSION'",
|
129
|
+
"additional_checks" => "-e 'puts RUBY_PATCHLEVEL == 180'",
|
130
|
+
"environment" => {
|
131
|
+
"LD_LIBRARY_PATH" => "/var/vcap/packages/mysqlclient/lib/mysql:/var/vcap/packages/sqlite/lib:/var/vcap/packages/libpq/lib:/var/vcap/packages/imagemagick/lib:$LD_LIBRARY_PATH",
|
132
|
+
"BUNDLE_GEMFILE" => nil,
|
133
|
+
"PATH" => "/var/vcap/packages/imagemagick/bin:/var/vcap/packages/dea_transition/rubygems/1.9.1/bin:/var/vcap/packages/dea_ruby19/bin:/var/vcap/packages/dea_node08/bin:$PATH",
|
134
|
+
"GEM_PATH" => "/var/vcap/packages/dea_transition/rubygems/1.9.1:$GEM_PATH",
|
135
|
+
},
|
136
|
+
"status" => {
|
137
|
+
"name" => "current",
|
138
|
+
},
|
139
|
+
"series" => "ruby19",
|
140
|
+
"category" => "ruby",
|
141
|
+
"name" => "ruby19",
|
142
|
+
}
|
143
|
+
}
|
144
|
+
})
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'schemata/cloud_controller/cloud_controller'
|
2
|
+
require 'support/helpers'
|
3
|
+
|
4
|
+
describe Schemata::CloudController 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::CloudController::Bar, 10)
|
41
|
+
end
|
42
|
+
|
43
|
+
after :each do
|
44
|
+
reset_version(Schemata::CloudController::Bar)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should take a v10 msg and create a v10 obj" do
|
48
|
+
msg_obj = Schemata::CloudController::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::CloudController::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::CloudController::Bar, 11)
|
63
|
+
end
|
64
|
+
|
65
|
+
after :each do
|
66
|
+
reset_version(Schemata::CloudController::Bar)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should take a v10 msg and create a v11 obj" do
|
70
|
+
msg_obj = Schemata::CloudController::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::CloudController::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::CloudController::Bar, 10)
|
87
|
+
end
|
88
|
+
|
89
|
+
after :each do
|
90
|
+
reset_version(Schemata::CloudController::Bar)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should take a v10 obj and encode a json msg" do
|
94
|
+
v10_obj = Schemata::CloudController::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::CloudController::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::CloudController::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::CloudController::Bar)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'schemata/helpers/hash_copy'
|
2
|
+
|
3
|
+
describe Schemata::HashCopyHelpers do
|
4
|
+
describe "#deep_copy" do
|
5
|
+
it "should deep copy nil" do
|
6
|
+
copy = Schemata::HashCopyHelpers.deep_copy(nil)
|
7
|
+
copy.should == nil
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should deep copy a given string" do
|
11
|
+
original = "foo"
|
12
|
+
copy = Schemata::HashCopyHelpers.deep_copy(original)
|
13
|
+
copy.should be_instance_of String
|
14
|
+
copy.should == original
|
15
|
+
copy.object_id.should_not == original.object_id
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should deep copy a given boolean" do
|
19
|
+
Schemata::HashCopyHelpers.deep_copy(true).
|
20
|
+
should be_an_instance_of TrueClass
|
21
|
+
Schemata::HashCopyHelpers.deep_copy(false).
|
22
|
+
should be_an_instance_of FalseClass
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should deep copy a given numeric type" do
|
26
|
+
original = 0
|
27
|
+
copy = Schemata::HashCopyHelpers.deep_copy(original)
|
28
|
+
copy.should == original
|
29
|
+
copy.should be_an_instance_of Fixnum
|
30
|
+
|
31
|
+
# set original to be max fixnum + 1
|
32
|
+
original = 2**(0.size * 8 -2)
|
33
|
+
copy = Schemata::HashCopyHelpers.deep_copy(original)
|
34
|
+
copy.should == original
|
35
|
+
copy.should be_an_instance_of Bignum
|
36
|
+
|
37
|
+
original = 0.0
|
38
|
+
copy = Schemata::HashCopyHelpers.deep_copy(original)
|
39
|
+
copy.should == original
|
40
|
+
copy.should be_an_instance_of Float
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should deep copy a given hash" do
|
44
|
+
original = {"foo" => "bar"}
|
45
|
+
copy = Schemata::HashCopyHelpers.deep_copy(original)
|
46
|
+
copy.should be_instance_of Hash
|
47
|
+
copy.should == original
|
48
|
+
|
49
|
+
copy.object_id.should_not == original.object_id
|
50
|
+
copy["foo"].object_id.should_not == original["foo"].object_id
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should deep copy a given array" do
|
54
|
+
original = [1, 2, "hello"]
|
55
|
+
copy = Schemata::HashCopyHelpers.deep_copy(original)
|
56
|
+
copy.should be_instance_of Array
|
57
|
+
copy.should == original
|
58
|
+
|
59
|
+
copy.object_id.should_not == original.object_id
|
60
|
+
# only check object_id of String object
|
61
|
+
copy[2].object_id.should_not == original[2].object_id
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should deep copy nested types" do
|
65
|
+
original = {
|
66
|
+
"foo" => "bar",
|
67
|
+
"inner" => {
|
68
|
+
"hello" => "goodbye",
|
69
|
+
},
|
70
|
+
}
|
71
|
+
copy = Schemata::HashCopyHelpers.deep_copy(original)
|
72
|
+
copy.should be_instance_of Hash
|
73
|
+
copy.should == original
|
74
|
+
|
75
|
+
copy.object_id.should_not == original.object_id
|
76
|
+
copy["foo"].object_id.should_not == original["foo"].object_id
|
77
|
+
copy["inner"].object_id.should_not == original["inner"].object_id
|
78
|
+
copy["inner"]["hello"].object_id.
|
79
|
+
should_not == original["inner"]["hello"].object_id
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should raise error for unknown type" do
|
83
|
+
klass = Class.new
|
84
|
+
expect do
|
85
|
+
Schemata::HashCopyHelpers.deep_copy(klass.new)
|
86
|
+
end.to raise_error(described_class::CopyError, /Unexpected class: /)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
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
|