Skip to content

Commit 154c79d

Browse files
committed
Add test files
Start with promtail config file for now. Based on https://github.com/cloudfoundry/otel-collector-release
1 parent 97a2fbd commit 154c79d

File tree

5 files changed

+116
-0
lines changed

5 files changed

+116
-0
lines changed

.github/workflows/scripts.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: scripts
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
spec-test:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: ruby/setup-ruby@v1
17+
with:
18+
ruby-version: '3.4'
19+
bundler-cache: true
20+
- run: ./scripts/subtests/spec-test

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'rspec'
4+
gem 'bosh-template'

Gemfile.lock

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
bosh-template (2.4.0)
5+
semi_semantic (~> 1.2.0)
6+
diff-lcs (1.6.2)
7+
rspec (3.13.1)
8+
rspec-core (~> 3.13.0)
9+
rspec-expectations (~> 3.13.0)
10+
rspec-mocks (~> 3.13.0)
11+
rspec-core (3.13.4)
12+
rspec-support (~> 3.13.0)
13+
rspec-expectations (3.13.5)
14+
diff-lcs (>= 1.2.0, < 2.0)
15+
rspec-support (~> 3.13.0)
16+
rspec-mocks (3.13.5)
17+
diff-lcs (>= 1.2.0, < 2.0)
18+
rspec-support (~> 3.13.0)
19+
rspec-support (3.13.4)
20+
semi_semantic (1.2.0)
21+
22+
PLATFORMS
23+
arm64-darwin-24
24+
ruby
25+
26+
DEPENDENCIES
27+
bosh-template
28+
rspec
29+
30+
BUNDLED WITH
31+
2.6.9

scripts/subtests/spec-test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
set -eux
4+
set -o pipefail
5+
6+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
7+
8+
set +e
9+
bundler_executable=$(which bundle)
10+
set -e
11+
if [ -z "${bundler_executable}" ] || [ ! -x "${bundler_executable}" ]; then
12+
gem install bundler
13+
fi
14+
15+
pushd "${SCRIPT_DIR}/../.." > /dev/null
16+
bundle install
17+
bundle exec rspec
18+
popd > /dev/null

spec/jobs/promtail_spec.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# frozen_string_literal: true
2+
3+
require 'rspec'
4+
require 'bosh/template/test'
5+
6+
describe 'promtail config/config.yml.erb' do
7+
let(:release_dir) { File.join(File.dirname(__FILE__), '../..') }
8+
let(:release) { Bosh::Template::Test::ReleaseDir.new(release_dir) }
9+
let(:job) { release.job('promtail') }
10+
let(:template) { job.template('config/config.yml') }
11+
12+
let(:properties) do
13+
{
14+
'promtail' => {
15+
'loki' => {
16+
'server' => {
17+
'http_listen_address' => 'loki.example.com',
18+
'http_listen_port' => 3100
19+
},
20+
'external_labels' => {}
21+
}
22+
}
23+
}
24+
end
25+
26+
let(:rendered) { YAML.safe_load(template.render(properties)) }
27+
28+
context 'when promtail.loki.tls is true' do
29+
before { properties['promtail']['loki']['tls'] = true }
30+
31+
it 'uses https in the loki client url' do
32+
expect(rendered['clients'][0]['url']).to eq('https://loki.example.com:3100/loki/api/v1/push')
33+
end
34+
end
35+
36+
context 'when promtail.loki.tls is false' do
37+
before { properties['promtail']['loki']['tls'] = false }
38+
39+
it 'uses http in the loki client url' do
40+
expect(rendered['clients'][0]['url']).to eq('http://loki.example.com:3100/loki/api/v1/push')
41+
end
42+
end
43+
end

0 commit comments

Comments
 (0)