test/deploy_test.rb in eb_deployer-0.0.6 vs test/deploy_test.rb in eb_deployer-0.0.7

- old
+ new

@@ -1,25 +1,19 @@ +require 'tempfile' require 'eb_deployer' require 'aws_driver_stubs' require 'minitest/autorun' class DeployTest < Minitest::Test def setup @eb_driver = EBStub.new @s3_driver = S3Stub.new + @cf_driver = CFStub.new @sample_package = '/tmp/app-package.war' File.open(@sample_package, 'w') { |f| f << 's' * 100 } end - def deploy(opts) - EbDeployer.deploy({:package => @sample_package, - :bs_driver => @eb_driver, - :s3_driver => @s3_driver, - :version_label => 1}.merge(opts)) - end - - def test_first_deployment_create_environment assert !@eb_driver.environment_exists?('simple', eb_envname('simple', 'production')) deploy(:application => 'simple', :environment => "production") assert @eb_driver.environment_exists?('simple', eb_envname('simple', 'production')) end @@ -150,11 +144,93 @@ assert_equal ['simple-production.elasticbeanstalk.com', 'simple-production-inactive.elasticbeanstalk.com', 'simple-production-inactive.elasticbeanstalk.com'], smoked_host end + def test_deploy_with_resources_declared_will_create_a_cf_stack_for_env + cf_template = temp_file(JSON.dump({'Resources' => {'R1' => {}}})) + deploy(:application => 'simple', :environment => "production", + :resources => { + :template => cf_template + }) + assert @cf_driver.stack_exists?('simple-production') + end + + def test_transforms_resource_provsion_output_to_elastic_beanstalk_settings + cf_template = temp_file(JSON.dump({'Resources' => {'R1' => {}}})) + deploy(:application => 'simple', :environment => "production", + :resources => { + :template => cf_template + }) + assert @cf_driver.stack_exists?('simple-production') + end + + def test_transforms_resource_provsion_output_to_elastic_beanstalk_settings + cf_template = temp_file(JSON.dump({ + 'Resources' => {'R1' => {}}, + 'Outputs' => {'O1' => {}, 'O2' => {}} + })) + deploy(:application => 'simple', :environment => "production", + :resources => { + :template => cf_template, + :transforms => { + 'O1' => lambda { |v| {:namespace => 'aws.foo', :option_name => 'o1', :value => v} } + } + }) + assert @eb_driver.environment_settings('simple', eb_envname('simple', 'production')). + include?({:namespace => 'aws.foo', :option_name => 'o1', :value => 'value of O1'}) + end + + def test_can_query_resource_stack_output_after_deploy + cf_template = temp_file(JSON.dump({ + 'Resources' => {'R1' => {}}, + 'Outputs' => {'O1' => {}, 'O2' => {}} + })) + deploy(:application => 'simple', + :environment => "production", + :resources => { :template => cf_template }) + assert_equal 'value of O1', query_resource_output('O1', + :application => 'simple', + :environment => "production") + assert_equal 'value of O2', query_resource_output('O2', + :application => 'simple', + :environment => "production") + + end + + def test_should_raise_error_if_query_resources_that_have_not_been_provisioned_yet + assert_raises(EbDeployer::ResourceNotInReadyState) do + query_resource_output('O1', + :application => 'simple', + :environment => "production") + end + end + private + def temp_file(content) + f = Tempfile.new("foo") + f.write(content) + f + end + def eb_envname(app_name, env_name) EbDeployer::Environment.unique_ebenv_name(app_name, env_name) end + + def query_resource_output(key, opts) + EbDeployer.query_resource_output(key, {:bs_driver => @eb_driver, + :s3_driver => @s3_driver, + :cf_driver => @cf_driver}.merge(opts)) + end + + def deploy(opts) + EbDeployer.deploy({:package => @sample_package, + :bs_driver => @eb_driver, + :s3_driver => @s3_driver, + :cf_driver => @cf_driver, + :version_label => 1}.merge(opts)) + end + + + end