Skip to content

Commit

Permalink
Add test cases
Browse files Browse the repository at this point in the history
- Adds test case for parsing template variables in arrays.
- Adds test case for unquoted template varibles (invalid yaml) raising
  an error during template compilation.

Signed-off-by: Carson Long <[email protected]>
  • Loading branch information
acosta11 authored and ctlong committed Aug 30, 2024
1 parent 1f0378f commit bb8ecf0
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions spec/support/shared_examples_for_otel_collector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,11 @@ def without_internal_telemetry(cfg)
'headers' => {
'auth' => '{{ .anothersecret.secret }}'
}
},
'prometheus/test' => {
'tags' => [
'{{ .anothersecret.secret }}'
]
}
},
'service' => {
Expand Down Expand Up @@ -649,6 +654,7 @@ def without_internal_telemetry(cfg)
expect(rendered['exporters']['otlp']['tls']['key_pem']).to eq('bar')
expect(rendered['exporters']['otlp']['tls']['ca_pem']).to eq('baz')
expect(rendered['exporters']['otlp']['headers']['auth']).to eq('foobarbaz')
expect(rendered['exporters']['prometheus/test']['tags'][0]).to eq('foobarbaz')
end

context 'when no secrets exist for template variables' do
Expand All @@ -663,12 +669,14 @@ def without_internal_telemetry(cfg)
expect(rendered['exporters']['otlp']['tls']['key_pem']).to eq('{{ .testsecret.key }}')
expect(rendered['exporters']['otlp']['tls']['ca_pem']).to eq('{{ .testsecret.ca }}')
expect(rendered['exporters']['otlp']['headers']['auth']).to eq('{{ .anothersecret.secret }}')
expect(rendered['exporters']['prometheus/test']['tags'][0]).to eq('{{ .anothersecret.secret }}')
end
end

context 'when no template variables exist for a secret' do
before do
config['exporters']['otlp'].delete('headers')
config['exporters'].delete('prometheus/test')
end

it 'raises an error' do
Expand All @@ -688,6 +696,7 @@ def without_internal_telemetry(cfg)
expect(rendered['exporters']['otlp']['tls']['key_pem']).to eq('bar')
expect(rendered['exporters']['otlp']['tls']['ca_pem']).to eq('baz')
expect(rendered['exporters']['otlp']['headers']['auth']).to eq('foobarbaz')
expect(rendered['exporters']['prometheus/test']['tags'][0]).to eq('foobarbaz')
end
end

Expand All @@ -702,6 +711,22 @@ def without_internal_telemetry(cfg)
expect { rendered }.to raise_error(/The following secrets are unused: \['testsecret.cert', 'testsecret.key', 'testsecret.ca'\]/)
end
end

context 'when template variables are not quoted' do
before do
properties['config'] = '
exporters:
otlp/other:
endpoint: otelcol:4317
headers:
auth: {{ .test.secret }}'
properties['secrets'] = [{'name' => 'test', 'secret' => 'mysecret'}]
end

it 'does not match secrets to those variables' do
expect { rendered }.to raise_error(/The following secrets are unused: \['test.secret'\]/)
end
end
end
end
end

0 comments on commit bb8ecf0

Please sign in to comment.