<commit_before>#!/bin/bash

setup() {
  export OLD_DATA_DIRECTORY="$DATA_DIRECTORY"
  export OLD_SSL_DIRECTORY="$SSL_DIRECTORY"
  export DATA_DIRECTORY=/tmp/datadir
  export SSL_DIRECTORY=/tmp/ssldir
  export QUERY="printjson(db.getCollectionNames())"
  export DATABASE_USER="aptible"
  export DATABASE_PASSWORD="<PASSWORD>"
  export DATABASE_CLUSTER_KEY="key1234"
  export DATABASE_URL_NO_SSL="mongodb://$DATABASE_USER:$DATABASE_PASSWORD@localhost/db"
  export DATABASE_URL="$DATABASE_URL_NO_SSL?ssl=true&x-sslVerify=false"
  rm -rf "$DATA_DIRECTORY"
  rm -rf "$SSL_DIRECTORY"
  mkdir -p "$DATA_DIRECTORY"
  mkdir -p "$SSL_DIRECTORY"
}

teardown() {
  # Dump log, if any (facilitates troubleshooting)
  cat "$BATS_TEST_DIRNAME/mongodb.log" || true
  # Actually teardown
  export DATA_DIRECTORY="$OLD_DATA_DIRECTORY"
  export SSL_DIRECTORY="$OLD_SSL_DIRECTORY"
  unset OLD_DATA_DIRECTORY
  unset OLD_SSL_DIRECTORY
  unset QUERY
  unset DATABASE_USER
  unset DATABASE_PASSWORD
  unset DATABASE_CLUSTER_KEY
  unset DATABASE_URL
  PID=$(pgrep mongod) || return 0
  run pkill mongod
  while [ -n "$PID" ] && [ -e "/proc/${PID}" ]; do sleep 0.1; done
}

initialize_mongodb() {
  USERNAME="$DATABASE_USER" CLUSTER_KEY="$DATABASE_CLUSTER_KEY" PASSPHRASE="$DATABASE_PASSWORD" DATABASE=db run-database.sh --initialize
}

wait_for_mongodb() {
  run-database.sh > "$BATS_TEST_DIRNAME/mongodb.log" &

  # Try to connect as "DATABASE_USER" or without user (depending on how we started)
  for i in $(seq 10 -1 0); do
    if mongo --ssl --sslAllowInvalidCertificates -u "$DATABASE_USER" -p "$DATABASE_PASSWORD" db  --eval 'quit(0)'; then
      break<commit_msg>Remove data directory after tests to avoid committing large journal files<commit_after>#!/bin/bash

setup() {
  export OLD_DATA_DIRECTORY="$DATA_DIRECTORY"
  export OLD_SSL_DIRECTORY="$SSL_DIRECTORY"
  export DATA_DIRECTORY=/tmp/datadir
  export SSL_DIRECTORY=/tmp/ssldir
  export QUERY="printjson(db.getCollectionNames())"
  export DATABASE_USER="aptible"
  export DATABASE_PASSWORD="<PASSWORD>"
  export DATABASE_CLUSTER_KEY="key1234"
  export DATABASE_URL_NO_SSL="mongodb://$DATABASE_USER:$DATABASE_PASSWORD@localhost/db"
  export DATABASE_URL="$DATABASE_URL_NO_SSL?ssl=true&x-sslVerify=false"
  rm -rf "$DATA_DIRECTORY"
  rm -rf "$SSL_DIRECTORY"
  mkdir -p "$DATA_DIRECTORY"
  mkdir -p "$SSL_DIRECTORY"
}

teardown() {
  # Dump log, if any (facilitates troubleshooting)
  cat "$BATS_TEST_DIRNAME/mongodb.log" || true
  # Actually teardown
  export DATA_DIRECTORY="$OLD_DATA_DIRECTORY"
  export SSL_DIRECTORY="$OLD_SSL_DIRECTORY"
  unset OLD_DATA_DIRECTORY
  unset OLD_SSL_DIRECTORY
  unset QUERY
  unset DATABASE_USER
  unset DATABASE_PASSWORD
  unset DATABASE_CLUSTER_KEY
  unset DATABASE_URL
  PID=$(pgrep mongod) || return 0
  run pkill mongod
  while [ -n "$PID" ] && [ -e "/proc/${PID}" ]; do sleep 0.1; done
  rm -rf "$DATA_DIRECTORY"
  rm -rf "$SSL_DIRECTORY"
}

initialize_mongodb() {
  USERNAME="$DATABASE_USER" CLUSTER_KEY="$DATABASE_CLUSTER_KEY" PASSPHRASE="$DATABASE_PASSWORD" DATABASE=db run-database.sh --initialize
}

wait_for_mongodb() {
  run-database.sh > "$BATS_TEST_DIRNAME/mongodb.log" &

  # Try to connect as "DATABASE_USER" or without user (depending on how we started)
  for i in $(seq 10 -1 0); do
    if mongo --ssl --sslAllowInvalidCertificates -u "$DATABASE_USER" -p "$DATABASE_PASSWORD" db  --eval 'quit(0)'; then
      break
{'fraction_non_alphanumeric': 0.115712187958884, 'fraction_numerical': 0.007048458149779736, 'mean_word_length': 5.204007285974499, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5590849', 'n_tokens_mistral': 1344, 'n_tokens_neox': 1274, 'n_words': 263}