diff --git a/.github/workflows/scripts.yml b/.github/workflows/scripts.yml new file mode 100644 index 0000000..27245f9 --- /dev/null +++ b/.github/workflows/scripts.yml @@ -0,0 +1,20 @@ +name: scripts + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + spec-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.4' + bundler-cache: true + - run: ./scripts/subtests/spec-test \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..87300a1 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +gem 'rspec' +gem 'bosh-template' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..9b0d632 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,31 @@ +GEM + remote: https://rubygems.org/ + specs: + bosh-template (2.4.0) + semi_semantic (~> 1.2.0) + diff-lcs (1.6.2) + rspec (3.13.1) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.4) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.5) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.5) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.4) + semi_semantic (1.2.0) + +PLATFORMS + arm64-darwin-24 + ruby + +DEPENDENCIES + bosh-template + rspec + +BUNDLED WITH + 2.6.9 diff --git a/jobs/promtail/templates/config/config.yml.erb b/jobs/promtail/templates/config/config.yml.erb index 39f484c..4656ddf 100644 --- a/jobs/promtail/templates/config/config.yml.erb +++ b/jobs/promtail/templates/config/config.yml.erb @@ -40,7 +40,7 @@ positions: filename: <%= p('promtail.positions.filename') %> clients: <% if_p("promtail.loki.tls", "promtail.loki.mtls") do |promtail_loki_tls,promtail_loki_mtls| %> - - url: <% if promtail_loki_tls == true || promtail_loki_mtls == true %>https://<% else %>https://<% end %><%= p('promtail.loki.server.http_listen_address') %>:<%= p('promtail.loki.server.http_listen_port') %>/loki/api/v1/push + - url: <% if promtail_loki_tls == true || promtail_loki_mtls == true %>https://<% else %>http://<% end %><%= p('promtail.loki.server.http_listen_address') %>:<%= p('promtail.loki.server.http_listen_port') %>/loki/api/v1/push <% if promtail_loki_tls == true || promtail_loki_mtls == true %> tls_config: ca_file: /var/vcap/jobs/promtail/loki/certs/ca.pem diff --git a/scripts/subtests/spec-test b/scripts/subtests/spec-test new file mode 100755 index 0000000..20d3e8f --- /dev/null +++ b/scripts/subtests/spec-test @@ -0,0 +1,18 @@ +#!/bin/bash + +set -eux +set -o pipefail + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +set +e +bundler_executable=$(which bundle) +set -e +if [ -z "${bundler_executable}" ] || [ ! -x "${bundler_executable}" ]; then + gem install bundler +fi + +pushd "${SCRIPT_DIR}/../.." > /dev/null + bundle install + bundle exec rspec +popd > /dev/null \ No newline at end of file diff --git a/spec/jobs/promtail_spec.rb b/spec/jobs/promtail_spec.rb new file mode 100644 index 0000000..868cf73 --- /dev/null +++ b/spec/jobs/promtail_spec.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +require 'rspec' +require 'bosh/template/test' + +describe 'promtail config/config.yml.erb' do + let(:release_dir) { File.join(File.dirname(__FILE__), '../..') } + let(:release) { Bosh::Template::Test::ReleaseDir.new(release_dir) } + let(:job) { release.job('promtail') } + let(:template) { job.template('config/config.yml') } + + let(:properties) do + { + 'promtail' => { + 'loki' => { + 'server' => { + 'http_listen_address' => 'loki.example.com', + 'http_listen_port' => 3100 + }, + 'external_labels' => {} + } + } + } + end + + let(:rendered) { YAML.safe_load(template.render(properties)) } + + context 'when promtail.loki.tls is true' do + before { properties['promtail']['loki']['tls'] = true } + + it 'uses https in the loki client url' do + expect(rendered['clients'][0]['url']).to eq('https://loki.example.com:3100/loki/api/v1/push') + end + end + + context 'when promtail.loki.tls is false' do + before { properties['promtail']['loki']['tls'] = false } + + it 'uses http in the loki client url' do + expect(rendered['clients'][0]['url']).to eq('http://loki.example.com:3100/loki/api/v1/push') + end + end +end