<commit_before>require File.join(File.dirname(__FILE__), '..', 'clipp_test')

class TestRegression < Test::Unit::TestCase
  include CLIPPTest

  CONFIG = <<-EOS
    LoadModule "ibmod_lua.so"
  EOS

  def test_sig
    lua = <<-EOS
      Sig("basic1", "1"):
        fields([[REQUEST_METHOD]]):
        op('imatch', [[GET]]):
        phase([[REQUEST_HEADER]]):
        action([[clipp_announce:basic1]])
    EOS
    lua_file = File.expand_path(File.join(BUILDDIR, rand(10000).to_s + '.lua'))
    File.open(lua_file, 'w') {|fp| fp.print lua}

    clipp(
      :input => "echo:\"GET /foo\"",
      :config => CONFIG,
      :default_site_config => <<-EOC
          LuaInclude "#{lua_file}"
          LuaCommitRules
          RuleEnable all
      EOC
    )
    assert_no_issues
    assert_log_match /CLIPP ANNOUNCE: basic1/
  end

  def test_action
    lua = <<-EOS
      Action("basic2", "1"):
        phase([[REQUEST_HEADER]]):
        action([[clipp_announce:basic2]])
    EOS
    lua_file = File.expand_path(File.join(BUILDDIR, rand(10000).to_s + '.lua'))
    File.open(lua_file, 'w') {|fp| fp.print lua}

    clipp(
      :input => "echo:\"GET /foo\"",
      :config => CONFIG,
      :default_site_config => <<-EOC
          LuaInclude "#{lua_file}"
          LuaCommitRules
      EOC
    )
    assert_no_issues
    assert_log_match /CLIPP ANNOUNCE: basic2/
  end
end<commit_msg>clipp/tests: Clean up Lua waggle tests.<commit_after>require File.join(File.dirname(__FILE__), '..', 'clipp_test')

class TestRegression < Test::Unit::TestCase
  include CLIPPTest

  def make_config(file, extras = {})
    return {
      :config => "LoadModule \"ibmod_lua.so\"\n" +
        "LuaInclude \"#{file}\"\n" +
        "LuaCommitRules",
      :default_site_config => "RuleEnable all",
    }.merge(extras)
  end

  SITE_CONFIG = "RuleEnable all"


  def test_sig
    lua = <<-EOS
      Sig("basic1", "1"):
        fields([[REQUEST_METHOD]]):
        op('imatch', [[GET]]):
        phase([[REQUEST_HEADER]]):
        action([[clipp_announce:basic1]])
    EOS
    lua_file = File.expand_path(File.join(BUILDDIR, rand(10000).to_s + '.lua'))
    File.open(lua_file, 'w') {|fp| fp.print lua}

    clipp(make_config(lua_file,
      :input => "echo:\"GET /foo\""
    ))
    assert_no_issues
    assert_log_match /CLIPP ANNOUNCE: basic1/
  end

  def test_action
    lua = <<-EOS
      Action("basic2", "1"):
        phase([[REQUEST_HEADER]]):
        action([[clipp_announce:basic2]])
    EOS
    lua_file = File.expand_path(File.join(BUILDDIR, rand(10000).to_s + '.lua'))
    File.open(lua_file, 'w') {|fp| fp.print lua}

    clipp(make_config(lua_file,
      :input => "echo:\"GET /foo\""
    ))
    assert_no_issues
    assert_log_match /CLIPP ANNOUNCE: basic2/
  end
end
{'fraction_non_alphanumeric': 0.16145454545454546, 'fraction_numerical': 0.01309090909090909, 'mean_word_length': 2.7684931506849315, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 13, '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': '4123464', 'n_tokens_mistral': 1039, 'n_tokens_neox': 1013, 'n_words': 181}