<commit_before>require './lib/vtc'
require './lib/vcl'
require './lib/client_test_base'
require './lib/server'
require './lib/varnish'

module Urushiol
  class VarnishTestBase
    def initialize (name,vcl_file_ref=nil)
      @vtc_obj    = Vtc.new(name)
      @vcl_source = vcl_file_ref
    end

    def mock_varnish(name)
      varnish = Varnish.new(name)
      yield varnish if block_given?
      @vtc_obj.append_config(varnish.varnish_source)
    end

    def mock_backends(source=@vcl_source)
      if source != nil
        @vtc_obj.mock_backends(Vcl.new(source).get_conf)
      else
        puts "\nCan't mock backends if no VCL file is specified.\n"
      end
    end

    def server(&block)
      if block_given?
        @vtc_obj.append_config(yield Server)
      end
    end

    def define_tests(tests)
      @vtc_obj.mock_clients_and_tests(tests)
    end

    def client_testcase(name,config="",&block)
      test = ClientTestBase.new(name,config)
      yield test if block_given?
      @vtc_obj.append_config(test.test_source)
    end

    def mock_server(name,&block)
      server = Server.new(name)
      yield server if block_given?
      @vtc_obj.append_config(server.server_source)
    end

    def create_test_file(vtc)
      File.open('/tmp/test.vtc', "wb") { |f| f.write(vtc.get_spec) }
    end

    def override_vcl_file(vcl_file)
      File.open('/tmp/test.vcl', "wb") { |f| f.write(Vcl.new(vcl_file).get_conf) }
    end

    def get_vcl
      @vcl_source
    end

    def delay(time)
      @vtc_obj.append_config("\ndelay #{time}")
    end

    def run
      create_test_file(@vtc_obj)
      system("varnishtest /tmp/test.vtc")
      cleanup
    end

    def cleanup
      #system("rm /tmp/test.vtc")
    end
  end<commit_msg>now cleans up after itself when tests have been ran<commit_after>require './lib/vtc'
require './lib/vcl'
require './lib/client_test_base'
require './lib/server'
require './lib/varnish'

module Urushiol
  class VarnishTestBase
    def initialize (name,vcl_file_ref=nil)
      @vtc_obj    = Vtc.new(name)
      @vcl_source = vcl_file_ref
    end

    def mock_varnish(name)
      varnish = Varnish.new(name)
      yield varnish if block_given?
      @vtc_obj.append_config(varnish.varnish_source)
    end

    def mock_backends(source=@vcl_source)
      if source != nil
        @vtc_obj.mock_backends(Vcl.new(source).get_conf)
      else
        puts "\nCan't mock backends if no VCL file is specified.\n"
      end
    end

    def server(&block)
      if block_given?
        @vtc_obj.append_config(yield Server)
      end
    end

    def define_tests(tests)
      @vtc_obj.mock_clients_and_tests(tests)
    end

    def client_testcase(name,config="",&block)
      test = ClientTestBase.new(name,config)
      yield test if block_given?
      @vtc_obj.append_config(test.test_source)
    end

    def mock_server(name,&block)
      server = Server.new(name)
      yield server if block_given?
      @vtc_obj.append_config(server.server_source)
    end

    def create_test_file(vtc)
      File.open('/tmp/test.vtc', "wb") { |f| f.write(vtc.get_spec) }
    end

    def override_vcl_file(vcl_file)
      File.open('/tmp/test.vcl', "wb") { |f| f.write(Vcl.new(vcl_file).get_conf) }
    end

    def get_vcl
      @vcl_source
    end

    def delay(time)
      @vtc_obj.append_config("\ndelay #{time}")
    end

    def run
      create_test_file(@vtc_obj)
      system("varnishtest /tmp/test.vtc")
      cleanup
    end

    def cleanup
      system("rm /tmp/test.vtc")
      system("rm /tmp/test.vcl")
    end
  end
{'fraction_non_alphanumeric': 0.11054994388327721, 'fraction_numerical': 0.0, 'mean_word_length': 2.6340468909276247, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2388392', 'n_tokens_mistral': 1337, 'n_tokens_neox': 1291, 'n_words': 248}