<commit_before>set :application, "capistrano-custom-maintenance"
set :repository, "."
set :deploy_to do
  File.join("/home", user, application)
end
set :deploy_via, :copy
set :scm, :none
set :use_sudo, false
set :user, "vagrant"
set :password, "<PASSWORD>"
set :ssh_options, {:user_known_hosts_file => "/dev/null"}

role :web, "192.168.33.10"
role :app, "192.168.33.10"
role :db,  "192.168.33.10", :primary => true

$LOAD_PATH.push(File.expand_path("../../lib", File.dirname(__FILE__)))
require "capistrano-custom-maintenance"
require "capistrano/configuration/resources/platform_resources"
require "tempfile"

def assert_file_exists(file, options={})
  begin
    invoke_command("test -f #{file.dump}", options)
  rescue
    logger.debug("assert_file_exists(#{file}) failed.")
    invoke_command("ls #{File.dirname(file).dump}", options)
    raise
  end
end

def assert_file_not_exists(file, options={})
  begin
    invoke_command("test \! -f #{file.dump}", options)
  rescue
    logger.debug("assert_file_not_exists(#{file}) failed.")
    invoke_command("ls #{File.dirname(file).dump}", options)
    raise
  end
end

def assert_file_content(file, content, options={})
  begin
    tempfile = Tempfile.new("capistrano-custom-maintenance")
    download(file, tempfile.path)
    tempfile.seek(0)
    raise if content != tempfile.read
  rescue
    logger.debug("assert_file_content_type(#{file}, #{content.dump}) failed.")
    raise
  end
end

def assert_file_encoding(file, encoding, options={})
  begin
    invoke_command("test $(nkf -g #{file.dump}) = #{encoding.dump}")
  rescue
    logger.debug("assert_file_encoding(#{file}, #{encoding.dump} failed.")
    raise
  end
end

def assert_command(cmdline, options={})
  begin
    invoke_command(cmdline, options)
  rescue
    logger.debug("assert_command(#{cmdline}) failed.")
    raise
  end
end

def assert_command_fails(cmdline, options={})
  failed = false
  begin
    invoke_command(cmdline, options)
  rescue
    logger.debug("assert_command_fails(#{cmdline}) failed.")
    failed = true
  ensure
    abort unless failed
  end
end

def reset_maintenance!
  variables.each_key do |key|
    reset!(key) if /^maintenance_/ =~ key
  end
end

task(:test_all) {
  find_and_execute_task("test_default")
  find_and_execute_task("test_with_html")
  find_and_execute_task("test_with_javascript")
  find_and_execute_task("test_with_json")
}

on(:start) {
  run("rm -rf #{deploy_to.dump}")
}

namespace(:test_default) {
  task(:default) {
    methods.grep(/^test_/).each do |m|
      send(m)
    end
  }
  before "test_default", "test_default:setup"
  after "test_default", "test_default:teardown"

  task(:setup) {
#   set(:maintenance_template_path, File.expand_path("tmp/maintenance"))
    set(:maintenance_content_type, "text/html")<commit_msg>clean up :deploy_to on test start<commit_after>set :application, "capistrano-custom-maintenance"
set :repository, "."
set :deploy_to do
  File.join("/home", user, application)
end
set :deploy_via, :copy
set :scm, :none
set :use_sudo, false
set :user, "vagrant"
set :password, "<PASSWORD>"
set :ssh_options, {:user_known_hosts_file => "/dev/null"}

role :web, "192.168.33.10"
role :app, "192.168.33.10"
role :db,  "192.168.33.10", :primary => true

$LOAD_PATH.push(File.expand_path("../../lib", File.dirname(__FILE__)))
require "capistrano-custom-maintenance"
require "capistrano/configuration/resources/platform_resources"
require "tempfile"

def assert_file_exists(file, options={})
  begin
    invoke_command("test -f #{file.dump}", options)
  rescue
    logger.debug("assert_file_exists(#{file}) failed.")
    invoke_command("ls #{File.dirname(file).dump}", options)
    raise
  end
end

def assert_file_not_exists(file, options={})
  begin
    invoke_command("test \! -f #{file.dump}", options)
  rescue
    logger.debug("assert_file_not_exists(#{file}) failed.")
    invoke_command("ls #{File.dirname(file).dump}", options)
    raise
  end
end

def assert_file_content(file, content, options={})
  begin
    tempfile = Tempfile.new("capistrano-custom-maintenance")
    download(file, tempfile.path)
    tempfile.seek(0)
    raise if content != tempfile.read
  rescue
    logger.debug("assert_file_content_type(#{file}, #{content.dump}) failed.")
    raise
  end
end

def assert_file_encoding(file, encoding, options={})
  begin
    invoke_command("test $(nkf -g #{file.dump}) = #{encoding.dump}")
  rescue
    logger.debug("assert_file_encoding(#{file}, #{encoding.dump} failed.")
    raise
  end
end

def assert_command(cmdline, options={})
  begin
    invoke_command(cmdline, options)
  rescue
    logger.debug("assert_command(#{cmdline}) failed.")
    raise
  end
end

def assert_command_fails(cmdline, options={})
  failed = false
  begin
    invoke_command(cmdline, options)
  rescue
    logger.debug("assert_command_fails(#{cmdline}) failed.")
    failed = true
  ensure
    abort unless failed
  end
end

def reset_maintenance!
  variables.each_key do |key|
    reset!(key) if /^maintenance_/ =~ key
  end
end

task(:test_all) {
  find_and_execute_task("test_default")
  find_and_execute_task("test_with_html")
  find_and_execute_task("test_with_javascript")
  find_and_execute_task("test_with_json")
}

on(:load) {
  run("rm -rf #{deploy_to.dump}")
}

namespace(:test_default) {
  task(:default) {
    methods.grep(/^test_/).each do |m|
      send(m)
    end
  }
  before "test_default", "test_default:setup"
  after "test_default", "test_default:teardown"

  task(:setup) {
#   set(:maintenance_template_path, File.expand_path("tmp/maintenance"))
    set(:maintenance_content_type, "text/html")
{'fraction_non_alphanumeric': 0.14668572449526532, 'fraction_numerical': 0.011077362872967662, 'mean_word_length': 4.7592592592592595, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1267845', 'n_tokens_mistral': 1966, 'n_tokens_neox': 1924, 'n_words': 386}