Class: Urushiol::Vtc

Inherits:
Object
  • Object
show all
Defined in:
lib/vtc.rb

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Vtc

Returns a new instance of Vtc.



4
5
6
# File 'lib/vtc.rb', line 4

def initialize(name)
  @vtc = ""
end

Instance Method Details

#append_config(tests) ⇒ Object



32
33
34
# File 'lib/vtc.rb', line 32

def append_config(tests)
  @vtc << tests
end

#get_specObject



41
42
43
# File 'lib/vtc.rb', line 41

def get_spec
  @vtc
end

#mock_backends(vcl) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/vtc.rb', line 8

def mock_backends(vcl)
  if vcl != nil
    backends = vcl.scan(/^backend (\w*)\W+/).flatten

    #Mock servers in vtc-file
    backends.each do |backend|
      index = backends.index(backend)
      @vtc << "server s#{index} -repeat 10000 {
          # Receive a request
          rxreq
          # Send a standard response
          txresp -hdr \"Connection: close\" -body \"#{backend}\"
        } -start \n"

      #mock backends in vcl-file
      vcl.gsub!(/(?m)backend #{backend} \{(.*?)\}/,
                 "backend #{backend} {\n  .host = \"${s#{index}_addr}\";\n  .port = \"${s#{index}_port}\";\n}")
    end
    @test_vcl = vcl
  else
    puts("no vcl-file given")
  end
end

#mock_varnishObject



36
37
38
39
# File 'lib/vtc.rb', line 36

def mock_varnish
  @vtc << "# Start a varnish instance called \"v1\" from vcl and override backends with mock server adresses
          varnish v1 -arg \"-f /tmp/test.vcl\" -start \n"
end