Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

wip

  • Loading branch information...
commit 9cc855d1c1e265a05d03fe340f6048546b7d5478 1 parent a1889ce
@halogenandtoast halogenandtoast authored
View
4 Gemfile
@@ -1,6 +1,7 @@
source "http://rubygems.org"
-gem "em-http-request", "0.3.0"
+gem "eventmachine", "1.0.0.beta.3"
+gem "em-http-request", "1.0.0.beta.3"
gem "em-hiredis", "0.1.0"
gem "daemons", "1.1.0"
gem "json_pure", "1.4.6"
@@ -14,4 +15,5 @@ group :development do
gem "timecop"
gem "webmock"
gem "SystemTimer", :platform => :mri_18
+ gem "ruby-debug19", :platform => :mri_19
end
View
33 Gemfile.lock
@@ -9,26 +9,33 @@ GEM
specs:
SystemTimer (1.2)
addressable (2.2.5)
+ archive-tar-minitar (0.5.2)
bourne (1.0)
mocha (= 0.9.8)
+ columnize (0.3.2)
crack (0.1.8)
daemons (1.1.0)
diff-lcs (1.1.2)
em-hiredis (0.1.0)
hiredis (~> 0.3.0)
- em-http-request (0.3.0)
- addressable (>= 2.0.0)
- escape_utils
- eventmachine (>= 0.12.9)
- escape_utils (0.2.3)
- eventmachine (0.12.10)
+ em-http-request (1.0.0.beta.3)
+ addressable (>= 2.2.3)
+ em-socksify
+ eventmachine
+ http_parser.rb (>= 0.5.1)
+ em-socksify (0.1.0)
+ eventmachine
+ eventmachine (1.0.0.beta.3)
git (1.2.5)
hiredis (0.3.1)
+ http_parser.rb (0.5.1)
jeweler (1.5.1)
bundler (~> 1.0.0)
git (>= 1.2.5)
rake
json_pure (1.4.6)
+ linecache19 (0.5.12)
+ ruby_core_source (>= 0.1.4)
mocha (0.9.8)
rake
rake (0.8.7)
@@ -41,6 +48,16 @@ GEM
rspec-expectations (2.5.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.5.0)
+ ruby-debug-base19 (0.11.25)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby_core_source (>= 0.1.4)
+ ruby-debug19 (0.11.6)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby-debug-base19 (>= 0.11.19)
+ ruby_core_source (0.1.5)
+ archive-tar-minitar (>= 0.5.2)
timecop (0.3.5)
webmock (1.6.2)
addressable (>= 2.2.2)
@@ -54,11 +71,13 @@ DEPENDENCIES
bourne
daemons (= 1.1.0)
em-hiredis (= 0.1.0)
- em-http-request (= 0.3.0)
+ em-http-request (= 1.0.0.beta.3)
em-spec!
+ eventmachine (= 1.0.0.beta.3)
jeweler
json_pure (= 1.4.6)
redis (= 2.1.1)
rspec
+ ruby-debug19
timecop
webmock
View
36 data/daikon/heroku.crt
@@ -1,36 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIGLjCCBRagAwIBAgIQBW45cqDTT/6c02Tq4xlhcTANBgkqhkiG9w0BAQUFADBm
-MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
-d3cuZGlnaWNlcnQuY29tMSUwIwYDVQQDExxEaWdpQ2VydCBIaWdoIEFzc3VyYW5j
-ZSBDQS0zMB4XDTEwMDgyNjAwMDAwMFoXDTEzMDgyOTIzNTk1OVowaDELMAkGA1UE
-BhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBGcmFuY2lz
-Y28xFTATBgNVBAoTDEhlcm9rdSwgSW5jLjEVMBMGA1UEAxQMKi5oZXJva3UuY29t
-MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDFNwvpUS9ZWlQrnZzLht9DT4s2
-nSnjxBoL9k4HN6zag0OrkcJS4bcr1l6/WiPDYzBESRoRW0nZlhA6oHVJY0eeyfLY
-7F9FQxJ/EXz8inC17nquEey7H7+enD/NLZL+Vzc3pZWYp0+dTRs6k9oe7ClCU9pB
-RPfmeoh/qKj9tR6VWQIDAQABo4IDWDCCA1QwHwYDVR0jBBgwFoAUUOpzidsp+xCP
-nuUBINTee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BlAGYAZQByAGUAbgBjAGUALjAdBgNVHSUEFjAUBggrBgEF
-BQcDAQYIKwYBBQUHAwIwDQYJKoZIhvcNAQEFBQADggEBACjkMtcOy1q1bYdStzy5
-5LTeSNv7rYXhQS3I5/Ukv8vcseHglN7PvAwj7QhegKyzGxdv1mCL8ZHkLEqkRS+w
-VgVB6CULi9RVBOLcFZW/bGFF++7HGpaJXRDS5eQP/e5qCfdtHvWiX+6ATIGSMg2F
-ZAMPAo0wVmrMYkQaVNpmxEmyYdEJp8oxjyMahjVsDUptCPqMTmY2nFm7bRM89D/6
-fIqWtKWH1nfGK3IIYlQN13GIN5p26GrF139Hq9Ndu5ABl/oLFkaM+qu6CyDY5Y26
-KNE9hEj2Zvtw2btKLtP0w2ROlxU+AIQb1mbYrldVIkYMmuHfDt8MUI4TwR+Ip6uT
-638=
------END CERTIFICATE-----
View
10 lib/daikon.rb
@@ -29,13 +29,5 @@
require 'daikon/daemons_hacks'
module Daikon
- VERSION = "0.9.2"
-
- def self.data_dir(path)
- if datadir = Gem.datadir("daikon")
- File.join(datadir, path)
- else
- ""
- end
- end
+ VERSION = "0.9.3"
end
View
2  lib/daikon/client.rb
@@ -36,7 +36,7 @@ def request(method, path, options = {})
url = "#{config.server_prefix}#{path}"
options[:head] ||= {}
options[:head]['Authorization'] = config.api_key
- options[:ssl] = {:verify_peer => true, :cert_chain_file => Daikon.data_dir("heroku.crt")}
+ options[:ssl] = {:verify_peer => true}
log "#{method.to_s.upcase} #{url}"
View
2  lib/daikon/configuration.rb
@@ -1,7 +1,7 @@
module Daikon
class Configuration
BLANK_KEY = "1234567890"
- URL = "https://radish.heroku.com"
+ URL = "https://ssl.radishapp.com"
FLAGS = ["-u", "-k", "-s"]
OPTIONS = ["redis_url", "api_key", "server_prefix"]
DEFAULTS = ["redis://0.0.0.0:6379", BLANK_KEY, URL]
View
72 spec/client_spec.rb
@@ -26,22 +26,22 @@
end
end
-describe Daikon::Client, "when server is down" do
- subject { Daikon::Client.new }
-
- before do
- stub_request(:any, infos_url).to_timeout
- end
-
- it "does not kill the client" do
- em do
- subject.on(:request_error) { EM.stop }
- lambda {
- subject.report_info({})
- }.should_not raise_error
- end
- end
-end
+# describe Daikon::Client, "when server is down" do
+# subject { Daikon::Client.new }
+#
+# before do
+# stub_request(:any, infos_url).to_timeout
+# end
+#
+# it "does not kill the client" do
+# em do
+# subject.on(:request_error) { EM.stop }
+# lambda {
+# subject.report_info({})
+# }.should_not raise_error
+# end
+# end
+# end
describe Daikon::Client, "when it returns bad json" do
subject { Daikon::Client.new }
@@ -53,6 +53,7 @@
it "does not commit suicide" do
em do
subject.on(:request_success) { EM.stop }
+ subject.report_info({})
lambda {
subject.report_info({})
}.should_not raise_error
@@ -72,7 +73,7 @@
subject.rotate_monitor(DateTime.parse(past), DateTime.parse(now))
end
- WebMock.should have_requested(:post, summaries_url(server)).
+ FakeRadish.should have_requested(:post, summaries_url(server)).
with(:headers => headers) { |req| JSON.parse!(req.body) == payload }
end
end
@@ -104,19 +105,20 @@
context "with default configuration" do
let(:api_key) { config.api_key }
- let(:server) { "https://radish.heroku.com" }
- let(:config) { Daikon::Configuration.new }
-
- it_should_behave_like "a summary api consumer"
- end
-
- context "with custom settings" do
- let(:api_key) { "0987654321" }
- let(:server) { "http://localhost:9999" }
- let(:config) { Daikon::Configuration.new(["-k", api_key, "-s", "http://localhost:9999"]) }
+ # let(:server) { "https://ssl.radishapp.com" }
+ let(:server) { "http://0.0.0.0:8090" }
+ let(:config) { Daikon::Configuration.new(["-s", "http://0.0.0.0:8090"]) }
it_should_behave_like "a summary api consumer"
end
+#
+# context "with custom settings" do
+# let(:api_key) { "0987654321" }
+# let(:server) { "http://localhost:9999" }
+# let(:config) { Daikon::Configuration.new(["-k", api_key, "-s", "http://localhost:9999"]) }
+#
+# it_should_behave_like "a summary api consumer"
+# end
end
shared_examples_for "a info api consumer" do
@@ -131,7 +133,7 @@
subject.report_info(info)
end
- WebMock.should have_requested(:post, infos_url(server)).
+ FakeRadish.should have_requested(:post, infos_url(server)).
with(:body => info.to_json, :headers => headers)
end
end
@@ -147,17 +149,17 @@
context "with default configuration" do
let(:api_key) { config.api_key }
- let(:server) { "https://radish.heroku.com" }
+ let(:server) { "https://ssl.radishapp.com" }
let(:config) { Daikon::Configuration.new }
it_should_behave_like "a info api consumer"
end
- context "with custom settings" do
- let(:api_key) { "0987654321" }
- let(:server) { "http://localhost:9999" }
- let(:config) { Daikon::Configuration.new(["-k", api_key, "-s", "http://localhost:9999"]) }
+ # context "with custom settings" do
+ # let(:api_key) { "0987654321" }
+ # let(:server) { "http://localhost:9999" }
+ # let(:config) { Daikon::Configuration.new(["-k", api_key, "-s", "http://localhost:9999"]) }
- it_should_behave_like "a info api consumer"
- end
+ # it_should_behave_like "a info api consumer"
+ # end
end
View
4 spec/spec_helper.rb
@@ -10,13 +10,12 @@
require 'bourne'
require 'em-spec/rspec'
require 'timecop'
-require 'webmock/rspec'
require 'support/capture_helper'
require 'support/parse_helper'
require 'support/url_helper'
+require 'support/radish_helper'
-WebMock.disable_net_connect!
RSpec.configure do |config|
config.mock_with :mocha
@@ -26,6 +25,7 @@
config.include ParseHelper
config.include RedisMock::Helper
config.include UrlHelper
+ config.include FakeRadish::Matchers
config.before do
Daikon::Monitor.reset
View
163 spec/support/radish_helper.rb
@@ -0,0 +1,163 @@
+$fake_radish_registry = {:get => {}, :post => {}, :any => {}}
+$fake_radish_requests = []
+
+module FakeRadish
+ module Server
+
+ def post_init
+ @data_received = ""
+ end
+
+ def receive_data data
+ $stdout.write(data)
+ @data_received << data
+ method, path = parse_http_info
+ save_request(data)
+ puts data
+ puts response_for(method, path)
+ send_data response_for(method, path)
+ close_connection_after_writing
+ return true
+ end
+
+ def save_request(data)
+ header, body = data.split("\r\n\r\n")
+ request_str, *header_lines = header.split("\r\n")
+ headers = {}
+ headers_lines.each do |header_line|
+ key, value = headler_line.split(/:\s+/)
+ headers[key] = value
+ end
+ method, path = parse_http_info
+ $fake_radish_requests << {:method => method, :body => body, :headers => headers}
+ end
+
+ def parse_method(method)
+ method.downcase.to_sym
+ end
+
+ def parse_http_info
+ @data_received.split(/\s+/)[0,2]
+ end
+
+ def received_requests
+ @received_requests ||= {:get => {}, :post => {}, :any => {}}
+ end
+
+ def response_for(method, path)
+ method = parse_method(method)
+ received_requests[method][path] = received_requests[:any][path] = true
+ response = $fake_radish_registry[method][path] || $fake_radish_registry[:any][path]
+ if response
+ raw_response = "HTTP/1.1 #{response.status[0]} #{response.status[1]}\r\n"
+ raw_response << response.headers.map{|key, value| "#{key}: #{value}"}.join("\r\n")
+ raw_response << "\r\n\r\n"
+ raw_response << response.body
+ raw_response
+ else
+ body = "Not Found"
+ headers = {
+ :Date => Time.now,
+ :Server => "FakeRadish Server",
+ :"Last-Modified" => Time.now,
+ :"Accept-Ranges" => "bytes",
+ :"Content-Length" => body.length,
+ :Vary => "Accept-Encoding",
+ :Connection => "close",
+ :"Content-Type" => "text/html"
+ }
+ raw_response = "HTTP/1.1 404 Not Found\r\n"
+ raw_response << headers.map{|key, value| "#{key}: #{value}"}.join("\r\n")
+ raw_response << "\r\n\r\n"
+ raw_response << body
+ raw_response
+ end
+ end
+
+ end
+
+ class Stub
+ def initialize(method, path)
+ $fake_radish_registry[method][path] = self
+ end
+
+ def body
+ @options[:body] || ""
+ end
+
+ def default_headers
+ {
+ :Date => Time.now,
+ :Server => "FakeRadish Server",
+ :"Last-Modified" => Time.now,
+ :"Accept-Ranges" => "bytes",
+ :"Content-Length" => body.length,
+ :Vary => "Accept-Encoding",
+ :Connection => "close",
+ :"Content-Type" => "text/html"
+ }
+ end
+
+ def headers
+ default_headers.merge(@options[:headers] || {})
+ end
+
+ def status
+ [@options[:status], "OK"]
+ end
+
+ def to_return options = {}
+ @options = options
+ end
+
+ def to_timeout
+
+ end
+ end
+
+ module Matchers
+ def have_requested(method, uri)
+ FakeRadish::FakeRadishMatcher.new(method, uri)
+ end
+ end
+
+ class FakeRadishMatcher
+ def initialize(method, uri)
+ @method = method
+ @uri = uri
+ end
+
+ def with(options = {}, &block)
+ @options = options
+ @block = block
+ self
+ end
+
+ def matches?(fake_radish)
+ puts $fake_radish_requests.inspect
+ end
+
+ def failure_message
+ "Request not matched"
+ end
+
+ def negative_failure_message
+ "Request matched when it should not have been"
+ end
+
+ def does_not_match?(fake_radish)
+ puts "SIGH"
+ end
+ end
+end
+
+def stub_request(method, path)
+ puts "STUBBING: #{method} #{path}"
+ FakeRadish::Stub.new(method, path)
+end
+
+Thread.new do
+ EventMachine::run {
+ EventMachine::start_server("0.0.0.0", 8090, FakeRadish::Server)
+ }
+end
Please sign in to comment.
Something went wrong with that request. Please try again.