|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +# Cloud Foundry Java Buildpack |
| 4 | +# Copyright 2013-2021 the original author or authors. |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | + |
| 18 | +require 'spec_helper' |
| 19 | +require 'component_helper' |
| 20 | +require 'java_buildpack/framework/datadog_javaagent' |
| 21 | +require 'java_buildpack/util/tokenized_version' |
| 22 | + |
| 23 | +describe JavaBuildpack::Framework::DatadogJavaagent do |
| 24 | + include_context 'with component help' |
| 25 | + |
| 26 | + describe '#detect' do |
| 27 | + subject(:detect) { component.detect } |
| 28 | + |
| 29 | + it 'does not detect without an api key' do |
| 30 | + expect(detect).to be nil |
| 31 | + end |
| 32 | + |
| 33 | + context 'when api key is empty' do |
| 34 | + let(:environment) { { 'DD_API_KEY' => '' } } |
| 35 | + |
| 36 | + it { is_expected.to be nil } |
| 37 | + end |
| 38 | + |
| 39 | + context 'when apm is disabled' do |
| 40 | + let(:environment) { { 'DD_API_KEY' => 'foo', 'DD_APM_ENABLED' => 'false' } } |
| 41 | + |
| 42 | + it { is_expected.to be nil } |
| 43 | + end |
| 44 | + |
| 45 | + context 'when apm is enabled with no api key' do |
| 46 | + let(:environment) { { 'DD_APM_ENABLED' => 'true' } } |
| 47 | + |
| 48 | + it { is_expected.to eq("datadog-javaagent=#{version}") } |
| 49 | + end |
| 50 | + |
| 51 | + context 'when apm key is provided' do |
| 52 | + let(:environment) { { 'DD_API_KEY' => 'foo' } } |
| 53 | + |
| 54 | + it { is_expected.to eq("datadog-javaagent=#{version}") } |
| 55 | + end |
| 56 | + end |
| 57 | + |
| 58 | + context 'when apm key is provided' do |
| 59 | + let(:environment) { { 'DD_API_KEY' => 'foo' } } |
| 60 | + |
| 61 | + it 'compile downloads datadog-javaagent JAR', cache_fixture: 'stub-datadog-javaagent.jar' do |
| 62 | + component.compile |
| 63 | + expect(sandbox + "datadog-javaagent-#{version}.jar").to exist |
| 64 | + end |
| 65 | + |
| 66 | + it 'release updates JAVA_OPTS' do |
| 67 | + component.release |
| 68 | + expect(java_opts).to include("-javaagent:$PWD/.java-buildpack/datadog_javaagent/datadog_javaagent-#{version}.jar") |
| 69 | + end |
| 70 | + end |
| 71 | +end |
0 commit comments