Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Enforce gem dir structure, fix schema, fix bugs

Change-Id: I05bd340be993fc03062e1c0bb02c5d983d625c08
  • Loading branch information...
commit 1d3559875fb9a2fc15abfc8ee7871a45db37b9cd 1 parent 2eecf0b
@dsabeti dsabeti authored
View
2  Gemfile
@@ -1,6 +1,6 @@
source 'https://rubygems.org'
-gemspec :name => 'schemata-component'
+gemspec :name => 'schemata-staging'
group :test do
gem 'rspec'
View
4 Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- schemata-component (0.0.1)
+ schemata-staging (0.0.1)
membrane
yajl-ruby
@@ -31,4 +31,4 @@ DEPENDENCIES
ci_reporter
rake
rspec
- schemata-component!
+ schemata-staging!
View
1  lib/schemata/common/msgbase.rb
@@ -1,3 +1,4 @@
+require 'yajl'
require 'schemata/common/error'
module Schemata
View
1  lib/schemata/common/msgtypebase.rb
@@ -1,4 +1,5 @@
require 'schemata/common/msgbase'
+require 'schemata/common/parsed_msg'
module Schemata
module MessageTypeBase
View
6 lib/schemata/helpers/hash_copy.rb
@@ -10,7 +10,11 @@ def self.deep_copy(node)
return node
when Hash
copy = {}
- node.each { |k, v| copy[k] = deep_copy(v) }
+ # XXX NB: The 'to_s' below was included because some components use
+ # symbols as keys instead of strings. This fix is temporary; in the
+ # long term, we should change all components to use the same type for
+ # their keys
+ node.each { |k, v| copy[k.to_s] = deep_copy(v) }
return copy
when Array
return node.map { |v| deep_copy(v) }
View
0  lib/schemata/staging/staging.rb → lib/schemata/staging.rb
File renamed without changes
View
8 lib/schemata/staging/message/message_v1.rb
@@ -30,7 +30,7 @@ module Message
},
"options" => any,
"plan" => String,
- "plan_options" => any,
+ "plan_option" => any,
"type" => String,
"version" => String,
"vendor" => String,
@@ -43,8 +43,8 @@ module Message
optional("runtimes") => [Hash],
},
"meta" => {
- "debug" => any,
- "console" => any,
+ optional("debug") => any,
+ optional("console") => any,
optional("command") => String,
},
"resources" => {
@@ -89,7 +89,7 @@ module Message
},
"options" => {},
"plan" => "free",
- "plan_options" => nil,
+ "plan_option" => nil,
"type" => "document",
"version" => "1.8",
"vendor" => "mongodb",
View
148 lib/schemata/staging/message/message_v2.rb
@@ -1,148 +0,0 @@
-require 'membrane'
-require 'schemata/helpers/hash_copy'
-require 'schemata/common/msgtypebase'
-
-module Schemata
- module Staging
- module Message
-
- version 2 do
- define_schema do
- {
- "app_id" => Integer,
- "download_uri" => String,
- "upload_uri" => String,
- "properties" => {
- "services" => [ {
- "label" => String,
- "tags" => [String],
- "name" => String,
- "credentials" => {
- # XXX Does this schema vary by service?
- "hostname" => String,
- "host" => String,
- "port" => Integer,
- "password" => String,
- "name" => String,
-
- },
- "options" => any,
- "plan" => String,
- "plan_options" => any,
- "type" => String,
- "version" => String,
- "vendor" => String,
- } ],
- "environment" => [String],
- "framework" => String,
- "framework_info" => {
- "name" => String,
- optional("detection") => [Hash],
- optional("runtimes") => [Hash],
- },
- "meta" => {
- "debug" => any,
- "console" => any,
- optional("command") => String,
- },
- "resources" => {
- "memory" => Integer,
- "disk" => Integer,
- "fds" => Integer,
- },
- "runtime" => String,
- "runtime_info" => Hash,
- },
- }
- end
-
- define_min_version 1
-
- define_upvert do |old_data|
- old_data
- end
-
- define_generate_old_fields do |msg_obj|
- {}
- end
-
- define_mock_values do
- {
- "app_id" => 1,
- "download_uri" => "http://foobar@172.0.0.0:100/download",
- "upload_uri" => "http://foobar@172.0.0.0:100/upload",
- "properties" => {
- "services" => [ {
- "label" => "mongodb-1.8",
- "tags" => ["mongodb"],
- "name" => "mongodb-685a",
- "credentials" => {
- "hostname" => "172.20.208.40",
- "host" => "172.20.208.40",
- "port" => 25001,
- "password" => "a2ee7245-cdee-4a4a-b426-a8258ff1b39a",
- "name" => "2eaa7336-2696-43cd-bb96-a614740b3511",
- "username" => "aaf31edf-b2bc-4f97-a033-7021c2528ce8",
- "db" => "db",
- "url" => "mongodb://aaf31edf-b2bc-4f97-a033-7021c2528ce8:a2ee7245-cdee-4a4a-b426-a8258ff1b39a@172.20.208.40:25001/db",
- },
- "options" => {},
- "plan" => "free",
- "plan_options" => nil,
- "type" => "document",
- "version" => "1.8",
- "vendor" => "mongodb",
- } ],
- "environment" => [],
- "framework" => "sinatra",
- "framework_info" => {
- "name" => "sinatra",
- "runtimes" => [
- {"ruby18" => {
- "default" => true}},
- {"ruby19" => {
- "default" => false}},
- ],
- "detection" => [
- {"*.rb" => "\\s*require[\\s\\(]*['\"]sinatra(/base)?['\"]"},
- {"config/environment.rb" => false}
- ],
- },
- "meta" => {
- "debug" => nil,
- "console" => nil,
- },
- "resources" => {
- "memory" => 64,
- "disk" => 2048,
- "fds" => 256,
- },
- "runtime" => "ruby19",
- "runtime_info" => {
- "description" => "Ruby 1.9",
- "version" => "1.9.2p180",
- "executable" => "/var/vcap/packages/dea_ruby19/bin/ruby",
- "staging" => "/var/vcap/packages/ruby/bin/ruby stage",
- "version_output" => "1.9.2",
- "version_flag" => "-e 'puts RUBY_VERSION'",
- "additional_checks" => "-e 'puts RUBY_PATCHLEVEL == 180'",
- "environment" => {
- "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",
- "BUNDLE_GEMFILE" => nil,
- "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",
- "GEM_PATH" => "/var/vcap/packages/dea_transition/rubygems/1.9.1:$GEM_PATH",
- },
- "status" => {
- "name" => "current",
- },
- "series" => "ruby19",
- "category" => "ruby",
- "name" => "ruby19",
- }
- }
- }
- end
- end
- end
- end
-end
View
2  lib/schemata/staging/version.rb
@@ -1,5 +1,5 @@
module Schemata
module Staging
- VERSION = "0.0.1"
+ VERSION = "0.0.1.1"
end
end
View
27 schemata-staging.gemspec
@@ -0,0 +1,27 @@
+require File.expand_path('../lib/schemata/staging/version', __FILE__)
+
+Gem::Specification.new do |gem|
+ gem.name = "schemata-staging"
+ gem.version = Schemata::Staging::VERSION
+ gem.date = '2012-11-21'
+ gem.summary = 'validation for cloundfoundry stager messages'
+ gem.homepage = 'http://www.cloudfoundry.org'
+ gem.authors = ['dsabeti']
+ gem.email = ['support@cloudfoundry.org']
+ gem.description = <<-EOT
+ Specify schema for staging messages and validate messages
+ against defined schema
+ EOT
+ gem.files = Dir.glob("**/*").select do |f|
+ f =~ /lib\/schemata\/(staging|common|helpers)/
+ end
+ gem.executables = `git ls-files`.split($\).grep(%r{^bin/}).map{ |f| File.basename(f) }
+ gem.test_files = `git ls-files`.split($\).grep(%r{^(test|spec|features)/})
+ gem.require_paths = ["lib"]
+
+ gem.add_dependency("membrane")
+ gem.add_dependency("yajl-ruby")
+ gem.add_development_dependency("ci_reporter")
+ gem.add_development_dependency("rake")
+ gem.add_development_dependency("rspec")
+end
View
126 spec/staging/staging_message_spec.rb
@@ -1,6 +1,6 @@
require 'yajl'
require 'support/helpers'
-require 'schemata/staging/staging'
+require 'schemata/staging'
describe Schemata::Staging do
describe ".mock_message" do
@@ -101,51 +101,6 @@
}.to raise_error(Schemata::DecodeError)
end
end
-
- context "current version is 2" do
- it "should return a V2 object given a V1-encoded json" do
- v1_hash = Schemata::HashCopyHelpers.deep_copy(
- Schemata::Staging::Message::V1::MOCK_VALUES
- )
- msg_hash = {"V1" => v1_hash, "min_version" => 1}
-
- json = Yajl::Encoder.encode(msg_hash)
-
- msg_obj = Schemata::Staging::Message.decode(json)
- msg_obj.class.should == Schemata::Staging::Message::V2
-
- msg_obj.app_id.should == 1
- msg_obj.download_uri.should == "http://foobar@172.0.0.0:100/download"
- msg_obj.upload_uri.should == "http://foobar@172.0.0.0:100/upload"
- msg_obj.properties.should ==
- Schemata::Staging::Message::V2::MOCK_VALUES["properties"]
- end
-
- it "should return a V2 object given a V2-encoded json" do
- v2_hash = Schemata::HashCopyHelpers.deep_copy(
- Schemata::Staging::Message::V2::MOCK_VALUES
- )
- msg_hash = {"V2" => v2_hash, "V1" => {}, "min_version" => 1}
-
- json = Yajl::Encoder.encode(msg_hash)
-
- msg_obj = Schemata::Staging::Message.decode(json)
- msg_obj.class.should == Schemata::Staging::Message::V2
-
- msg_obj.app_id.should == 1
- msg_obj.download_uri.should == "http://foobar@172.0.0.0:100/download"
- msg_obj.upload_uri.should == "http://foobar@172.0.0.0:100/upload"
- msg_obj.properties.should ==
- Schemata::Staging::Message::V2::MOCK_VALUES["properties"]
- end
-
- it "should raise an error if the json has additional fields" do
- json = '{"V2":{}, "min_version":1, "foo":"bar"}'
- expect {
- msg_obj = Schemata::Staging::Message.decode(json)
- }.to raise_error(Schemata::DecodeError)
- end
- end
end
end
@@ -229,82 +184,3 @@
end
end
end
-
-describe Schemata::Staging::Message::V2 do
- before :each do
- set_current_version(Schemata::Staging::Message, 2)
- end
-
- after :each do
- reset_version(Schemata::Staging::Message)
- end
-
- describe "#new" do
- it "should create a V2 object given an incomplete hash" do
- msg_obj = Schemata::Staging::Message::V2.new({"app_id" => 1})
- end
-
- it "should raise an error if the hash contains incorrect types" do
- expect {
- msg_obj = Schemata::Staging::Message::V2.new({"app_id" => "foo"})
- }.to raise_error(Schemata::UpdateAttributeError)
- end
- end
-
- describe "#encode" do
- it "should return a json string with the proper Schemata format" do
- msg_obj = Schemata::Staging.mock_message(2)
- json = msg_obj.encode
- json_hash = Yajl::Parser.parse(json)
-
- v2_hash = json_hash['V2']
- v1_hash = json_hash['V1']
- min_version = json_hash['min_version']
-
- v2_hash.should == Schemata::Staging::Message::V2::MOCK_VALUES
- v1_hash.should == {}
- min_version.should == 1
- end
-
- it "should raise an error if the object is incomplete" do
- msg_obj = Schemata::Staging::Message::V2.new({})
- expect {
- msg_obj.encode
- }.to raise_error(Schemata::EncodeError)
- end
- end
-
- describe "#app_id" do
- it "should return the app_id if it was specified at instatiation" do
- msg_obj = Schemata::Staging::Message::V2.new({"app_id" => 1})
- msg_obj.app_id.should == 1
- end
-
- it "should return the app_id if it was set with an attr writer" do
- msg_obj = Schemata::Staging::Message::V2.new({})
- msg_obj.app_id = 1
- msg_obj.app_id.should == 1
- end
-
- it "should return nil if the app_id was never specified" do
- msg_obj = Schemata::Staging::Message::V2.new({})
- msg_obj.app_id.should be_nil
- end
- end
-
- describe "#app_id=" do
- it "should change the app_id and return the new value" do
- msg_obj = Schemata::Staging::Message::V2.new({"app_id" => 1})
- ret = (msg_obj.app_id =2)
- msg_obj.app_id.should == 2
- ret.should == 2
- end
-
- it "should raise an error if the wrong type is given" do
- msg_obj = Schemata::Staging::Message::V2.new({"app_id" => 1})
- expect {
- msg_obj.app_id = "foo"
- }.to raise_error(Schemata::UpdateAttributeError)
- end
- end
-end

0 comments on commit 1d35598

Please sign in to comment.
Something went wrong with that request. Please try again.