<commit_before>require 'json'
require 'time'
require 'cgi'

test_name "validation of basic PuppetDB resource event queries" do

  skip_test "Skipping read-db test for HyperSQL.  This feature is only available for Postgres" if test_config[:database] == :embedded

  step "Create second database as a read-only database" do

    second_db_manifest = <<MANIFEST
include postgresql::server
postgresql::db{ "puppetdb2":
    user     => 'puppetdb2',
    password => '<PASSWORD>',
    grant    => 'all',
    require  => Class['::postgresql::server'],
  }
MANIFEST
  
    apply_manifest_on(database, second_db_manifest)
    sleep_until_started(database)
  end

  step "Copy db schema to the new puppetdb2 database" do

    duplicate_db_command = <<DUPE
    su postgres -c "pg_dump puppetdb | sed -e 's/OWNER TO.*;/OWNER TO puppetdb2;/i' | psql puppetdb2"
DUPE
  
    on database, duplicate_db_command
  end

  step "Update puppetdb database.ini to include a read database" do
    on database, "cp -p #{puppetdb_confdir(database)}/conf.d/database.ini #{puppetdb_confdir(database)}/conf.d/database.ini.bak"

    on database, "echo '[read-database]
classname = org.postgresql.Driver
subprotocol = postgresql
subname = //localhost:5432/puppetdb2
username = puppetdb2
password = <PASSWORD>
' >> #{puppetdb_confdir(database)}/conf.d/database.ini"

    restart_puppetdb database<commit_msg>Fix report tests to utilise postgresql 3.0.0 syntax<commit_after>require 'json'
require 'time'
require 'cgi'

test_name "validation of basic PuppetDB resource event queries" do

  skip_test "Skipping read-db test for HyperSQL.  This feature is only available for Postgres" if test_config[:database] == :embedded

  step "Create second database as a read-only database" do

    second_db_manifest = <<MANIFEST
include postgresql::server
postgresql::server::db{ 'puppetdb2':
  user     => 'puppetdb2',
  password => '<PASSWORD>',
  grant    => 'all',
  require  => Class['::postgresql::server'],
}
MANIFEST
  
    apply_manifest_on(database, second_db_manifest)
    sleep_until_started(database)
  end

  step "Copy db schema to the new puppetdb2 database" do

    duplicate_db_command = <<DUPE
    su postgres -c "pg_dump puppetdb | sed -e 's/OWNER TO.*;/OWNER TO puppetdb2;/i' | psql puppetdb2"
DUPE
  
    on database, duplicate_db_command
  end

  step "Update puppetdb database.ini to include a read database" do
    on database, "cp -p #{puppetdb_confdir(database)}/conf.d/database.ini #{puppetdb_confdir(database)}/conf.d/database.ini.bak"

    on database, "echo '[read-database]
classname = org.postgresql.Driver
subprotocol = postgresql
subname = //localhost:5432/puppetdb2
username = puppetdb2
password = <PASSWORD>
' >> #{puppetdb_confdir(database)}/conf.d/database.ini"

    restart_puppetdb database
{'fraction_non_alphanumeric': 0.10768126346015794, 'fraction_numerical': 0.008973438621679828, 'mean_word_length': 4.401162790697675, 'pattern_counts': {'":': 1, '<': 15, '<?xml version=': 0, '>': 19, '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': '5623383', 'n_tokens_mistral': 963, 'n_tokens_neox': 919, 'n_words': 250}