|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | +fixture=$(mktemp) |
| 4 | +trap 'rm -f "$fixture"' EXIT |
| 5 | + |
| 6 | +# Use real Helm renders, including YAML values (not just --set, which can |
| 7 | +# preserve a different numeric type). No deployment or real secrets are needed. |
| 8 | +env -u GEM_HOME -u GEM_PATH -u RUBYLIB -u RUBYOPT ruby -rjson -ryaml -ropen3 \ |
| 9 | + - "$fixture" <<'RUBY' |
| 10 | +chart = 'deploy/charts/buzz-push-gateway' |
| 11 | +command = ['helm', 'template', 'push', chart, '--set', 'gatewayOrigin=https://push.example'] |
| 12 | +cases = [] |
| 13 | +render = lambda do |label, expected, args, values| |
| 14 | + output, error, status = Open3.capture3(*command, *args, stdin_data: values) |
| 15 | + raise "#{label}: Helm failed: #{error}" unless status.success? |
| 16 | + deployment = YAML.load_stream(output).compact.find { |x| x['kind'] == 'Deployment' } |
| 17 | + entries = deployment.fetch('spec').fetch('template').fetch('spec').fetch('containers')[0].fetch('env') |
| 18 | + # Secret references are intentionally excluded; Config's fixture supplies |
| 19 | + # synthetic keyrings and database configuration in memory. |
| 20 | + literal_env = entries.select { |entry| entry.key?('value') }.to_h do |entry| |
| 21 | + value = entry.fetch('value') |
| 22 | + raise "#{label}: #{entry['name']} is not a string" unless value.is_a?(String) |
| 23 | + [entry.fetch('name'), value] |
| 24 | + end |
| 25 | + raise "#{label}: lifetime missing" unless literal_env.key?('BUZZ_PUSH_MAX_GRANT_LIFETIME_SECONDS') |
| 26 | + cases << [label, expected, literal_env] |
| 27 | +end |
| 28 | +render.call('default', 2592000, [], '') |
| 29 | +[1, 2592000, 2592001, 31536000].each do |seconds| |
| 30 | + render.call("values #{seconds}", seconds, ['-f', '-'], "maxGrantLifetimeSeconds: #{seconds}\n") |
| 31 | + render.call("set #{seconds}", seconds, ['--set', "maxGrantLifetimeSeconds=#{seconds}"], '') |
| 32 | +end |
| 33 | +
|
| 34 | +# Integer conversion must never hide invalid inputs. Helm's schema remains |
| 35 | +# authoritative, including rejecting strings that merely look numeric. |
| 36 | +['0', '-1', '31536001', '2592000.5', '"2592000"', 'true'].each do |value| |
| 37 | + _, error, status = Open3.capture3(*command, '-f', '-', stdin_data: "maxGrantLifetimeSeconds: #{value}\n") |
| 38 | + unless !status.success? && error.include?('maxGrantLifetimeSeconds') |
| 39 | + raise "expected schema rejection for #{value}: #{error}" |
| 40 | + end |
| 41 | +end |
| 42 | +File.write(ARGV.fetch(0), JSON.generate(cases)) |
| 43 | +RUBY |
| 44 | + |
| 45 | +BUZZ_TEST_HELM_ENV_FILE="$fixture" cargo test -p buzz-push-gateway --lib \ |
| 46 | + config::tests::helm_rendered_grant_lifetimes -- --ignored --exact |
0 commit comments