|
| 1 | +#!/usr/bin/env bats |
| 2 | + |
| 3 | +load test_helper |
| 4 | + |
| 5 | +REPO_ROOT="$(cd "$(dirname "${BATS_TEST_FILENAME:-$0}")/.." && pwd)" |
| 6 | + |
| 7 | +setup() { |
| 8 | + strict_setup |
| 9 | + mkdir -p "$BATS_TEST_TMPDIR/bin" |
| 10 | + export SEED_CAPTURE="$BATS_TEST_TMPDIR/seed" |
| 11 | + export TMPDIR="$BATS_TEST_TMPDIR" |
| 12 | + export PATH="$BATS_TEST_TMPDIR/bin:$PATH" |
| 13 | + cat > "$BATS_TEST_TMPDIR/bin/curl" <<'EOF' |
| 14 | +#!/usr/bin/env bash |
| 15 | +set -eu |
| 16 | +printf '%s\n' "$@" > "$SEED_CAPTURE.args" |
| 17 | +cat > "$SEED_CAPTURE.body" |
| 18 | +if ! grep --fixed-strings --line-regexp --quiet 'Content-Type: application/json' "$SEED_CAPTURE.args"; then |
| 19 | + echo 'seed request is missing its JSON content type' >&2 |
| 20 | + exit 22 |
| 21 | +fi |
| 22 | +EOF |
| 23 | + chmod +x "$BATS_TEST_TMPDIR/bin/curl" |
| 24 | +} |
| 25 | + |
| 26 | +assert_seed_request() { |
| 27 | + local account=$1 |
| 28 | + # shellcheck source=e2e-chainsaw/observability-proxy/lib.sh |
| 29 | + . "$REPO_ROOT/hack/e2e-chainsaw/observability-proxy/lib.sh" |
| 30 | + if [ "$account" = 0 ]; then |
| 31 | + ingest tenant-test-logsa e2e-marker-a |
| 32 | + else |
| 33 | + ingest tenant-test-logsa e2e-marker-a "$account" |
| 34 | + fi |
| 35 | + grep --fixed-strings --line-regexp --quiet "AccountID: $account" "$SEED_CAPTURE.args" |
| 36 | + grep --fixed-strings --line-regexp --quiet 'ProjectID: 0' "$SEED_CAPTURE.args" |
| 37 | + grep --fixed-strings --line-regexp --quiet 'http://localhost:19471/insert/jsonline?_stream_fields=kubernetes_namespace_name&_msg_field=log' "$SEED_CAPTURE.args" |
| 38 | + grep --fixed-strings --line-regexp --quiet -- '--data-binary' "$SEED_CAPTURE.args" |
| 39 | + grep --fixed-strings --line-regexp --quiet '@-' "$SEED_CAPTURE.args" |
| 40 | + printf '%s\n' '{"kubernetes_namespace_name":"tenant-test-logsa","log":"e2e-marker-a"}' > "$SEED_CAPTURE.expected" |
| 41 | + cmp "$SEED_CAPTURE.expected" "$SEED_CAPTURE.body" |
| 42 | + rm "$body" |
| 43 | +} |
| 44 | + |
| 45 | +@test "observability seeds send JSON without consuming the body as form data" { |
| 46 | + assert_seed_request 0 |
| 47 | +} |
| 48 | + |
| 49 | +@test "observability seeds preserve an explicit VictoriaLogs account" { |
| 50 | + assert_seed_request 7 |
| 51 | +} |
0 commit comments