dpl-connect 1.8.43

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +8 -0
  4. data/.rspec +2 -0
  5. data/.travis.yml +36 -0
  6. data/Gemfile +100 -0
  7. data/LICENSE +22 -0
  8. data/README.md +934 -0
  9. data/Rakefile +1 -0
  10. data/TESTING.md +29 -0
  11. data/bin/dpl +5 -0
  12. data/dpl.gemspec +32 -0
  13. data/lib/dpl/cli.rb +66 -0
  14. data/lib/dpl/error.rb +3 -0
  15. data/lib/dpl/provider.rb +264 -0
  16. data/lib/dpl/provider/anynines.rb +13 -0
  17. data/lib/dpl/provider/appfog.rb +21 -0
  18. data/lib/dpl/provider/atlas.rb +108 -0
  19. data/lib/dpl/provider/azure_webapps.rb +48 -0
  20. data/lib/dpl/provider/bintray.rb +509 -0
  21. data/lib/dpl/provider/bitballoon.rb +22 -0
  22. data/lib/dpl/provider/bluemix_cloud_foundry.rb +23 -0
  23. data/lib/dpl/provider/boxfuse.rb +57 -0
  24. data/lib/dpl/provider/catalyze.rb +49 -0
  25. data/lib/dpl/provider/chef_supermarket.rb +85 -0
  26. data/lib/dpl/provider/cloud66.rb +38 -0
  27. data/lib/dpl/provider/cloud_files.rb +38 -0
  28. data/lib/dpl/provider/cloud_foundry.rb +43 -0
  29. data/lib/dpl/provider/code_deploy.rb +123 -0
  30. data/lib/dpl/provider/deis.rb +119 -0
  31. data/lib/dpl/provider/divshot.rb +23 -0
  32. data/lib/dpl/provider/elastic_beanstalk.rb +195 -0
  33. data/lib/dpl/provider/engine_yard.rb +90 -0
  34. data/lib/dpl/provider/firebase.rb +27 -0
  35. data/lib/dpl/provider/gae.rb +97 -0
  36. data/lib/dpl/provider/gcs.rb +59 -0
  37. data/lib/dpl/provider/hackage.rb +29 -0
  38. data/lib/dpl/provider/heroku.rb +18 -0
  39. data/lib/dpl/provider/heroku/api.rb +98 -0
  40. data/lib/dpl/provider/heroku/generic.rb +94 -0
  41. data/lib/dpl/provider/heroku/git.rb +28 -0
  42. data/lib/dpl/provider/lambda.rb +236 -0
  43. data/lib/dpl/provider/launchpad.rb +48 -0
  44. data/lib/dpl/provider/modulus.rb +23 -0
  45. data/lib/dpl/provider/npm.rb +64 -0
  46. data/lib/dpl/provider/openshift.rb +59 -0
  47. data/lib/dpl/provider/ops_works.rb +132 -0
  48. data/lib/dpl/provider/packagecloud.rb +144 -0
  49. data/lib/dpl/provider/pages.rb +79 -0
  50. data/lib/dpl/provider/puppet_forge.rb +43 -0
  51. data/lib/dpl/provider/pypi.rb +111 -0
  52. data/lib/dpl/provider/releases.rb +139 -0
  53. data/lib/dpl/provider/rubygems.rb +51 -0
  54. data/lib/dpl/provider/s3.rb +123 -0
  55. data/lib/dpl/provider/scalingo.rb +97 -0
  56. data/lib/dpl/provider/script.rb +29 -0
  57. data/lib/dpl/provider/surge.rb +33 -0
  58. data/lib/dpl/provider/testfairy.rb +190 -0
  59. data/lib/dpl/provider/transifex.rb +45 -0
  60. data/lib/dpl/version.rb +3 -0
  61. data/notes/engine_yard.md +1 -0
  62. data/notes/heroku.md +3 -0
  63. data/spec/cli_spec.rb +36 -0
  64. data/spec/provider/anynines_spec.rb +20 -0
  65. data/spec/provider/appfog_spec.rb +35 -0
  66. data/spec/provider/atlas_spec.rb +99 -0
  67. data/spec/provider/azure_webapps_spec.rb +95 -0
  68. data/spec/provider/bintray_spec.rb +259 -0
  69. data/spec/provider/bitballoon_spec.rb +32 -0
  70. data/spec/provider/bluemixcloudfoundry_spec.rb +23 -0
  71. data/spec/provider/boxfuse_spec.rb +16 -0
  72. data/spec/provider/catalyze_spec.rb +39 -0
  73. data/spec/provider/chef_supermarket_spec.rb +51 -0
  74. data/spec/provider/cloud66_spec.rb +44 -0
  75. data/spec/provider/cloud_files_spec.rb +88 -0
  76. data/spec/provider/cloudfoundry_spec.rb +71 -0
  77. data/spec/provider/code_deploy_spec.rb +360 -0
  78. data/spec/provider/deis_spec.rb +116 -0
  79. data/spec/provider/divshot_spec.rb +28 -0
  80. data/spec/provider/elastic_beanstalk_spec.rb +209 -0
  81. data/spec/provider/firebase_spec.rb +40 -0
  82. data/spec/provider/gae_spec.rb +26 -0
  83. data/spec/provider/gcs_spec.rb +115 -0
  84. data/spec/provider/hackage_spec.rb +47 -0
  85. data/spec/provider/heroku_spec.rb +357 -0
  86. data/spec/provider/lambda_spec.rb +432 -0
  87. data/spec/provider/launchpad_spec.rb +33 -0
  88. data/spec/provider/modulus_spec.rb +29 -0
  89. data/spec/provider/npm_spec.rb +95 -0
  90. data/spec/provider/openshift_spec.rb +91 -0
  91. data/spec/provider/ops_works_spec.rb +127 -0
  92. data/spec/provider/packagecloud_spec.rb +56 -0
  93. data/spec/provider/puppet_forge_spec.rb +60 -0
  94. data/spec/provider/pypi_spec.rb +103 -0
  95. data/spec/provider/releases_spec.rb +303 -0
  96. data/spec/provider/rubygems_spec.rb +106 -0
  97. data/spec/provider/s3_spec.rb +174 -0
  98. data/spec/provider/scalingo_spec.rb +64 -0
  99. data/spec/provider/script_spec.rb +26 -0
  100. data/spec/provider/surge_spec.rb +15 -0
  101. data/spec/provider/testfairy_spec.rb +86 -0
  102. data/spec/provider/transifex_spec.rb +110 -0
  103. data/spec/provider_spec.rb +210 -0
  104. data/spec/spec_helper.rb +20 -0
  105. metadata +279 -0
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ require 'dpl/provider/bitballoon'
3
+
4
+ describe DPL::Provider::BitBalloon do
5
+ subject :provider do
6
+ described_class.new(DummyContext.new,{})
7
+ end
8
+
9
+ describe "#needs_key?" do
10
+ example do
11
+ expect(provider.needs_key?).to eq(false)
12
+ end
13
+ end
14
+
15
+ describe "#push_app" do
16
+ example "Without optional parameters" do
17
+ expect(provider.context).to receive(:shell).with("bitballoon deploy")
18
+ provider.push_app
19
+ end
20
+
21
+ example "With optional parameters" do
22
+ provider.options.update(local_dir: 'build')
23
+ provider.options.update(access_token:'fake-access-token')
24
+ provider.options.update(site_id:'fake-site')
25
+
26
+ expected_command = "bitballoon deploy ./build --site-id=fake-site --access-token=fake-access-token"
27
+
28
+ expect(provider.context).to receive(:shell).with(expected_command)
29
+ provider.push_app
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+ require 'dpl/provider/bluemix_cloud_foundry'
3
+
4
+ describe DPL::Provider::BluemixCloudFoundry do
5
+ subject :provider do
6
+ described_class.new(DummyContext.new, region: 'eu-gb', username: 'Moonpie',
7
+ password: 'myexceptionallyaveragepassword',
8
+ organization: 'myotherorg',
9
+ space: 'inner',
10
+ manifest: 'worker-manifest.yml',
11
+ skip_ssl_validation: true)
12
+ end
13
+
14
+ describe "#check_auth" do
15
+ example do
16
+ expect(provider.context).to receive(:shell).with('test x$TRAVIS_OS_NAME = "xlinux" && rel="linux64-binary" || rel="macosx64"; wget "https://cli.run.pivotal.io/stable?release=${rel}&source=github" -qO cf.tgz && tar -zxvf cf.tgz && rm cf.tgz')
17
+ expect(provider.context).to receive(:shell).with('./cf api api.eu-gb.bluemix.net --skip-ssl-validation')
18
+ expect(provider.context).to receive(:shell).with('./cf login -u Moonpie -p myexceptionallyaveragepassword -o myotherorg -s inner')
19
+ provider.check_auth
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+ require 'dpl/provider/boxfuse'
3
+
4
+ describe DPL::Provider::Boxfuse do
5
+ subject :provider do
6
+ described_class.new(DummyContext.new, :user => 'dummyuser', :image => 'abc:123')
7
+ end
8
+
9
+ describe "#deploy" do
10
+ example do
11
+ expect(provider.context).to receive(:shell).with('curl -L https://files.boxfuse.com/com/boxfuse/client/boxfuse-commandline/latest/boxfuse-commandline-latest-linux-x64.tar.gz | tar xz')
12
+ expect(provider.context).to receive(:shell).with('boxfuse/boxfuse run -user=dummyuser -image=abc:123 -env=test')
13
+ provider.deploy
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+ require 'dpl/provider/catalyze'
3
+
4
+ describe DPL::Provider::Catalyze do
5
+ subject :provider do
6
+ described_class.new(DummyContext.new, :target => 'test-target', :path => 'test-path')
7
+ end
8
+
9
+ describe "#check_auth" do
10
+ it 'should require a target' do
11
+ provider.options.update(:target => nil)
12
+ expect{ provider.check_auth }.to raise_error("Missing Catalyze target")
13
+ end
14
+ end
15
+
16
+ describe "#push_app" do
17
+ it 'should push the current branch to the target' do
18
+ expect(provider.context).to receive(:shell).with("git push --force test-target HEAD:master")
19
+ provider.push_app
20
+ end
21
+ it 'should add and commit local build files if skip_cleanup is true' do
22
+ provider.options.update(:skip_cleanup => true)
23
+ expect(provider.context).to receive(:shell).with("git checkout HEAD")
24
+ expect(provider.context).to receive(:shell).with("git add test-path --all --force")
25
+ expect(provider.context).to receive(:shell).with("git commit -m \"Local build\" --quiet")
26
+ expect(provider.context).to receive(:shell).with("git push --force test-target HEAD:master")
27
+ provider.push_app
28
+ end
29
+ it 'should use a path of "." if the path is not specified' do
30
+ provider.options.update(:path => nil)
31
+ provider.options.update(:skip_cleanup => true)
32
+ expect(provider.context).to receive(:shell).with("git checkout HEAD")
33
+ expect(provider.context).to receive(:shell).with("git add . --all --force")
34
+ expect(provider.context).to receive(:shell).with("git commit -m \"Local build\" --quiet")
35
+ expect(provider.context).to receive(:shell).with("git push --force test-target HEAD:master")
36
+ provider.push_app
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+ require 'chef/cookbook_loader'
3
+ require 'chef/cookbook_uploader'
4
+ require 'dpl/provider/chef_supermarket'
5
+
6
+ describe DPL::Provider::ChefSupermarket do
7
+ subject :provider do
8
+ described_class.new(
9
+ DummyContext.new,
10
+ app: 'example',
11
+ cookbook_category: 'Others',
12
+ user_id: 'user',
13
+ client_key: '/tmp/example.pem'
14
+ )
15
+ end
16
+
17
+ let(:cookbook_uploader) do
18
+ double('cookbook_uploader', validate_cookbooks: true)
19
+ end
20
+
21
+ let(:http_resp) do
22
+ double('http_resp', body: '{}', code: '201')
23
+ end
24
+
25
+ describe "#check_auth" do
26
+ example do
27
+ ::File.stub(:exist?).and_return(true)
28
+ expect(File).to receive(:exist?)
29
+ provider.check_auth
30
+ end
31
+ end
32
+
33
+ describe "#check_app" do
34
+ example do
35
+ ::Chef::CookbookLoader.any_instance.stub(:[]).and_return nil
36
+ expect(::Chef::CookbookUploader).to receive(:new).and_return(cookbook_uploader)
37
+ provider.check_app
38
+ end
39
+ end
40
+
41
+ describe "#push_app" do
42
+ example do
43
+ expect(::Chef::CookbookSiteStreamingUploader).to receive(:create_build_dir).and_return('/tmp/build_dir')
44
+ expect(provider).to receive(:system).and_return(true)
45
+ expect(::File).to receive(:open)
46
+ expect(::Chef::CookbookSiteStreamingUploader).to receive(:post).and_return(http_resp)
47
+ expect(::FileUtils).to receive(:rm_rf).with('/tmp/build_dir')
48
+ provider.push_app
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+ require 'dpl/provider/cloud66'
3
+
4
+ describe DPL::Provider::Cloud66 do
5
+ subject :provider do
6
+ described_class.new(DummyContext.new, options)
7
+ end
8
+
9
+ let(:successful_response){ double(code: '200') }
10
+ let(:not_found_response){ double(code: '404') }
11
+ let(:options){ {} }
12
+
13
+ describe "#push_app" do
14
+ context 'with a successful response' do
15
+ let(:options){ {:redeployment_hook => 'https://hooks.cloud66.com/stacks/redeploy/0101010101010101'} }
16
+
17
+ example do
18
+ expect(provider).to receive(:webhook_call).with('https', 'hooks.cloud66.com', 443, '/stacks/redeploy/0101010101010101').and_return(successful_response)
19
+ provider.push_app
20
+ end
21
+ end
22
+
23
+ context 'with a 404 response' do
24
+ let(:options){ {:redeployment_hook => 'https://hooks.cloud66.com/stacks/redeploy/0101010101010101'} }
25
+
26
+ it 'should raise an error' do
27
+ expect(provider).to receive(:webhook_call).with('https', 'hooks.cloud66.com', 443, '/stacks/redeploy/0101010101010101').and_return(not_found_response)
28
+ expect { provider.push_app }.to raise_error(DPL::Error, "Redeployment failed [404]")
29
+ end
30
+ end
31
+
32
+ context 'with missing redeployment_hook option' do
33
+ it 'should raise an error' do
34
+ expect { provider.push_app }.to raise_error(DPL::Error, "missing redeployment_hook")
35
+ end
36
+ end
37
+ end
38
+
39
+ describe "#needs_key?" do
40
+ example do
41
+ expect(provider.needs_key?).to eq(false)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+ require 'dpl/provider/cloud_files'
3
+ require 'fog'
4
+
5
+ describe DPL::Provider::CloudFiles do
6
+ before :each do
7
+ Fog.mock!
8
+ end
9
+
10
+ subject :provider do
11
+ described_class.new(DummyContext.new, :username => 'username', :api_key => 'api key', :container => 'travis', :region => 'dfw')
12
+ end
13
+
14
+ describe "#needs_key?" do
15
+ example do
16
+ expect(provider.needs_key?).to eq(false)
17
+ end
18
+ end
19
+
20
+ describe "#api" do
21
+ example do
22
+ expect(Fog::Storage).to receive(:new).with(:provider => 'Rackspace', :rackspace_username => 'username', :rackspace_api_key => 'api key', :rackspace_region => 'dfw')
23
+
24
+ provider.api
25
+ end
26
+ end
27
+
28
+ describe "#check_auth" do
29
+ example do
30
+ expect(provider).to receive(:log).with('Authenticated as username')
31
+
32
+ provider.check_auth
33
+ end
34
+ end
35
+
36
+ describe "#push_app" do
37
+ let :files do
38
+ files = double
39
+
40
+ directory = double
41
+ allow(directory).to receive(:files) { files }
42
+
43
+ directories = double
44
+ expect(directories).to receive(:get).with('travis').and_return(directory)
45
+
46
+ service = double(:service)
47
+ allow(service).to receive(:directories) { directories }
48
+ allow(provider).to receive(:api) { service }
49
+
50
+ files
51
+ end
52
+
53
+ example do
54
+ expect(files).to receive(:create).with(:key => 'a', :body => 'a body')
55
+ expect(files).to receive(:create).with(:key => 'b', :body => 'b body')
56
+ expect(files).to receive(:create).with(:key => 'c', :body => 'c body')
57
+
58
+ expect(Dir).to receive(:glob).with('**/*').and_return(['a', 'b', 'c'])
59
+ allow(File).to receive(:open) { |name| "#{name} body" }
60
+
61
+ provider.push_app
62
+ end
63
+
64
+ example "with dot_match option" do
65
+ provider.options.update(:dot_match => true)
66
+ expect(files).to receive(:create).with(:key => '.a', :body => '.a body')
67
+ expect(files).to receive(:create).with(:key => 'a', :body => 'a body')
68
+
69
+ expect(Dir).to receive(:glob).with('**/*', File::FNM_DOTMATCH).and_return(['.a', 'a'])
70
+ allow(File).to receive(:open) { |name| "#{name} body" }
71
+
72
+ provider.push_app
73
+ end
74
+ end
75
+
76
+ describe "#deploy" do
77
+ example 'Not Found' do
78
+ directories = double
79
+ allow(directories).to receive(:get) { nil }
80
+
81
+ service = double(:service)
82
+ allow(service).to receive(:directories) { directories }
83
+ allow(provider).to receive(:api) { service }
84
+
85
+ expect { provider.deploy }.to raise_error(DPL::Error, 'The specified container does not exist.')
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+ require 'dpl/provider/cloud_foundry'
3
+
4
+ describe DPL::Provider::CloudFoundry do
5
+ subject :provider do
6
+ described_class.new(DummyContext.new, api: 'api.run.awesome.io', username: 'mallomar',
7
+ password: 'myreallyawesomepassword',
8
+ organization: 'myorg',
9
+ space: 'outer',
10
+ manifest: 'worker-manifest.yml',
11
+ skip_ssl_validation: true)
12
+ end
13
+
14
+ describe "#check_auth" do
15
+ example do
16
+ expect(provider.context).to receive(:shell).with('test x$TRAVIS_OS_NAME = "xlinux" && rel="linux64-binary" || rel="macosx64"; wget "https://cli.run.pivotal.io/stable?release=${rel}&source=github" -qO cf.tgz && tar -zxvf cf.tgz && rm cf.tgz')
17
+ expect(provider.context).to receive(:shell).with('./cf api api.run.awesome.io --skip-ssl-validation')
18
+ expect(provider.context).to receive(:shell).with('./cf login -u mallomar -p myreallyawesomepassword -o myorg -s outer')
19
+ provider.check_auth
20
+ end
21
+ end
22
+
23
+ describe "#check_app" do
24
+ context 'when the manifest file exists' do
25
+ example do
26
+ File.stub(:exists?).with('worker-manifest.yml').and_return(true)
27
+ expect{provider.check_app}.not_to raise_error
28
+ end
29
+ end
30
+
31
+ context 'when the manifest file exists' do
32
+ example do
33
+ File.stub(:exists?).with('worker-manifest.yml').and_return(false)
34
+ expect{provider.check_app}.to raise_error('Application must have a manifest.yml for unattended deployment')
35
+ end
36
+ end
37
+ end
38
+
39
+ describe "#needs_key?" do
40
+ example do
41
+ expect(provider.needs_key?).to eq(false)
42
+ end
43
+ end
44
+
45
+ describe "#push_app" do
46
+ before do
47
+ allow(provider.context).to receive(:shell).and_return(true)
48
+ end
49
+
50
+ example "With manifest" do
51
+ expect(provider.context).to receive(:shell).with('./cf push -f worker-manifest.yml')
52
+ expect(provider.context).to receive(:shell).with('./cf logout')
53
+ provider.push_app
54
+ end
55
+
56
+ example "Without manifest" do
57
+ provider.options.update(:manifest => nil)
58
+ expect(provider.context).to receive(:shell).with('./cf push')
59
+ expect(provider.context).to receive(:shell).with('./cf logout')
60
+ provider.push_app
61
+ end
62
+
63
+ example 'Failed to push' do
64
+ allow(provider.context).to receive(:shell).and_return(false)
65
+
66
+ expect(provider.context).to receive(:shell).with('./cf push -f worker-manifest.yml')
67
+ expect(provider.context).to receive(:shell).with('./cf logout')
68
+ expect{provider.push_app}.to raise_error(DPL::Error, 'Failed to push app')
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,360 @@
1
+ require 'spec_helper'
2
+ require 'aws-sdk'
3
+ require 'dpl/error'
4
+ require 'dpl/provider'
5
+ require 'dpl/provider/code_deploy'
6
+
7
+ describe DPL::Provider::CodeDeploy do
8
+
9
+ subject :provider do
10
+ described_class.new(DummyContext.new, :access_key_id => 'qwertyuiopasdfghjklz', :secret_access_key => 'qwertyuiopasdfghjklzqwertyuiopasdfghjklz')
11
+ end
12
+
13
+ describe '#code_deploy_options' do
14
+ context 'without region' do
15
+ example do
16
+ options = provider.code_deploy_options
17
+ expect(options[:region]).to eq('us-east-1')
18
+ end
19
+ end
20
+
21
+ context 'with region' do
22
+ example do
23
+ region = 'us-west-1'
24
+ provider.options.update(:region => region)
25
+ options = provider.code_deploy_options
26
+ expect(options[:region]).to eq(region)
27
+ end
28
+ end
29
+
30
+ context 'without endpoint' do
31
+ example do
32
+ options = provider.code_deploy_options
33
+ expect(options[:endpoint]).to eq(nil)
34
+ end
35
+ end
36
+
37
+ context 'with endpoint' do
38
+ example do
39
+ endpoint = 's3test.com.s3-website-us-west-2.amazonaws.com'
40
+ provider.options.update(:endpoint => endpoint)
41
+ options = provider.code_deploy_options
42
+ expect(options[:endpoint]).to eq(endpoint)
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ describe DPL::Provider::CodeDeploy do
49
+ access_key_id = 'someaccesskey'
50
+ secret_access_key = 'somesecretaccesskey'
51
+ application = 'app'
52
+ deployment_group = 'group'
53
+ description = 'description'
54
+ revision = '23jkljkl'
55
+ client_options = {
56
+ :stub_responses => true,
57
+ :region => 'us-east-1',
58
+ :credentials => ::Aws::Credentials.new(access_key_id, secret_access_key),
59
+ :endpoint => 'https://codedeploy.us-east-1.amazonaws.com'
60
+ }
61
+
62
+ subject :provider do
63
+ described_class.new(DummyContext.new, {
64
+ :access_key_id => access_key_id,
65
+ :secret_access_key => secret_access_key
66
+ })
67
+ end
68
+
69
+ before :each do
70
+ provider.stub(:code_deploy_options).and_return(client_options)
71
+ end
72
+
73
+ describe '#code_deploy' do
74
+ example do
75
+ expect(::Aws::CodeDeploy::Client).to receive(:new).with(client_options).once
76
+ provider.code_deploy
77
+ end
78
+ end
79
+
80
+ describe '#needs_key?' do
81
+ example do
82
+ expect(provider.needs_key?).to eq(false)
83
+ end
84
+ end
85
+
86
+ describe '#revision' do
87
+ expected_s3_revision = {
88
+ revision_type: 'S3',
89
+ s3_location: {
90
+ bucket: 'bucket',
91
+ bundle_type: 'tar',
92
+ key: 'key'
93
+ }
94
+ }
95
+
96
+ expected_github_revision = {
97
+ revision_type: 'GitHub',
98
+ git_hub_location: {
99
+ commit_id: '2lk3j4k2j3k4j23k4j',
100
+ repository: 'travis-ci/dpl'
101
+ }
102
+ }
103
+
104
+ before(:each) do
105
+ provider.stub(:s3_revision).and_return(expected_s3_revision)
106
+ provider.stub(:github_revision).and_return(expected_github_revision)
107
+ end
108
+
109
+ context 'when s3' do
110
+ before do
111
+ provider.options.update(:revision_type => :s3)
112
+ end
113
+
114
+ example do
115
+ expect(provider.revision).to eq(expected_s3_revision)
116
+ end
117
+ end
118
+
119
+ context 'when github' do
120
+ before do
121
+ provider.options.update(:revision_type => :github)
122
+ end
123
+
124
+ example do
125
+ expect(provider.revision).to eq(expected_github_revision)
126
+ end
127
+ end
128
+
129
+ context 'when not specified' do
130
+ before do
131
+ provider.options.update(:bucket => 'bucket')
132
+ end
133
+
134
+ example do
135
+ expect(provider.revision).to eq(expected_s3_revision)
136
+ end
137
+ end
138
+
139
+ context 'when revision and bucket are not specified' do
140
+ example do
141
+ expect(provider.revision).to eq(expected_github_revision)
142
+ end
143
+ end
144
+
145
+ context 'when not a known revision type' do
146
+ type = :bad
147
+
148
+ before do
149
+ provider.options.update(:revision_type => type)
150
+ end
151
+
152
+ example do
153
+ expect(provider).to receive(:error).with(/unknown revision type :#{type}/)
154
+ provider.revision
155
+ end
156
+ end
157
+ end
158
+
159
+ describe '#s3_revision' do
160
+ bucket = 'bucket'
161
+ bundle_type = 'tar'
162
+ key = "/some/key.#{bundle_type}"
163
+
164
+ before(:each) do
165
+ expect(provider).to receive(:option).with(:bucket).and_return(bucket)
166
+ expect(provider).to receive(:bundle_type).and_return(bundle_type)
167
+ expect(provider).to receive(:s3_key).and_return(key)
168
+ end
169
+
170
+ example do
171
+ expect(provider.s3_revision).to eq({
172
+ revision_type: 'S3',
173
+ s3_location: {
174
+ bucket: bucket,
175
+ bundle_type: bundle_type,
176
+ key: key
177
+ }
178
+ })
179
+ end
180
+ end
181
+
182
+ describe '#github_revision' do
183
+ commit_id = '432s35s3'
184
+ repository = 'git@github.com/org/repo.git'
185
+
186
+ context 'with options set' do
187
+ before(:each) do
188
+ expect(provider.options).to receive(:[]).with(:commit_id).and_return(commit_id)
189
+ expect(provider.options).to receive(:[]).with(:repository).and_return(repository)
190
+ end
191
+
192
+ example do
193
+ expect(provider.github_revision).to eq({
194
+ revision_type: 'GitHub',
195
+ git_hub_location: {
196
+ commit_id: commit_id,
197
+ repository: repository
198
+ }
199
+ })
200
+ end
201
+ end
202
+
203
+ context 'with environment variables' do
204
+ before(:each) do
205
+ expect(provider.options).to receive(:[]).with(:commit_id).and_return(nil)
206
+ expect(provider.options).to receive(:[]).with(:repository).and_return(nil)
207
+ expect(provider.context.env).to receive(:[]).with('TRAVIS_COMMIT').and_return(commit_id)
208
+ expect(provider.context.env).to receive(:[]).with('TRAVIS_REPO_SLUG').and_return(repository)
209
+ end
210
+
211
+ example do
212
+ expect(provider.github_revision).to eq({
213
+ revision_type: 'GitHub',
214
+ git_hub_location: {
215
+ commit_id: commit_id,
216
+ repository: repository
217
+ }
218
+ })
219
+ end
220
+ end
221
+
222
+ context 'without required options' do
223
+ before(:each) do
224
+ expect(provider.options).to receive(:[]).with(:commit_id).and_return(nil)
225
+ provider.options.stub(:[]).with(:repository) { nil }
226
+ expect(provider.context.env).to receive(:[]).with('TRAVIS_COMMIT').and_return(nil)
227
+ expect(provider.context.env).to receive(:[]).with('TRAVIS_REPO_SLUG').and_return(nil)
228
+ end
229
+
230
+ example do
231
+ expect{provider.github_revision}.to raise_error(DPL::Error)
232
+ end
233
+ end
234
+ end
235
+
236
+ describe '#push_app' do
237
+ before(:each) do
238
+ old_options = provider.options
239
+ provider.stub(:options) {old_options.merge({
240
+ :application_name => application,
241
+ :deployment_group_name => deployment_group,
242
+ :description => description,
243
+ :repository => 'git@github.com:travis-ci/dpl.git'
244
+ })}
245
+ end
246
+
247
+ context 'without an error' do
248
+ deployment_id = 'some-deployment-id'
249
+
250
+ before do
251
+ provider.code_deploy.stub_responses(:create_deployment, :deployment_id => deployment_id)
252
+ end
253
+
254
+ example do
255
+ expect(provider).to receive(:log).with(/Triggered deployment \"#{deployment_id}\"\./)
256
+ provider.push_app
257
+ end
258
+
259
+ before do
260
+ allow(provider.code_deploy).to receive(:get_deployment).and_return(
261
+ {:deployment_info => {:status => "Created"}},
262
+ {:deployment_info => {:status => "Queued"}},
263
+ {:deployment_info => {:status => "InProgress"}},
264
+ {:deployment_info => {:status => "Succeeded"}})
265
+ end
266
+
267
+ example 'with :wait_until_deployed' do
268
+ old_options = provider.options
269
+ provider.stub(:options) {old_options.merge({
270
+ app_id: 'app-id',
271
+ wait_until_deployed: true})}
272
+ expect(provider).to receive(:log).with(/Triggered deployment \"#{deployment_id}\"\./)
273
+ expect(provider).to receive(:log).with(/Deployment successful./)
274
+ provider.push_app
275
+ end
276
+ end
277
+
278
+ context 'with an error' do
279
+ before do
280
+ provider.code_deploy.stub_responses(:create_deployment, 'DeploymentLimitExceededException')
281
+ end
282
+
283
+ example do
284
+ expect(provider).to receive(:error).once
285
+ provider.push_app
286
+ end
287
+ end
288
+ end
289
+
290
+ describe '#bundle_type' do
291
+ context 'with s3_key' do
292
+ format = 'zip'
293
+ s3_key = "/some/key/name.#{format}"
294
+
295
+ before(:each) do
296
+ expect(provider).to receive(:s3_key).and_return(s3_key)
297
+ end
298
+
299
+ example do
300
+ expect(provider.bundle_type).to eq(format)
301
+ end
302
+ end
303
+
304
+ context 'without s3_key' do
305
+ bundle_type = 'tar'
306
+
307
+ before do
308
+ expect(provider).to receive(:s3_key).and_return('')
309
+ expect(provider).to receive(:option).with(:bundle_type).and_return(bundle_type)
310
+ end
311
+
312
+ example do
313
+ expect(provider.bundle_type).to eq(bundle_type)
314
+ end
315
+ end
316
+ end
317
+
318
+ describe '#s3_key' do
319
+ key = '/some/key/name.zip'
320
+
321
+ context 'with key option' do
322
+ before do
323
+ expect(provider.options).to receive(:[]).with(:key).and_return(key)
324
+ end
325
+
326
+ example do
327
+ expect(provider.s3_key).to eq(key)
328
+ end
329
+ end
330
+
331
+ context 'with s3_key option' do
332
+ before do
333
+ expect(provider).to receive(:option).with(:s3_key).and_return(key)
334
+ end
335
+
336
+ example do
337
+ expect(provider.s3_key).to eq(key)
338
+ end
339
+ end
340
+ end
341
+
342
+ describe '#default_description' do
343
+ build_number = 2
344
+
345
+ before do
346
+ provider.context.env.stub(:[]).with('TRAVIS_BUILD_NUMBER').and_return(build_number)
347
+ end
348
+
349
+ example do
350
+ expect(provider.default_description).to eq("Deploy build #{build_number} via Travis CI")
351
+ end
352
+ end
353
+
354
+ describe '#check_auth' do
355
+ example do
356
+ expect(provider).to receive(:log).with("Logging in with Access Key: #{access_key_id[-4..-1].rjust(20, '*')}")
357
+ provider.check_auth
358
+ end
359
+ end
360
+ end