Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/scripts.yml
Original file line number Diff line number Diff line change
@@ -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'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if its OK to use newer version here?

bundler-cache: true
- run: ./scripts/subtests/spec-test
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

gem 'rspec'
gem 'bosh-template'
31 changes: 31 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion jobs/promtail/templates/config/config.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions scripts/subtests/spec-test
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions spec/jobs/promtail_spec.rb
Original file line number Diff line number Diff line change
@@ -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