forked from cloudfoundry/java-buildpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew_relic_agent_spec.rb
More file actions
103 lines (77 loc) · 4.03 KB
/
new_relic_agent_spec.rb
File metadata and controls
103 lines (77 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Cloud Foundry Java Buildpack
# Copyright 2013-2017 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require 'spec_helper'
require 'component_helper'
require 'java_buildpack/framework/new_relic_agent'
require 'java_buildpack/util/tokenized_version'
describe JavaBuildpack::Framework::NewRelicAgent do
include_context 'component_helper'
it 'does not detect without newrelic-n/a service' do
expect(component.detect).to be_nil
end
context do
before do
allow(services).to receive(:one_service?).with(/newrelic/, %w[licenseKey license_key]).and_return(true)
end
it 'detects with newrelic-n/a service' do
expect(component.detect).to eq("new-relic-agent=#{version}")
end
it 'downloads New Relic agent JAR',
cache_fixture: 'stub-new-relic-agent.jar' do
component.compile
expect(sandbox + "new_relic_agent-#{version}.jar").to exist
end
it 'copies resources',
cache_fixture: 'stub-new-relic-agent.jar' do
component.compile
expect(sandbox + 'newrelic.yml').to exist
end
it 'supports custom cups via env var override' do
ENV['JBP_CONFIG_NEW_RELIC_CUPS'] = 'custom-cups-name'
allow(java_home).to receive(:java_8_or_later?).and_return(JavaBuildpack::Util::TokenizedVersion.new('1.7.0_u10'))
expect(services).to receive(:find_service).with('custom-cups-name').and_return('credentials' => { 'licenseKey' => 'custom-cups-license-key' })
component.release
# Unset after the test
ENV['JBP_CONFIG_NEW_RELIC_CUPS'] = nil
end
it 'updates JAVA_OPTS' do
allow(services).to receive(:find_service).and_return('credentials' => { 'licenseKey' => 'test-license-key' })
allow(java_home).to receive(:java_8_or_later?).and_return(JavaBuildpack::Util::TokenizedVersion.new('1.7.0_u10'))
component.release
expect(java_opts).to include("-javaagent:$PWD/.java-buildpack/new_relic_agent/new_relic_agent-#{version}.jar")
expect(java_opts).to include('-Dnewrelic.home=$PWD/.java-buildpack/new_relic_agent')
expect(java_opts).to include('-Dnewrelic.config.license_key=test-license-key')
expect(java_opts).to include('-Dnewrelic.config.app_name=test-application-name')
expect(java_opts).to include('-Dnewrelic.config.log_file_name=STDOUT')
end
it 'updates JAVA_OPTS with additional options' do
allow(services).to receive(:find_service).and_return('credentials' => { 'licenseKey' => 'test-license-key',
'license_key' => 'different-license-key',
'app_name' => 'different-name',
'foo' => 'bar' })
allow(java_home).to receive(:java_8_or_later?).and_return(JavaBuildpack::Util::TokenizedVersion.new('1.7.0_u10'))
component.release
expect(java_opts).to include('-Dnewrelic.config.license_key=different-license-key')
expect(java_opts).to include('-Dnewrelic.config.app_name=different-name')
expect(java_opts).to include('-Dnewrelic.config.foo=bar')
end
it 'updates JAVA_OPTS on Java 8' do
allow(services).to receive(:find_service).and_return('credentials' => { 'licenseKey' => 'test-license-key' })
allow(java_home).to receive(:java_8_or_later?).and_return(JavaBuildpack::Util::TokenizedVersion.new('1.8.0_u10'))
component.release
expect(java_opts).to include('-Dnewrelic.enable.java.8=true')
end
end
end