Skip to content
Browse files

Add router gem and first router message

Change-Id: I2fb1003e5496e5fb5c02ea387d796dbfd355aac7
  • Loading branch information...
1 parent 2f3175d commit 20dd13cb4b8ac4bda692f0087694b59fb11e3281 @dsabeti dsabeti committed Dec 10, 2012
View
10 Gemfile.router
@@ -0,0 +1,10 @@
+source 'https://rubygems.org'
+
+gemspec :name => 'schemata-router'
+
+gem 'vcap_common', :git => 'https://github.com/cloudfoundry/vcap-common.git'
+
+group :test do
+ gem 'rspec'
+ gem 'ci_reporter'
+end
View
9 lib/schemata/router.rb
@@ -0,0 +1,9 @@
+require 'schemata/router/register_request'
+
+module Schemata
+ module Router
+ def self.mock_register_request(version=RegisterRequest.current_version)
+ RegisterRequest::const_get("V#{version}").mock
+ end
+ end
+end
View
13 lib/schemata/router/register_request.rb
@@ -0,0 +1,13 @@
+require 'schemata/common/msgtypebase'
+
+module Schemata
+ module Router
+ module RegisterRequest
+ extend Schemata::MessageTypeBase
+ end
+ end
+end
+
+Dir[File.dirname(__FILE__) + '/register_request/*.rb'].each do |file|
+ require file
+end
View
51 lib/schemata/router/register_request/register_request_v1.rb
@@ -0,0 +1,51 @@
+module Schemata
+ module Router
+ module RegisterRequest
+ version 1 do
+ include_preschemata
+
+ define_schema do
+ {
+ optional("dea") => String,
+ optional("app") => String,
+ "uris" => [String],
+ "host" => String,
+ "port" => Integer,
+ "tags" => {
+ optional("framework") => String,
+ optional("runtime") => String,
+ optional("component") => String,
+ },
+ optional("private_instance_id") => String,
+ }
+ end
+
+ define_min_version 1
+
+ define_upvert do |old_data|
+ raise NotImplementedError.new
+ end
+
+ define_generate_old_fields do |msg_obj|
+ raise NotImplementedError.new
+ end
+
+ define_mock_values do
+ {
+ "dea" => proc { VCAP.secure_uuid },
+ "app" => proc { Random.rand(100).to_s },
+ "uris" => ["foo.vcap.me"],
+ "host" => "127.0.0.1",
+ "port" => 80,
+ "tags" => {
+ "framework" => "rails3",
+ "runtime" => "ruby18",
+ "component" => "dashboard",
+ },
+ "private_instance_id" => proc { VCAP.secure_uuid },
+ }
+ end
+ end
+ end
+ end
+end
View
5 lib/schemata/router/version.rb
@@ -0,0 +1,5 @@
+module Schemata
+ module Router
+ VERSION = "0.0.1"
+ end
+end
View
28 schemata-router.gemspec
@@ -0,0 +1,28 @@
+require File.expand_path('../lib/schemata/router/version', __FILE__)
+
+Gem::Specification.new do |gem|
+ gem.name = "schemata-router"
+ gem.version = Schemata::Router::VERSION
+ gem.date = '2012-12-19'
+ gem.summary = 'validation for cloundfoundry Router messages'
+ gem.homepage = 'http://www.cloudfoundry.org'
+ gem.authors = ['dsabeti']
+ gem.email = ['support@cloudfoundry.org']
+ gem.description = <<-EOT
+ Specify schema for Router messages and validate messages
+ against defined schema
+ EOT
+ gem.files = Dir.glob("**/*").select do |f|
+ f =~ /lib\/schemata\/(router|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_dependency('vcap_common')
+ gem.add_development_dependency("ci_reporter")
+ gem.add_development_dependency("rake")
+ gem.add_development_dependency("rspec")
+end
View
10 spec/router/register_request_spec.rb
@@ -0,0 +1,10 @@
+require 'schemata/router'
+require 'spec_helper'
+
+describe Schemata::Router::RegisterRequest do
+ it_behaves_like "a message type"
+end
+
+describe Schemata::Router::RegisterRequest::V1 do
+ it_behaves_like "a message"
+end
View
6 spec/router/router_spec.rb
@@ -0,0 +1,6 @@
+require 'schemata/router'
+require 'spec_helper'
+
+describe Schemata::Router do
+ it_behaves_like "a schemata component"
+end

0 comments on commit 20dd13c

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