|
| 1 | +# Cloud Foundry Java Buildpack |
| 2 | +# Copyright 2013-2017 the original author or authors. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +require 'spec_helper' |
| 17 | +require 'component_helper' |
| 18 | +require 'java_buildpack/framework/metric_writer' |
| 19 | + |
| 20 | +describe JavaBuildpack::Framework::MetricWriter do |
| 21 | + include_context 'component_helper' |
| 22 | + |
| 23 | + it 'does not detect without metric-forwarder service' do |
| 24 | + expect(component.detect).to be_nil |
| 25 | + end |
| 26 | + |
| 27 | + context do |
| 28 | + |
| 29 | + before do |
| 30 | + allow(services).to receive(:one_service?).with(/metrics-forwarder/, 'access_key', 'hostname').and_return(true) |
| 31 | + end |
| 32 | + |
| 33 | + it 'detects with metric-forwarder service' do |
| 34 | + expect(component.detect).to eq("metric-writer=#{version}") |
| 35 | + end |
| 36 | + |
| 37 | + it 'downloads Metric Writer JAR', |
| 38 | + cache_fixture: 'stub-metric-writer.jar' do |
| 39 | + |
| 40 | + component.compile |
| 41 | + |
| 42 | + expect(sandbox + "metric_writer-#{version}.jar").to exist |
| 43 | + end |
| 44 | + |
| 45 | + it 'adds the metric writer to the additional libraries in compile when needed', |
| 46 | + cache_fixture: 'stub-metric-writer.jar' do |
| 47 | + |
| 48 | + component.compile |
| 49 | + |
| 50 | + expect(additional_libraries).to include(sandbox + "metric_writer-#{version}.jar") |
| 51 | + end |
| 52 | + |
| 53 | + it 'adds the metric writer to the additional libraries in release when needed', |
| 54 | + cache_fixture: 'stub-metric-writer.jar' do |
| 55 | + |
| 56 | + allow(services).to receive(:find_service).and_return('credentials' => { 'access_key' => 'test-access-key', |
| 57 | + 'hostname' => 'test-hostname' }) |
| 58 | + |
| 59 | + component.release |
| 60 | + |
| 61 | + expect(additional_libraries).to include(sandbox + "metric_writer-#{version}.jar") |
| 62 | + end |
| 63 | + |
| 64 | + it 'updates JAVA_OPTS' do |
| 65 | + allow(services).to receive(:find_service).and_return('credentials' => { 'access_key' => 'test-access-key', |
| 66 | + 'hostname' => 'test-hostname' }) |
| 67 | + |
| 68 | + component.release |
| 69 | + |
| 70 | + expect(java_opts).to include('-Dcloudfoundry.metrics.accessToken=test-access-key') |
| 71 | + expect(java_opts).to include('-Dcloudfoundry.metrics.applicationId=test-application-id') |
| 72 | + expect(java_opts).to include('-Dcloudfoundry.metrics.endpoint=https://test-hostname') |
| 73 | + expect(java_opts).to include('-Dcloudfoundry.metrics.instanceId=$CF_INSTANCE_GUID') |
| 74 | + expect(java_opts).to include('-Dcloudfoundry.metrics.instanceIndex=$CF_INSTANCE_INDEX') |
| 75 | + end |
| 76 | + |
| 77 | + end |
| 78 | + |
| 79 | +end |
0 commit comments