ey-core 3.4.4 → 3.6.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +5 -5
  2. data/.ruby-version +1 -1
  3. data/CHANGELOG.md +27 -5
  4. data/Gemfile +1 -2
  5. data/README.md +65 -8
  6. data/ey-core.gemspec +6 -5
  7. data/features/docker_registry_credentials.feature +21 -0
  8. data/features/environment_variables.feature +54 -0
  9. data/features/step_definitions/accounts_steps.rb +14 -0
  10. data/features/step_definitions/applications_steps.rb +7 -14
  11. data/features/step_definitions/docker_registry_credentials_steps.rb +3 -0
  12. data/features/step_definitions/environment_variables_steps.rb +51 -0
  13. data/features/step_definitions/environments_steps.rb +15 -0
  14. data/features/support/environment_variable_helpers.rb +20 -0
  15. data/features/support/mock_api.rb +0 -1
  16. data/features/support/resource_helpers.rb +12 -0
  17. data/lib/ey-core/cli/deploy.rb +12 -9
  18. data/lib/ey-core/cli/docker_registry_login.rb +29 -0
  19. data/lib/ey-core/cli/environment_variables.rb +71 -0
  20. data/lib/ey-core/cli/helpers/chef.rb +1 -1
  21. data/lib/ey-core/cli/helpers/core.rb +32 -3
  22. data/lib/ey-core/cli/helpers/server_sieve.rb +7 -0
  23. data/lib/ey-core/cli/main.rb +5 -4
  24. data/lib/ey-core/cli/servers.rb +35 -17
  25. data/lib/ey-core/cli/ssh.rb +6 -0
  26. data/lib/ey-core/client/mock.rb +4 -0
  27. data/lib/ey-core/client.rb +27 -0
  28. data/lib/ey-core/collections/auto_scaling_alarms.rb +8 -0
  29. data/lib/ey-core/collections/auto_scaling_policies.rb +33 -0
  30. data/lib/ey-core/collections/container_clusters.rb +9 -0
  31. data/lib/ey-core/collections/container_service_deployments.rb +17 -0
  32. data/lib/ey-core/collections/environment_variables.rb +8 -0
  33. data/lib/ey-core/models/account.rb +10 -0
  34. data/lib/ey-core/models/address.rb +2 -0
  35. data/lib/ey-core/models/application.rb +1 -0
  36. data/lib/ey-core/models/auto_scaling_alarm.rb +54 -0
  37. data/lib/ey-core/models/auto_scaling_group.rb +26 -0
  38. data/lib/ey-core/models/base_auto_scaling_policy.rb +61 -0
  39. data/lib/ey-core/models/container_service_deployment.rb +17 -0
  40. data/lib/ey-core/models/deployment.rb +1 -0
  41. data/lib/ey-core/models/environment.rb +53 -47
  42. data/lib/ey-core/models/environment_variable.rb +29 -0
  43. data/lib/ey-core/models/request.rb +4 -0
  44. data/lib/ey-core/models/simple_auto_scaling_policy.rb +24 -0
  45. data/lib/ey-core/models/step_auto_scaling_policy.rb +24 -0
  46. data/lib/ey-core/models/target_auto_scaling_policy.rb +24 -0
  47. data/lib/ey-core/requests/create_account.rb +5 -0
  48. data/lib/ey-core/requests/create_address.rb +1 -0
  49. data/lib/ey-core/requests/create_application.rb +8 -7
  50. data/lib/ey-core/requests/create_auto_scaling_alarm.rb +69 -0
  51. data/lib/ey-core/requests/create_auto_scaling_policy.rb +68 -0
  52. data/lib/ey-core/requests/create_environment.rb +2 -1
  53. data/lib/ey-core/requests/create_environment_variable.rb +39 -0
  54. data/lib/ey-core/requests/create_user.rb +8 -6
  55. data/lib/ey-core/requests/deploy_environment_application.rb +1 -0
  56. data/lib/ey-core/requests/destroy_auto_scaling_alarm.rb +49 -0
  57. data/lib/ey-core/requests/destroy_auto_scaling_policy.rb +49 -0
  58. data/lib/ey-core/requests/discover_container_service_deployments.rb +71 -0
  59. data/lib/ey-core/requests/get_applications.rb +1 -1
  60. data/lib/ey-core/requests/get_auto_scaling_alarm.rb +27 -0
  61. data/lib/ey-core/requests/get_auto_scaling_alarms.rb +34 -0
  62. data/lib/ey-core/requests/get_auto_scaling_policies.rb +46 -0
  63. data/lib/ey-core/requests/get_auto_scaling_policy.rb +27 -0
  64. data/lib/ey-core/requests/get_deployments.rb +1 -1
  65. data/lib/ey-core/requests/get_environment_variable.rb +19 -0
  66. data/lib/ey-core/requests/get_environment_variables.rb +29 -0
  67. data/lib/ey-core/requests/get_environments.rb +1 -1
  68. data/lib/ey-core/requests/get_ssl_certificate.rb +1 -1
  69. data/lib/ey-core/requests/retrieve_docker_registry_credentials.rb +24 -0
  70. data/lib/ey-core/requests/update_auto_scaling_alarm.rb +45 -0
  71. data/lib/ey-core/requests/update_auto_scaling_policy.rb +46 -0
  72. data/lib/ey-core/requests/update_environment_variable.rb +25 -0
  73. data/lib/ey-core/test_helpers/auto_scaling_helpers.rb +35 -0
  74. data/lib/ey-core/test_helpers.rb +2 -0
  75. data/lib/ey-core/version.rb +1 -1
  76. data/spec/addresses_spec.rb +2 -1
  77. data/spec/auto_scaling_alarms_spec.rb +40 -0
  78. data/spec/auto_scaling_policies_spec.rb +94 -0
  79. data/spec/docker_registry_credentials_spec.rb +16 -0
  80. data/spec/spec_helper.rb +7 -0
  81. data/spec/support/core.rb +0 -2
  82. metadata +78 -18
@@ -0,0 +1,71 @@
1
+ class Ey::Core::Client
2
+ class Real
3
+ def discover_container_service_deployments(params={})
4
+ url = params.delete("url")
5
+
6
+ request(
7
+ :method => :get,
8
+ :url => url,
9
+ :params => params,
10
+ :path => "/container_service_deployments/discover",
11
+ )
12
+ end
13
+ end
14
+
15
+ class Mock
16
+ def discover_container_service_deployments(params={})
17
+ extract_url_params!(params)
18
+
19
+ callback_url = params.delete("callback_url")
20
+ deployment_id = self.uuid
21
+ resource_id = self.uuid
22
+
23
+ existing_deploymens = self.data[:container_service_deployments].values.select do |deployment|
24
+ deployment["container_service_id"] == container_service["id"]
25
+ end
26
+ existing_deploymens = nil if existing_deploymens.empty?
27
+
28
+ resources = existing_deploymens || [{
29
+ "id" => deployment_id,
30
+ "container_service_id" => params["container_service_id"],
31
+ "public_ip_address" => "123.456.789.123",
32
+ "private_ip_address" => "10.0.1.2",
33
+ "container_instance_id" => SecureRandom.uuid,
34
+ "port_mappings" => [{
35
+ "container_port" => "80",
36
+ "host_port" => "80",
37
+ "protocol" => "tcp"
38
+ }],
39
+ "provisioned_id" => resource_id,
40
+ "health_status" => "HEALTHY",
41
+ "task_arn" => SecureRandom.uuid,
42
+ "container_health_status" => [{
43
+ "container_arn" => SecureRandom.uuid,
44
+ "health_status" => SecureRandom.uuid
45
+ }]
46
+ }]
47
+
48
+ request = {
49
+ "id" => request_id,
50
+ "type" => "discover_container_service_deployments",
51
+ "successful" => true,
52
+ "started_at" => Time.now,
53
+ "finished_at" => nil,
54
+ "resource" => [:container_service_deployments, resource_id, resources, "/container_service_deployments"]
55
+ }
56
+
57
+ self.data[:container_service_deployments][deployment_id] = request
58
+
59
+ response_hash = request.dup
60
+ response_hash.delete("resource")
61
+
62
+ response(
63
+ :body => {"request" => response_hash},
64
+ :status => 200,
65
+ :headers => {
66
+ "Content-Type" => "application/json; charset=utf8"
67
+ }
68
+ )
69
+ end
70
+ end
71
+ end
@@ -17,7 +17,7 @@ class Ey::Core::Client
17
17
  def get_applications(params={})
18
18
  extract_url_params!(params)
19
19
 
20
- headers, applications_page = search_and_page(params, :applications, search_keys: %w[type repository account name environment])
20
+ headers, applications_page = search_and_page(params, :applications, search_keys: %w[id type repository account name environment])
21
21
 
22
22
  response(
23
23
  :body => {"applications" => applications_page},
@@ -0,0 +1,27 @@
1
+ class Ey::Core::Client
2
+ class Real
3
+ def get_auto_scaling_alarm(params = {})
4
+ id = params["id"]
5
+ url = params["url"]
6
+
7
+ request(
8
+ :method => :get,
9
+ :path => "auto_scaling_alarms/#{id}",
10
+ :url => url
11
+ )
12
+ end
13
+ end
14
+
15
+ class Mock
16
+ def get_auto_scaling_alarm(params = {})
17
+ response(
18
+ :body => {
19
+ "auto_scaling_alarm" => self.find(
20
+ :auto_scaling_alarms,
21
+ resource_identity(params)
22
+ )
23
+ },
24
+ )
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,34 @@
1
+ class Ey::Core::Client
2
+ class Real
3
+ def get_auto_scaling_alarms(params = {})
4
+ query = Ey::Core.paging_parameters(params)
5
+ url = params.delete("url")
6
+
7
+ request(
8
+ :params => params,
9
+ :path => "/auto_scaling_alarms",
10
+ :query => params,
11
+ :url => url,
12
+ )
13
+ end
14
+ end
15
+
16
+ class Mock
17
+ def get_auto_scaling_alarms(params = {})
18
+ extract_url_params!(params)
19
+
20
+ headers, auto_scaling_alarms_page = search_and_page(
21
+ params,
22
+ :auto_scaling_alarms,
23
+ search_keys: %w{ id auto_scaling_policy },
24
+ resources: data[:auto_scaling_alarms]
25
+ )
26
+
27
+ response(
28
+ :body => { "auto_scaling_alarms" => auto_scaling_alarms_page },
29
+ :status => 200,
30
+ :headers => headers
31
+ )
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,46 @@
1
+ class Ey::Core::Client
2
+ class Real
3
+ def get_auto_scaling_policies(params = {})
4
+ query = Ey::Core.paging_parameters(params)
5
+ url = params.delete("url")
6
+
7
+ request(
8
+ :params => params,
9
+ :path => "/auto_scaling_policies",
10
+ :query => params,
11
+ :url => url,
12
+ )
13
+ end
14
+ end
15
+
16
+ class Mock
17
+ def get_auto_scaling_policies(params = {})
18
+ extract_url_params!(params)
19
+
20
+ resources = data[:auto_scaling_policies].select { |_key, policy| filter_policy(params, policy) }
21
+ params.delete("types")
22
+
23
+ headers, auto_scaling_policies_page = search_and_page(
24
+ params,
25
+ :auto_scaling_policies,
26
+ search_keys: %w{ id auto_scaling_group },
27
+ resources: resources
28
+ )
29
+
30
+ response(
31
+ :body => { "auto_scaling_policies" => auto_scaling_policies_page },
32
+ :status => 200,
33
+ :headers => headers
34
+ )
35
+ end
36
+
37
+ private
38
+
39
+ def filter_policy(params, item)
40
+ return false if params["auto_scaling_group"] != item["auto_scaling_group"]
41
+
42
+ types = params["types"]
43
+ types.is_a?(::Array) && types.include?(item["type"])
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,27 @@
1
+ class Ey::Core::Client
2
+ class Real
3
+ def get_auto_scaling_policy(params = {})
4
+ id = params["id"]
5
+ url = params["url"]
6
+
7
+ request(
8
+ :method => :get,
9
+ :path => "auto_scaling_policies/#{id}",
10
+ :url => url
11
+ )
12
+ end
13
+ end
14
+
15
+ class Mock
16
+ def get_auto_scaling_policy(params = {})
17
+ response(
18
+ :body => {
19
+ "auto_scaling_policy" => self.find(
20
+ :auto_scaling_policies,
21
+ resource_identity(params)
22
+ )
23
+ },
24
+ )
25
+ end
26
+ end
27
+ end
@@ -7,7 +7,7 @@ class Ey::Core::Client
7
7
  request(
8
8
  :params => params,
9
9
  :path => "/deployments",
10
- :query => params,
10
+ :query => query,
11
11
  :url => url,
12
12
  )
13
13
  end
@@ -0,0 +1,19 @@
1
+ class Ey::Core::Client
2
+ class Real
3
+ def get_environment_variable(params={})
4
+ id = params.delete("id")
5
+ url = params.delete("url")
6
+
7
+ request(
8
+ :path => "environment_variables/#{id}",
9
+ :url => url,
10
+ )
11
+ end
12
+ end
13
+
14
+ class Mock
15
+ def get_environment_variable(params={})
16
+ response(body: {"environment_variable" => find(:environment_variables, resource_identity(params))})
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,29 @@
1
+ class Ey::Core::Client
2
+ class Real
3
+ def get_environment_variables(params={})
4
+ query = Ey::Core.paging_parameters(params)
5
+ url = params.delete("url")
6
+
7
+ request(
8
+ :params => params,
9
+ :path => "/environment_variables",
10
+ :query => params,
11
+ :url => url,
12
+ )
13
+ end
14
+ end
15
+
16
+ class Mock
17
+ def get_environment_variables(params={})
18
+ extract_url_params!(params)
19
+
20
+ headers, environment_variables_page = search_and_page(params, :environment_variables, search_keys: %w(environment application))
21
+
22
+ response(
23
+ :body => {"environment_variables" => environment_variables_page},
24
+ :status => 200,
25
+ :headers => headers
26
+ )
27
+ end
28
+ end
29
+ end
@@ -17,7 +17,7 @@ class Ey::Core::Client
17
17
  def get_environments(params={})
18
18
  extract_url_params!(params)
19
19
 
20
- headers, environments_page = search_and_page(params, :environments, search_keys: %w[account name])
20
+ headers, environments_page = search_and_page(params, :environments, search_keys: %w[id account name])
21
21
 
22
22
  response(
23
23
  :body => {"environments" => environments_page},
@@ -5,7 +5,7 @@ class Ey::Core::Client
5
5
  url = params["url"]
6
6
 
7
7
  request(
8
- :path => "ssl_certificates/#{id}",
8
+ :path => "ssl-certificates/#{id}",
9
9
  :url => url,
10
10
  )
11
11
  end
@@ -0,0 +1,24 @@
1
+ class Ey::Core::Client
2
+ class Real
3
+ def retrieve_docker_registry_credentials(account_id, location_id)
4
+ request(
5
+ :path => "/accounts/#{account_id}/docker-registry/#{location_id}/credentials"
6
+ )
7
+ end
8
+ end
9
+
10
+ class Mock
11
+ def retrieve_docker_registry_credentials(account_id, location_id)
12
+ response(
13
+ :body => {
14
+ 'docker_registry_credentials' => {
15
+ 'username' => 'foo',
16
+ 'password' => 'bar',
17
+ 'registry_endpoint' => "https://012345678901.dkr.ecr.#{location_id}.amazonaws.com",
18
+ 'expires_at' => (Time.now + 8 * 3600).to_i
19
+ }
20
+ }
21
+ )
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,45 @@
1
+ class Ey::Core::Client
2
+ class Real
3
+ def update_auto_scaling_alarm(params = {})
4
+ id = params.delete("id")
5
+
6
+ request(
7
+ :method => :put,
8
+ :path => "/auto_scaling_alarms/#{id}",
9
+ :body => { "auto_scaling_alarm" => params.fetch("auto_scaling_alarm") },
10
+ )
11
+ end
12
+ end
13
+
14
+ class Mock
15
+ def update_auto_scaling_alarm(params = {})
16
+ resource_id = params.delete("id")
17
+ now = Time.now
18
+ resource = find(:auto_scaling_alarms, resource_id)
19
+ .merge(params["auto_scaling_alarm"])
20
+ .merge("updated_at" => now)
21
+ resource.merge!(params)
22
+
23
+ request = {
24
+ "id" => self.uuid,
25
+ "type" => "update_auto_scaling_alarm",
26
+ "successful" => true,
27
+ "created_at" => now - 5,
28
+ "started_at" => now - 3,
29
+ "finished_at" => now,
30
+ "updated_at" => now,
31
+ "message" => nil,
32
+ "read_channel" => nil,
33
+ "resource" => [:auto_scaling_alarms, resource_id, resource],
34
+ "resource_url" => url_for("/auto_scaling_alarms/#{resource_id}")
35
+ }
36
+
37
+ self.data[:requests][request["id"]] = request
38
+
39
+ response(
40
+ body: { "request" => request },
41
+ status: 200
42
+ )
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,46 @@
1
+ class Ey::Core::Client
2
+ class Real
3
+ def update_auto_scaling_policy(params = {})
4
+ id = params.delete("id")
5
+
6
+ request(
7
+ :method => :put,
8
+ :path => "/auto_scaling_policies/#{id}",
9
+ :body => { "auto_scaling_policy" => params.fetch("auto_scaling_policy") },
10
+ )
11
+ end
12
+ end
13
+
14
+ class Mock
15
+ def update_auto_scaling_policy(params = {})
16
+ resource_id = params.delete("id")
17
+ now = Time.now
18
+
19
+ resource = find(:auto_scaling_policies, resource_id)
20
+ .merge(params["auto_scaling_policy"])
21
+ .merge("updated_at" => now)
22
+ resource.merge!(params)
23
+
24
+ request = {
25
+ "id" => self.uuid,
26
+ "type" => "update_auto_scaling_policy",
27
+ "successful" => true,
28
+ "created_at" => now - 5,
29
+ "updated_at" => now,
30
+ "started_at" => now - 3,
31
+ "finished_at" => now,
32
+ "message" => nil,
33
+ "read_channel" => nil,
34
+ "resource" => [:auto_scaling_policies, resource_id, resource],
35
+ "resource_url" => url_for("/auto_scaling_policies/#{resource_id}")
36
+ }
37
+
38
+ self.data[:requests][request["id"]] = request
39
+
40
+ response(
41
+ body: { "request" => request },
42
+ status: 200
43
+ )
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,25 @@
1
+ class Ey::Core::Client
2
+ class Real
3
+ def update_environment_variable(_params={})
4
+ params = Cistern::Hash.stringify_keys(_params)
5
+ id = params.delete("id")
6
+ body = { environment_variable: params }
7
+
8
+ request(
9
+ :method => :put,
10
+ :path => "/environment_variables/#{id}",
11
+ :body => body
12
+ )
13
+ end
14
+ end
15
+
16
+ class Mock
17
+ def update_environment_variable(_params={})
18
+ params = Cistern::Hash.stringify_keys(_params).merge!("updated_at" => Time.now)
19
+ environment_variable = find(:environment_variables, params.delete("id"))
20
+ environment_variable.merge!(params)
21
+
22
+ response(:body => { "environment_variable" => environment_variable })
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,35 @@
1
+ module Ey
2
+ module Core
3
+ module TestHelpers
4
+ module AutoScalingHelpers
5
+ def create_auto_scaling_group(options = {})
6
+ environment = options[:environment] || create_environment
7
+
8
+ groups = client.auto_scaling_groups
9
+
10
+ groups.create!(
11
+ minimum_size: 2,
12
+ maximum_size: 6,
13
+ environment: environment
14
+ ).resource!
15
+ end
16
+
17
+ def create_auto_scaling_policy(options = {})
18
+ group = options.delete(:auto_scaling_group) || create_auto_scaling_group
19
+ policies = client.auto_scaling_policies
20
+
21
+ policies.create!(
22
+ {
23
+ auto_scaling_group_id: group.id,
24
+ action_value: 2,
25
+ action_unit: "instances",
26
+ action_type: "add",
27
+ name: SecureRandom.hex(16),
28
+ type: "simple"
29
+ }.merge(options)
30
+ ).resource!
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -2,6 +2,7 @@ require 'ey-core/test_helpers/account_helpers'
2
2
  require 'ey-core/test_helpers/alert_helpers'
3
3
  require 'ey-core/test_helpers/client_helpers'
4
4
  require 'ey-core/test_helpers/resource_helpers'
5
+ require 'ey-core/test_helpers/auto_scaling_helpers'
5
6
 
6
7
  module Ey
7
8
  module Core
@@ -10,6 +11,7 @@ module Ey
10
11
  include AlertHelpers
11
12
  include ClientHelpers
12
13
  include ResourceHelpers
14
+ include AutoScalingHelpers
13
15
  end
14
16
  end
15
17
  end
@@ -1,5 +1,5 @@
1
1
  module Ey
2
2
  module Core
3
- VERSION = "3.4.4"
3
+ VERSION = "3.6.4"
4
4
  end
5
5
  end
@@ -6,12 +6,13 @@ describe 'addresses' do
6
6
  let!(:provider) { create_provider(account: account) }
7
7
 
8
8
  it "creates an address" do
9
- request = client.addresses.create!(provider: provider, location: "us-west-2")
9
+ request = client.addresses.create!(provider: provider, location: "us-west-2", scope: "vpc")
10
10
  address = request.resource!
11
11
  expect(address.id).not_to be_nil
12
12
  expect(address.ip_address).not_to be_nil
13
13
  expect(address.provisioned_id).not_to be_nil
14
14
  expect(address.provider).to eq(provider)
15
+ expect(address.scope).to eq("vpc")
15
16
  end
16
17
 
17
18
  context "with an address" do
@@ -0,0 +1,40 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "Auto scaling alarms" do
4
+ let!(:client) { create_client }
5
+ let!(:account) { create_account(client: client) }
6
+ let(:policy) { create_auto_scaling_policy }
7
+
8
+ let(:params) do
9
+ {
10
+ "name" => SecureRandom.hex(16),
11
+ "aggregation_type" => "avg",
12
+ "metric_type" => "cpu",
13
+ "operand" => "gt",
14
+ "trigger_value" => 0.5,
15
+ "number_of_periods" => 1,
16
+ "period_length" => 30,
17
+ "auto_scaling_policy_id" => policy.id
18
+ }
19
+ end
20
+
21
+ let!(:alarm) { client.auto_scaling_alarms.create!(params).resource! }
22
+
23
+ it "creates a new alarm for an auto scaling policy" do
24
+ expect(alarm).not_to be_nil
25
+ expect(policy.auto_scaling_alarms).not_to be_empty
26
+ expect(client.auto_scaling_alarms).not_to be_empty
27
+ end
28
+
29
+ it "updates an alarm" do
30
+ expect do
31
+ alarm.update("name" => "new name")
32
+ end.to change { alarm.name }.to("new name")
33
+ end
34
+
35
+ it "destroys auto scalig alarm by it's id" do
36
+ expect do
37
+ alarm.destroy!
38
+ end.to change { policy.reload.auto_scaling_alarms.count }.from(1).to(0)
39
+ end
40
+ end
@@ -0,0 +1,94 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "Auto scaling policies" do
4
+ let!(:client) { create_client }
5
+ let!(:account) { create_account(client: client) }
6
+ let!(:environment) { create_environment(account: account) }
7
+ let(:auto_scaling_group) { create_auto_scaling_group(environment: environment.id) }
8
+ let(:simple_policy_params) do
9
+ {
10
+ name: SecureRandom.hex(16),
11
+ action_value: 2,
12
+ action_type: "add",
13
+ action_unit: "instances",
14
+ auto_scaling_group_id: auto_scaling_group.id,
15
+ type: "simple"
16
+ }
17
+ end
18
+
19
+ describe "common requests for all policy types" do
20
+ let!(:policy) { client.auto_scaling_policies.create!(simple_policy_params).resource! }
21
+
22
+ it "is able to retrieve auto scaling policy by it's id" do
23
+ found_policy = client.auto_scaling_policies.get(policy.id)
24
+ expect(found_policy).not_to be_nil
25
+ expect(found_policy.id).to eq(policy.id)
26
+ end
27
+
28
+ it "updates auto scaling policy" do
29
+ expect do
30
+ policy.update(name: "new name")
31
+ end.to change { policy.name }.to("new name")
32
+ end
33
+
34
+ it "destroys a policy by it's id" do
35
+ expect do
36
+ policy.destroy!
37
+ end.to change { auto_scaling_group.reload.simple_auto_scaling_policies.count }.from(1).to(0)
38
+ end
39
+ end
40
+
41
+ context "simple autoscaling policy" do
42
+ it "adds one to autoscaling group" do
43
+ expect {
44
+ client.auto_scaling_policies.create!(simple_policy_params)
45
+ }.to change { auto_scaling_group.reload.simple_auto_scaling_policies.count }.from(0).to(1)
46
+ .and not_change { auto_scaling_group.reload.step_auto_scaling_policies.count }
47
+ .and not_change { auto_scaling_group.reload.target_auto_scaling_policies.count }
48
+ end
49
+ end
50
+
51
+ context "target tracking auto scaling policy" do
52
+ let(:params) do
53
+ {
54
+ auto_scaling_group_id: auto_scaling_group.id,
55
+ name: SecureRandom.hex(16),
56
+ target_value: 0.7,
57
+ estimated_warmup: 200,
58
+ metric_type: "avg_cup",
59
+ disable_scale_in: false,
60
+ type: "target"
61
+ }
62
+ end
63
+
64
+ it "adds one to autoscaling group" do
65
+ expect {
66
+ client.auto_scaling_policies.create!(params)
67
+ }.to change { auto_scaling_group.reload.target_auto_scaling_policies.count }.from(0).to(1)
68
+ .and not_change { auto_scaling_group.reload.simple_auto_scaling_policies.count }
69
+ .and not_change { auto_scaling_group.reload.step_auto_scaling_policies.count }
70
+ end
71
+ end
72
+
73
+ context "step auto scaling policy" do
74
+ let(:params) do
75
+ {
76
+ auto_scaling_group_id: auto_scaling_group.id,
77
+ name: SecureRandom.hex(16),
78
+ estimated_warmup: 200,
79
+ action_unit: "instances",
80
+ action_type: "add",
81
+ steps: [{ metric_from: 50, metric_to: nil, action_value: 1 }],
82
+ type: "step"
83
+ }
84
+ end
85
+
86
+ it "adds one to autoscaling group" do
87
+ expect {
88
+ client.auto_scaling_policies.create!(params)
89
+ }.to change { auto_scaling_group.reload.step_auto_scaling_policies.count }.from(0).to(1)
90
+ .and not_change { auto_scaling_group.reload.simple_auto_scaling_policies.count }
91
+ .and not_change { auto_scaling_group.reload.target_auto_scaling_policies.count }
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'as a user' do
4
+ let(:client) { create_client }
5
+ let(:location) { 'us-east-1' }
6
+ let!(:account) { create_account(client: client) }
7
+
8
+ it 'returns a valid docker registry credentials' do
9
+ credentials = account.retrieve_docker_registry_credentials(location)
10
+
11
+ expect(credentials.username).to be
12
+ expect(credentials.password).to be
13
+ expect(credentials.registry_endpoint).to match(/#{location}/)
14
+ expect(credentials.expires_at).to be > (Time.now + 6 * 3600).to_i
15
+ end
16
+ end