new_cfoundry 4.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.gitmodules +3 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +11 -0
- data/Checkfile +2 -0
- data/Gemfile +3 -0
- data/LICENSE +987 -0
- data/NOTICE +10 -0
- data/README.md +9 -0
- data/Rakefile +14 -0
- data/VERSION +1 -0
- data/cfoundry.gemspec +40 -0
- data/config/locales/en.yml +168 -0
- data/lib/cc_api_stub/app_usage_events.rb +11 -0
- data/lib/cc_api_stub/applications.rb +57 -0
- data/lib/cc_api_stub/domains.rb +32 -0
- data/lib/cc_api_stub/events.rb +11 -0
- data/lib/cc_api_stub/frameworks.rb +22 -0
- data/lib/cc_api_stub/helper.rb +148 -0
- data/lib/cc_api_stub/login.rb +21 -0
- data/lib/cc_api_stub/organization_users.rb +27 -0
- data/lib/cc_api_stub/organizations.rb +82 -0
- data/lib/cc_api_stub/routes.rb +26 -0
- data/lib/cc_api_stub/runtimes.rb +22 -0
- data/lib/cc_api_stub/service_bindings.rb +22 -0
- data/lib/cc_api_stub/service_instances.rb +22 -0
- data/lib/cc_api_stub/services.rb +21 -0
- data/lib/cc_api_stub/space_users.rb +27 -0
- data/lib/cc_api_stub/spaces.rb +58 -0
- data/lib/cc_api_stub/users.rb +85 -0
- data/lib/cc_api_stub.rb +20 -0
- data/lib/cfoundry/auth_token.rb +63 -0
- data/lib/cfoundry/baseclient.rb +216 -0
- data/lib/cfoundry/chatty_hash.rb +46 -0
- data/lib/cfoundry/client.rb +42 -0
- data/lib/cfoundry/concerns/login_helpers.rb +14 -0
- data/lib/cfoundry/concerns/proxy_options.rb +17 -0
- data/lib/cfoundry/errors.rb +163 -0
- data/lib/cfoundry/rest_client.rb +317 -0
- data/lib/cfoundry/test_support.rb +3 -0
- data/lib/cfoundry/trace_helpers.rb +64 -0
- data/lib/cfoundry/uaaclient.rb +160 -0
- data/lib/cfoundry/upload_helpers.rb +222 -0
- data/lib/cfoundry/v2/app.rb +303 -0
- data/lib/cfoundry/v2/app_event.rb +13 -0
- data/lib/cfoundry/v2/app_instance.rb +74 -0
- data/lib/cfoundry/v2/app_usage_event.rb +14 -0
- data/lib/cfoundry/v2/base.rb +108 -0
- data/lib/cfoundry/v2/client.rb +104 -0
- data/lib/cfoundry/v2/domain.rb +20 -0
- data/lib/cfoundry/v2/event.rb +17 -0
- data/lib/cfoundry/v2/helper.rb +11 -0
- data/lib/cfoundry/v2/managed_service_instance.rb +12 -0
- data/lib/cfoundry/v2/model.rb +211 -0
- data/lib/cfoundry/v2/model_magic/attribute.rb +49 -0
- data/lib/cfoundry/v2/model_magic/client_extensions.rb +170 -0
- data/lib/cfoundry/v2/model_magic/has_summary.rb +49 -0
- data/lib/cfoundry/v2/model_magic/query_multi_value_helper.rb +21 -0
- data/lib/cfoundry/v2/model_magic/query_value_helper.rb +33 -0
- data/lib/cfoundry/v2/model_magic/queryable_by.rb +39 -0
- data/lib/cfoundry/v2/model_magic/to_many.rb +138 -0
- data/lib/cfoundry/v2/model_magic/to_one.rb +81 -0
- data/lib/cfoundry/v2/model_magic.rb +134 -0
- data/lib/cfoundry/v2/organization.rb +44 -0
- data/lib/cfoundry/v2/quota_definition.rb +12 -0
- data/lib/cfoundry/v2/route.rb +25 -0
- data/lib/cfoundry/v2/service.rb +22 -0
- data/lib/cfoundry/v2/service_auth_token.rb +9 -0
- data/lib/cfoundry/v2/service_binding.rb +10 -0
- data/lib/cfoundry/v2/service_broker.rb +12 -0
- data/lib/cfoundry/v2/service_instance.rb +14 -0
- data/lib/cfoundry/v2/service_plan.rb +16 -0
- data/lib/cfoundry/v2/space.rb +30 -0
- data/lib/cfoundry/v2/stack.rb +10 -0
- data/lib/cfoundry/v2/user.rb +93 -0
- data/lib/cfoundry/v2/user_provided_service_instance.rb +15 -0
- data/lib/cfoundry/validator.rb +41 -0
- data/lib/cfoundry/version.rb +4 -0
- data/lib/cfoundry/zip.rb +56 -0
- data/lib/cfoundry.rb +5 -0
- data/release_notes/release_1_5_3.md +177 -0
- data/release_notes/release_2.3.1.md +14 -0
- data/release_notes/release_2.3.3.md +38 -0
- data/release_notes/release_2.3.4.md +16 -0
- data/release_notes/release_2.3.5.md +14 -0
- data/release_notes/release_2.3.6.md +14 -0
- data/release_notes/release_2.3.6.rc1.md +29 -0
- data/release_notes/release_2.3.6.rc2.md +19 -0
- data/release_notes/release_2.3.7.rc1.md +14 -0
- data/release_notes/release_2.4.0.md +41 -0
- data/release_notes/release_2.4.1.rc1.md +58 -0
- data/release_notes/release_3.0.0.md +21 -0
- data/release_notes/release_3.0.1.md +16 -0
- data/release_notes/release_3.0.2.rc1.md +19 -0
- data/release_notes/release_4.0.0.md +19 -0
- data/release_notes/release_4.0.1.md +14 -0
- data/release_notes/release_4.0.2.rc1.md +14 -0
- data/release_notes/release_4.0.2.rc2.md +11 -0
- data/release_notes/release_4.0.2.rc3.md +11 -0
- data/release_notes/release_4.0.2.rc4.md +19 -0
- data/release_notes/release_4.0.2.rc5.md +14 -0
- data/release_notes/release_4.0.3.md +19 -0
- data/release_notes/release_4.0.4.rc1.md +14 -0
- data/release_notes/release_4.0.4.rc2.md +14 -0
- data/release_notes/release_4.1.0.md +19 -0
- data/release_notes/release_4.2.0.rc.md +24 -0
- data/release_notes/release_4.3.0.md +22 -0
- data/release_notes/release_4.3.1.md +14 -0
- data/release_notes/release_4.3.10.md +14 -0
- data/release_notes/release_4.3.11.md +14 -0
- data/release_notes/release_4.3.12.md +14 -0
- data/release_notes/release_4.3.2.rc1.md +21 -0
- data/release_notes/release_4.3.3.md +24 -0
- data/release_notes/release_4.3.4.md +11 -0
- data/release_notes/release_4.3.4.rc1.md +24 -0
- data/release_notes/release_4.3.5.md +36 -0
- data/release_notes/release_4.3.5.rc1.md +21 -0
- data/release_notes/release_4.3.6.md +14 -0
- data/release_notes/release_4.3.7.md +50 -0
- data/release_notes/release_4.3.8.md +19 -0
- data/release_notes/release_4.3.9.md +14 -0
- data/release_notes/release_4.4.0.md +16 -0
- data/release_notes/release_4.5.1.md +11 -0
- data/release_notes/release_4.5.2.md +14 -0
- data/release_notes/release_4.5.3.md +29 -0
- data/release_notes/release_4.6.0.md +24 -0
- data/release_notes/release_4.6.1.md +14 -0
- data/release_notes/release_4.6.2.md +16 -0
- data/release_notes/release_4.6.3.rc1.md +14 -0
- data/release_notes/release_4.6.3.rc2.md +14 -0
- data/release_notes/release_4.6.3.rc3.md +17 -0
- data/release_notes/release_4.7.0.md +11 -0
- data/release_notes/release_4.7.1.md +14 -0
- data/release_notes/release_4.7.1.rc.1.md +14 -0
- data/release_notes/release_4.7.1.rc1.md +19 -0
- data/script/gpp +3 -0
- data/spec/cc_api_stub/app_usage_events_spec.rb +12 -0
- data/spec/cc_api_stub/applications_spec.rb +69 -0
- data/spec/cc_api_stub/domains_spec.rb +40 -0
- data/spec/cc_api_stub/events_spec.rb +12 -0
- data/spec/cc_api_stub/frameworks_spec.rb +19 -0
- data/spec/cc_api_stub/login_spec.rb +20 -0
- data/spec/cc_api_stub/organization_users_spec.rb +35 -0
- data/spec/cc_api_stub/organizations_spec.rb +118 -0
- data/spec/cc_api_stub/routes_spec.rb +19 -0
- data/spec/cc_api_stub/runtimes_spec.rb +19 -0
- data/spec/cc_api_stub/service_bindings_spec.rb +13 -0
- data/spec/cc_api_stub/service_instances_spec.rb +19 -0
- data/spec/cc_api_stub/services_spec.rb +11 -0
- data/spec/cc_api_stub/space_users_spec.rb +35 -0
- data/spec/cc_api_stub/spaces_spec.rb +38 -0
- data/spec/cc_api_stub/users_spec.rb +107 -0
- data/spec/cfoundry/auth_token_spec.rb +154 -0
- data/spec/cfoundry/baseclient_spec.rb +298 -0
- data/spec/cfoundry/client_spec.rb +13 -0
- data/spec/cfoundry/errors_spec.rb +117 -0
- data/spec/cfoundry/rest_client_spec.rb +349 -0
- data/spec/cfoundry/trace_helpers_spec.rb +91 -0
- data/spec/cfoundry/uaaclient_spec.rb +435 -0
- data/spec/cfoundry/upload_helpers_spec.rb +182 -0
- data/spec/cfoundry/v2/app_event_spec.rb +97 -0
- data/spec/cfoundry/v2/app_instance_spec.rb +31 -0
- data/spec/cfoundry/v2/app_spec.rb +354 -0
- data/spec/cfoundry/v2/app_usage_event_spec.rb +15 -0
- data/spec/cfoundry/v2/base_spec.rb +375 -0
- data/spec/cfoundry/v2/client_spec.rb +121 -0
- data/spec/cfoundry/v2/domain_spec.rb +63 -0
- data/spec/cfoundry/v2/event_spec.rb +15 -0
- data/spec/cfoundry/v2/managed_service_instance_spec.rb +149 -0
- data/spec/cfoundry/v2/model_magic/attribute_spec.rb +123 -0
- data/spec/cfoundry/v2/model_magic/has_summary_spec.rb +17 -0
- data/spec/cfoundry/v2/model_magic/to_many_spec.rb +53 -0
- data/spec/cfoundry/v2/model_magic/to_one_spec.rb +106 -0
- data/spec/cfoundry/v2/model_magic_spec.rb +43 -0
- data/spec/cfoundry/v2/model_spec.rb +434 -0
- data/spec/cfoundry/v2/organization_spec.rb +135 -0
- data/spec/cfoundry/v2/quota_definition_spec.rb +50 -0
- data/spec/cfoundry/v2/route_spec.rb +42 -0
- data/spec/cfoundry/v2/service_plan_spec.rb +53 -0
- data/spec/cfoundry/v2/service_spec.rb +58 -0
- data/spec/cfoundry/v2/space_spec.rb +13 -0
- data/spec/cfoundry/v2/user_provided_service_instance_spec.rb +57 -0
- data/spec/cfoundry/v2/user_spec.rb +206 -0
- data/spec/cfoundry/validator_spec.rb +94 -0
- data/spec/factories/app_events_factory.rb +7 -0
- data/spec/factories/app_usage_events_factory.rb +32 -0
- data/spec/factories/apps_factory.rb +11 -0
- data/spec/factories/clients_factory.rb +7 -0
- data/spec/factories/domains_factory.rb +10 -0
- data/spec/factories/events_factory.rb +50 -0
- data/spec/factories/organizations_factory.rb +12 -0
- data/spec/factories/quota_definitions_factory.rb +8 -0
- data/spec/factories/routes_factory.rb +10 -0
- data/spec/factories/service_instances_factory.rb +10 -0
- data/spec/factories/service_plans_factory.rb +10 -0
- data/spec/factories/services_factory.rb +10 -0
- data/spec/factories/spaces_factory.rb +10 -0
- data/spec/factories/user_provided_service_instances_factory.rb +10 -0
- data/spec/factories/users_factory.rb +10 -0
- data/spec/fixtures/apps/with_cfignore/.cfignore +4 -0
- data/spec/fixtures/apps/with_cfignore/.hidden_file +1 -0
- data/spec/fixtures/apps/with_cfignore/ambiguous_ignored +0 -0
- data/spec/fixtures/apps/with_cfignore/ignored_dir/file_in_ignored_dir.txt +1 -0
- data/spec/fixtures/apps/with_cfignore/ignored_file.txt +1 -0
- data/spec/fixtures/apps/with_cfignore/non_ignored_dir/file_in_non_ignored_dir.txt +1 -0
- data/spec/fixtures/apps/with_cfignore/non_ignored_dir/ignored_file.txt +1 -0
- data/spec/fixtures/apps/with_cfignore/non_ignored_dir/toplevel_ignored.txt +0 -0
- data/spec/fixtures/apps/with_cfignore/non_ignored_file.txt +1 -0
- data/spec/fixtures/apps/with_cfignore/toplevel_ignored.txt +0 -0
- data/spec/fixtures/apps/with_dotfiles/.dotfile +1 -0
- data/spec/fixtures/apps/with_dotfiles/xyz +1 -0
- data/spec/fixtures/apps/with_external_symlink/foo +1 -0
- data/spec/fixtures/apps/with_ignored_external_symlink/.cfignore +1 -0
- data/spec/fixtures/apps/with_ignored_external_symlink/foo +1 -0
- data/spec/fixtures/apps/with_nested_directories/foo/bar/baz/fizz +0 -0
- data/spec/fixtures/apps/with_nested_directories/xyz +0 -0
- data/spec/fixtures/empty_file +0 -0
- data/spec/fixtures/fake_cc_app_usage_events.json +152 -0
- data/spec/fixtures/fake_cc_application.json +20 -0
- data/spec/fixtures/fake_cc_application_summary.json +56 -0
- data/spec/fixtures/fake_cc_created_application.json +11 -0
- data/spec/fixtures/fake_cc_created_domain.json +15 -0
- data/spec/fixtures/fake_cc_created_organization.json +11 -0
- data/spec/fixtures/fake_cc_created_route.json +13 -0
- data/spec/fixtures/fake_cc_created_service_instance.json +11 -0
- data/spec/fixtures/fake_cc_created_space.json +11 -0
- data/spec/fixtures/fake_cc_created_user.json +11 -0
- data/spec/fixtures/fake_cc_domain.json +55 -0
- data/spec/fixtures/fake_cc_domain_spaces.json +27 -0
- data/spec/fixtures/fake_cc_empty_search.json +7 -0
- data/spec/fixtures/fake_cc_events.json +419 -0
- data/spec/fixtures/fake_cc_frameworks.json +20 -0
- data/spec/fixtures/fake_cc_managed_service_instance.json +83 -0
- data/spec/fixtures/fake_cc_organization.json +161 -0
- data/spec/fixtures/fake_cc_organization_domains.json +59 -0
- data/spec/fixtures/fake_cc_organization_search.json +37 -0
- data/spec/fixtures/fake_cc_organization_spaces.json +99 -0
- data/spec/fixtures/fake_cc_organization_summary.json +20 -0
- data/spec/fixtures/fake_cc_organization_users.json +81 -0
- data/spec/fixtures/fake_cc_route.json +16 -0
- data/spec/fixtures/fake_cc_runtimes.json +20 -0
- data/spec/fixtures/fake_cc_service_binding.json +22 -0
- data/spec/fixtures/fake_cc_service_bindings.json +24 -0
- data/spec/fixtures/fake_cc_service_instance.json +83 -0
- data/spec/fixtures/fake_cc_service_instances.json +72 -0
- data/spec/fixtures/fake_cc_services.json +160 -0
- data/spec/fixtures/fake_cc_space.json +45 -0
- data/spec/fixtures/fake_cc_space_apps.json +49 -0
- data/spec/fixtures/fake_cc_space_summary.json +84 -0
- data/spec/fixtures/fake_cc_spaces.json +92 -0
- data/spec/fixtures/fake_cc_stats.json +29 -0
- data/spec/fixtures/fake_cc_user.json +139 -0
- data/spec/fixtures/fake_cc_user_organizations.json +92 -0
- data/spec/fixtures/fake_cc_user_provided_service_instance.json +51 -0
- data/spec/fixtures/fake_cc_user_with_managers.json +85 -0
- data/spec/integration/client_spec.rb +38 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/support/factory_girl.rb +6 -0
- data/spec/support/shared_examples/cc_api_stub_request_examples.rb +79 -0
- data/spec/support/shared_examples/client_login_examples.rb +46 -0
- data/spec/support/shared_examples/model_summary_examples.rb +34 -0
- data/spec/support/test_model_builder.rb +10 -0
- data/vendor/errors/README.md +4 -0
- data/vendor/errors/v1.yml +189 -0
- data/vendor/errors/v2.yml +384 -0
- metadata +693 -0
@@ -0,0 +1,97 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module CFoundry
|
4
|
+
module V2
|
5
|
+
describe AppEvent do
|
6
|
+
let(:app) { build(:app) }
|
7
|
+
let(:app_event) { build(:app_event, :app => app) }
|
8
|
+
|
9
|
+
it "has an app" do
|
10
|
+
expect(app_event.app).to eq(app)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#instance_guid" do
|
14
|
+
it "has an instance guid" do
|
15
|
+
app_event.instance_guid = "foo"
|
16
|
+
expect(app_event.instance_guid).to eq("foo")
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when an invalid value is assigned" do
|
20
|
+
it "raises a Mismatch exception" do
|
21
|
+
expect {
|
22
|
+
app_event.instance_guid = 123
|
23
|
+
}.to raise_error(Mismatch)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#instance_index" do
|
29
|
+
it "has an instance index" do
|
30
|
+
app_event.instance_index = 123
|
31
|
+
expect(app_event.instance_index).to eq(123)
|
32
|
+
end
|
33
|
+
|
34
|
+
context "when an invalid value is assigned" do
|
35
|
+
it "raises a Mismatch exception" do
|
36
|
+
expect {
|
37
|
+
app_event.instance_index = "wrong"
|
38
|
+
}.to raise_error(Mismatch)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#exit_status" do
|
44
|
+
it "has an instance index" do
|
45
|
+
app_event.exit_status = 123
|
46
|
+
expect(app_event.exit_status).to eq(123)
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when an invalid value is assigned" do
|
50
|
+
it "raises a Mismatch exception" do
|
51
|
+
expect {
|
52
|
+
app_event.exit_status = "wrong"
|
53
|
+
}.to raise_error(Mismatch)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#exit_description" do
|
59
|
+
before do
|
60
|
+
stub_request(:get, /v2\/app_events\/.*/).to_return(:body => {:entity => {}}.to_json)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "defaults to an empty string" do
|
64
|
+
expect(app_event.exit_description).to eq("")
|
65
|
+
end
|
66
|
+
|
67
|
+
it "has an instance guid" do
|
68
|
+
app_event.exit_description = "foo"
|
69
|
+
expect(app_event.exit_description).to eq("foo")
|
70
|
+
end
|
71
|
+
|
72
|
+
context "when an invalid value is assigned" do
|
73
|
+
it "raises a Mismatch exception" do
|
74
|
+
expect {
|
75
|
+
app_event.exit_description = 123
|
76
|
+
}.to raise_error(Mismatch)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#timestamp" do
|
82
|
+
it "has a timestamp" do
|
83
|
+
app_event.timestamp = "2013-04-23 12:43:23 +0000"
|
84
|
+
expect(app_event.timestamp).to eq("2013-04-23 12:43:23 +0000")
|
85
|
+
end
|
86
|
+
|
87
|
+
context "when an invalid value is assigned" do
|
88
|
+
it "raises a Mismatch exception" do
|
89
|
+
expect {
|
90
|
+
app_event.timestamp = 42
|
91
|
+
}.to raise_error(Mismatch)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module CFoundry::V2
|
4
|
+
describe AppInstance do
|
5
|
+
let(:client) { double }
|
6
|
+
let(:guid) { 'a snowflake' }
|
7
|
+
let(:name) { 'test-app' }
|
8
|
+
let(:instance_json) {
|
9
|
+
{
|
10
|
+
:state => "RUNNING",
|
11
|
+
:since => 1383588787.1809542,
|
12
|
+
:debug_ip => nil,
|
13
|
+
:debug_port => nil,
|
14
|
+
:console_ip => nil,
|
15
|
+
:console_port => nil
|
16
|
+
}
|
17
|
+
}
|
18
|
+
describe '.for_app' do
|
19
|
+
before do
|
20
|
+
instances_json = {:"0" => instance_json}
|
21
|
+
client.stub_chain(:base, :instances).and_return instances_json
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'returns instances' do
|
25
|
+
instances = AppInstance.for_app(name, guid, client)
|
26
|
+
expect(instances.count).to eq 1
|
27
|
+
expect(instances.first.inspect).to eq "#<App::Instance '#{name}' \#0>"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,354 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module CFoundry
|
4
|
+
module V2
|
5
|
+
describe App do
|
6
|
+
let(:client) { build(:client) }
|
7
|
+
|
8
|
+
subject { build(:app, :client => client, :name => 'foo-app') }
|
9
|
+
|
10
|
+
describe "#events" do
|
11
|
+
let(:events) { [build(:app_event)] }
|
12
|
+
|
13
|
+
it "has events" do
|
14
|
+
subject.events = events
|
15
|
+
expect(subject.events).to eq(events)
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when an invalid value is assigned" do
|
19
|
+
it "raises a Mismatch exception" do
|
20
|
+
expect {
|
21
|
+
subject.events = [build(:organization)]
|
22
|
+
}.to raise_error(CFoundry::Mismatch)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "environment" do
|
28
|
+
let(:app) { build(:app, :env => {"FOO" => "1"}) }
|
29
|
+
|
30
|
+
it "returns a hash-like object" do
|
31
|
+
expect(app.env["FOO"]).to eq "1"
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "converting keys and values to strings" do
|
35
|
+
let(:app) { build(:app, :env => {:FOO => 1}) }
|
36
|
+
|
37
|
+
it "converts keys and values to strings" do
|
38
|
+
expect(app.env.to_hash).to eq("FOO" => "1")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when changes are made to the hash-like object" do
|
43
|
+
it "reflects the changes in .env" do
|
44
|
+
expect {
|
45
|
+
app.env["BAR"] = "2"
|
46
|
+
}.to change { app.env.to_hash }.from("FOO" => "1").to("FOO" => "1", "BAR" => "2")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when the env is set to something else" do
|
51
|
+
it "reflects the changes in .env" do
|
52
|
+
expect {
|
53
|
+
app.env = {"BAR" => "2"}
|
54
|
+
}.to change { app.env.to_hash }.from("FOO" => "1").to("BAR" => "2")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#summarize!" do
|
60
|
+
let(:app) { build(:app) }
|
61
|
+
|
62
|
+
it "assigns :instances as #total_instances" do
|
63
|
+
allow(app).to receive(:summary) { {:instances => 4} }
|
64
|
+
|
65
|
+
app.summarize!
|
66
|
+
|
67
|
+
expect(app.total_instances).to eq(4)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
shared_examples_for "something may stage the app" do
|
72
|
+
subject { build(:app, :client => client) }
|
73
|
+
let(:response) { {:body => '{ "foo": "bar" }'} }
|
74
|
+
|
75
|
+
before do
|
76
|
+
allow(client.base).to receive(:put).with("v2", "apps", subject.guid, anything) do
|
77
|
+
response
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
it "sends the PUT request" do
|
82
|
+
expect(client.base).to receive(:put).with(
|
83
|
+
"v2", "apps", subject.guid,
|
84
|
+
hash_including(
|
85
|
+
:return_response => true)) do
|
86
|
+
response
|
87
|
+
end
|
88
|
+
|
89
|
+
update
|
90
|
+
end
|
91
|
+
|
92
|
+
context "and a block is given" do
|
93
|
+
let(:response) do
|
94
|
+
{ :headers => { "x-app-staging-log" => "http://app/staging/log" },
|
95
|
+
:body => "{}"
|
96
|
+
}
|
97
|
+
end
|
98
|
+
|
99
|
+
it "yields the URL for the logs" do
|
100
|
+
yielded_url = nil
|
101
|
+
update do |url|
|
102
|
+
yielded_url = url
|
103
|
+
end
|
104
|
+
|
105
|
+
expect(yielded_url).to eq "http://app/staging/log"
|
106
|
+
end
|
107
|
+
|
108
|
+
context "and no staging header is returned" do
|
109
|
+
let(:response) do
|
110
|
+
{ :headers => {},
|
111
|
+
:body => "{}"
|
112
|
+
}
|
113
|
+
end
|
114
|
+
|
115
|
+
it "yields nil" do
|
116
|
+
yielded_url = :something
|
117
|
+
update do |url|
|
118
|
+
yielded_url = url
|
119
|
+
end
|
120
|
+
|
121
|
+
expect(yielded_url).to be_nil
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "#start!" do
|
128
|
+
it_should_behave_like "something may stage the app" do
|
129
|
+
def update(&blk)
|
130
|
+
subject.start!(&blk)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "#restart!" do
|
136
|
+
it_should_behave_like "something may stage the app" do
|
137
|
+
def update(&blk)
|
138
|
+
subject.restart!(&blk)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe "#update!" do
|
144
|
+
describe "changes" do
|
145
|
+
subject { build(:app, :client => client) }
|
146
|
+
let(:response) { {:body => {"foo" => "bar"}.to_json} }
|
147
|
+
|
148
|
+
before do
|
149
|
+
allow(client.base).to receive(:put).with("v2", "apps", subject.guid, anything) do
|
150
|
+
response
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
it "applies the changes from the response JSON" do
|
155
|
+
expect {
|
156
|
+
subject.update!
|
157
|
+
}.to change { subject.manifest }.to(:foo => "bar")
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
it_should_behave_like "something may stage the app" do
|
162
|
+
def update(&blk)
|
163
|
+
subject.update!(&blk)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe "#stream_update_log" do
|
169
|
+
let(:base_url) { "http://example.com/log" }
|
170
|
+
|
171
|
+
def mock_log(url = anything)
|
172
|
+
expect(client).to receive(:stream_url).with(url) { |_, &blk|
|
173
|
+
blk.call(yield)
|
174
|
+
}.ordered
|
175
|
+
end
|
176
|
+
|
177
|
+
def stub_log(url = anything)
|
178
|
+
allow(client).to receive(:stream_url).with(url) do |_, blk|
|
179
|
+
blk.call(yield)
|
180
|
+
end.ordered
|
181
|
+
end
|
182
|
+
|
183
|
+
it "yields chunks from the response to the block" do
|
184
|
+
mock_log { "a" }
|
185
|
+
mock_log { "b" }
|
186
|
+
mock_log { raise CFoundry::NotFound }
|
187
|
+
|
188
|
+
chunks = []
|
189
|
+
subject.stream_update_log(base_url) do |chunk|
|
190
|
+
chunks << chunk
|
191
|
+
end
|
192
|
+
|
193
|
+
expect(chunks).to eq(%w(a b))
|
194
|
+
end
|
195
|
+
|
196
|
+
it "retries when the connection times out" do
|
197
|
+
mock_log { raise ::Timeout::Error }
|
198
|
+
mock_log { "a" }
|
199
|
+
mock_log { raise ::Timeout::Error }
|
200
|
+
mock_log { "b" }
|
201
|
+
mock_log { raise ::Timeout::Error }
|
202
|
+
mock_log { raise CFoundry::NotFound }
|
203
|
+
|
204
|
+
chunks = []
|
205
|
+
subject.stream_update_log(base_url) do |chunk|
|
206
|
+
chunks << chunk
|
207
|
+
end
|
208
|
+
|
209
|
+
expect(chunks).to eq(%w(a b))
|
210
|
+
end
|
211
|
+
|
212
|
+
it "tracks the offset to stream from" do
|
213
|
+
url = "#{base_url}&tail&tail_offset="
|
214
|
+
|
215
|
+
mock_log("#{url}0") { "a" }
|
216
|
+
mock_log("#{url}1") { raise ::Timeout::Error }
|
217
|
+
mock_log("#{url}1") { "b" }
|
218
|
+
mock_log("#{url}2") { raise CFoundry::NotFound }
|
219
|
+
|
220
|
+
chunks = []
|
221
|
+
subject.stream_update_log(base_url) do |chunk|
|
222
|
+
chunks << chunk
|
223
|
+
end
|
224
|
+
|
225
|
+
expect(chunks).to eq(%w(a b))
|
226
|
+
end
|
227
|
+
|
228
|
+
it "stops when the endpoint disappears" do
|
229
|
+
mock_log { "a" }
|
230
|
+
mock_log { "b" }
|
231
|
+
mock_log { raise CFoundry::NotFound }
|
232
|
+
stub_log { "c" }
|
233
|
+
|
234
|
+
chunks = []
|
235
|
+
subject.stream_update_log(base_url) do |chunk|
|
236
|
+
chunks << chunk
|
237
|
+
end
|
238
|
+
|
239
|
+
expect(chunks).to eq(%w(a b))
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
describe "delete!" do
|
244
|
+
it "defaults to recursive" do
|
245
|
+
expect(client.base).to receive(:delete).with("v2", :apps, subject.guid, {:params => {:recursive => true}})
|
246
|
+
|
247
|
+
subject.delete!
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
it "accepts and ignores an options hash" do
|
252
|
+
expect(client.base).to receive(:delete).with("v2", :apps, subject.guid, {:params => {:recursive => true}})
|
253
|
+
|
254
|
+
subject.delete!(:recursive => false)
|
255
|
+
end
|
256
|
+
|
257
|
+
describe "#health" do
|
258
|
+
describe "when staging failed for an app" do
|
259
|
+
it "returns 'STAGING FAILED' as state" do
|
260
|
+
allow(AppInstance).to receive(:for_app) { raise CFoundry::StagingError }
|
261
|
+
allow(subject).to receive(:state) { "STARTED" }
|
262
|
+
|
263
|
+
expect(subject.health).to eq("STAGING FAILED")
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
describe "#percent_running" do
|
269
|
+
before do
|
270
|
+
allow(subject).to receive(:state) { "STARTED" }
|
271
|
+
subject.total_instances = instances.count
|
272
|
+
allow(AppInstance).to receive(:for_app).with(subject.name, subject.guid, client) { instances }
|
273
|
+
end
|
274
|
+
|
275
|
+
let(:instances) do
|
276
|
+
(1..3).map { double(AppInstance, state: "RUNNING") }
|
277
|
+
end
|
278
|
+
|
279
|
+
it "returns the percent of instances running as an integer" do
|
280
|
+
expect(subject.percent_running).to eq(100)
|
281
|
+
end
|
282
|
+
|
283
|
+
context "when half the instances are running" do
|
284
|
+
let(:instances) { [double(AppInstance, state: "RUNNING"), double(AppInstance, state: "STOPPED")] }
|
285
|
+
|
286
|
+
it "returns 50" do
|
287
|
+
expect(subject.percent_running).to eq(50)
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
context "when staging has failed" do
|
292
|
+
before { allow(AppInstance).to receive(:for_app) { raise CFoundry::StagingError } }
|
293
|
+
|
294
|
+
it "returns 0" do
|
295
|
+
expect(subject.percent_running).to eq(0)
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
describe "#host" do
|
301
|
+
let(:route) { build(:route, :host => "my-host") }
|
302
|
+
let(:app) { build(:app) }
|
303
|
+
|
304
|
+
context "when at least one route exists" do
|
305
|
+
it "returns the host that the user has specified" do
|
306
|
+
allow(app).to receive(:routes).and_return([route])
|
307
|
+
expect(app.host).to eq("my-host")
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
context "when no routes exists" do
|
312
|
+
it "returns the host that the user has specified" do
|
313
|
+
allow(app).to receive(:routes).and_return([])
|
314
|
+
expect(app.host).to be_nil
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
describe "#domain" do
|
320
|
+
let(:domain) { build(:domain, :name => "my-domain") }
|
321
|
+
let(:route) { build(:route, :domain => domain) }
|
322
|
+
let(:app) { build(:app) }
|
323
|
+
|
324
|
+
context "when at least one route exists" do
|
325
|
+
it "returns the domain that the user has specified" do
|
326
|
+
allow(app).to receive(:routes).and_return([route])
|
327
|
+
expect(app.domain).to eq("my-domain")
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
context "when no routes exists" do
|
332
|
+
it "returns the domain that the user has specified" do
|
333
|
+
allow(app).to receive(:routes).and_return([])
|
334
|
+
expect(app.domain).to be_nil
|
335
|
+
end
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
describe "#uri" do
|
340
|
+
context "when there are one or more routes" do
|
341
|
+
let(:domain) { build(:domain, :name => "example.com") }
|
342
|
+
let(:route) { build(:route, :host => "my-host", :domain => domain) }
|
343
|
+
let(:other_route) { build(:route, :host => "other-host", :domain => domain) }
|
344
|
+
let(:app) { build(:app) }
|
345
|
+
|
346
|
+
it "return the first one" do
|
347
|
+
allow(app).to receive(:routes).and_return([route, other_route])
|
348
|
+
expect(app.uri).to eq("#{route.host}.#{route.domain.name}")
|
349
|
+
end
|
350
|
+
end
|
351
|
+
end
|
352
|
+
end
|
353
|
+
end
|
354
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module CFoundry
|
4
|
+
module V2
|
5
|
+
describe AppUsageEvent do
|
6
|
+
let(:app_usage_event) { build(:app_usage_event, state: 'STOPPED') }
|
7
|
+
|
8
|
+
describe "#state" do
|
9
|
+
it "returns the state" do
|
10
|
+
expect(app_usage_event.state).to eq('STOPPED')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|