Skip to content

Commit 206c9df

Browse files
committed
Fix injection of VCAP_SERVICES into integration tests
1 parent f25d228 commit 206c9df

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

example_app/service_consumer_app.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def service_name
7777
end
7878

7979
def credentials_of_all_repos
80-
CF::App::Credentials.find_all_by_service_label(service_name)
80+
@credentials ||= CF::App::Credentials.new({'VCAP_SERVICES' => vcap_services})
81+
@credentials.find_all_by_service_label(service_name)
8182
end
82-
end
83+
end

example_app/test/integration/github_integration_test.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
before do
66
ensure_env_vars_exist
77

8-
@vcap_services_value = <<JSON
8+
@vcap_services_value = <<~JSON
99
{
1010
"github-repo": [
1111
{
@@ -16,14 +16,21 @@
1616
"name": "#{repo_name}",
1717
"uri": "#{repo_uri}",
1818
"ssh_url": "#{repo_ssh_url}",
19-
"private_key": "#{repo_private_key}"
19+
"private_key": #{repo_private_key.to_json}
2020
}
2121
}
2222
]
2323
}
24-
JSON
24+
JSON
25+
26+
@vcap_application_value = <<~JSON
27+
{
28+
"application_name": "#{File.basename(__FILE__, '.rb')}"
29+
}
30+
JSON
2531

2632
ServiceConsumerApp.any_instance.stubs(:vcap_services).returns(@vcap_services_value)
33+
ServiceConsumerApp.any_instance.stubs(:vcap_application).returns(@vcap_application_value)
2734

2835
visit "/"
2936
end
@@ -69,6 +76,7 @@ def repo_name
6976
end
7077

7178
def repo_private_key
79+
# the corresponding public key must be present as a deploy key in "#{github_username}/#{repo_name}"
7280
ENV["GITHUB_REPO_PRIVATE_KEY"]
7381
end
7482

@@ -86,4 +94,4 @@ def repo_fullname
8694

8795
def github_client
8896
::Octokit::Client.new(access_token: github_access_token)
89-
end
97+
end

0 commit comments

Comments
 (0)