Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
run provider server with artifice!
Browse files Browse the repository at this point in the history
  • Loading branch information
csquared committed Nov 21, 2011
1 parent d7f0790 commit d4a56d5
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 31 deletions.
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ GEM
specs:
addressable (2.2.6)
archive-tar-minitar (0.5.2)
artifice (0.6)
rack-test
columnize (0.3.4)
contest (0.1.3)
fakefs (0.4.0)
Expand All @@ -28,6 +30,8 @@ GEM
mime-types (1.17.2)
nokogiri (1.5.0)
rack (1.3.2)
rack-test (0.6.1)
rack (>= 1.0)
rake (0.9.2.2)
rest-client (1.6.7)
mime-types (>= 1.16)
Expand Down Expand Up @@ -59,6 +63,7 @@ PLATFORMS
ruby

DEPENDENCIES
artifice
contest
fakefs
haml
Expand Down
12 changes: 1 addition & 11 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,4 @@ Rake::TestTask.new(:test) do |t|
t.test_files = FileList["test/*_test.rb"]
end

desc 'Start the server'
task :start do
fork { exec "ruby test/resources/server.rb > test_log.txt 2>&1" }
end

desc 'Stop the server'
task :stop do
system "ps -ax | grep test/resources/server.rb | grep -v grep | awk '{print $1}' | xargs kill"
end

task :default => [:start, :test, :stop]
task :default => :test
1 change: 1 addition & 0 deletions kensa.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Gem::Specification.new do |s|
s.add_development_dependency(%q<haml>, [">= 0"])
s.add_development_dependency(%q<rr>, [">= 0"])
s.add_development_dependency(%q<fakefs>, [">= 0"])
s.add_development_dependency(%q<artifice>, [">= 0"])
s.add_runtime_dependency(%q<rest-client>, ["< 1.7.0", ">= 1.4.0"])
s.add_runtime_dependency(%q<yajl-ruby>, ["~> 0.6"])
s.add_runtime_dependency(%q<term-ansicolor>, ["~> 1.0"])
Expand Down
2 changes: 1 addition & 1 deletion lib/heroku/kensa/post_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def service(req, res)
</body>
</html>
HTML
res["Content-Lengh"] = res.body.size
res["Content-Length"] = res.body.size
@status = :Shutdown
end
end
1 change: 1 addition & 0 deletions test/all_check_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class AllCheckTest < Test::Unit::TestCase
include Heroku::Kensa
include ProviderMock

setup do
@data = Manifest.new(:method => :get).skeleton
Expand Down
12 changes: 12 additions & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,22 @@
require 'timecop'
require 'rr'
require 'yajl'
require 'artifice'
require 'test/resources/server'

class Test::Unit::TestCase
include RR::Adapters::TestUnit

module ProviderMock
def setup
Artifice.activate_with(ProviderServer)
end

def teardown
Artifice.deactivate
end
end

def kensa(command)
Heroku::Kensa::Client.new(command.split, :silent => true).run!
end
Expand Down
1 change: 1 addition & 0 deletions test/plan_change_check_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class PlanChangeCheckTest < Test::Unit::TestCase
include Heroku::Kensa
include ProviderMock

%w{get post}.each do |method|
context "with sso #{method}" do
Expand Down
1 change: 1 addition & 0 deletions test/provision_check_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class ProvisionCheckTest < Test::Unit::TestCase
include Heroku::Kensa
include ProviderMock

def check ; ProvisionCheck ; end

Expand Down
34 changes: 16 additions & 18 deletions test/resources/server.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
require 'rubygems'
require 'sinatra'
require 'sinatra/base'
require 'json'

enable :sessions

class ProviderServer < Sinatra::Base
helpers do
def heroku_only!
unless auth_heroku?
Expand Down Expand Up @@ -33,10 +32,15 @@ def json_must_include(keys)
end

def login(heroku_user=true)
session.clear
session[:logged_in] = true
session[:heroku] = heroku_user
redirect '/'
@header = heroku_user
haml <<-HAML
%html
%body
- if @header
#heroku-header
%h1 Heroku
%h1 Sample Addon
HAML
end
end

Expand Down Expand Up @@ -117,7 +121,7 @@ def sso
end

post '/working/sso/login' do
puts params.inspect
#puts params.inspect
sso
end

Expand Down Expand Up @@ -213,15 +217,9 @@ def sso_user

get '/' do
unauthorized! unless session[:logged_in]
haml :index
end

__END__

@@ index
%html
%body
- if session[:heroku]
#heroku-header
%h1 Heroku
%h1 Sample Addon
if $0 == __FILE__
self.run!
end
end
2 changes: 1 addition & 1 deletion test/sso_check_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class SsoCheckTest < Test::Unit::TestCase
include Heroku::Kensa

include ProviderMock

def check ; SsoCheck ; end
%w{get post}.each do |method|
Expand Down

0 comments on commit d4a56d5

Please sign in to comment.