0

I am currently trying to add some unitests to my growing varnish config file.

i managed to initialize it, and i think i got the basics of varnishtest and vtc format.

i need to load my varnish.vcl - inside there, are a few backends. which have .host to some internal hosts, those are not resolveable from the CI machine.

how can i override a backend?

my idea is basically like: (api01 is defined in varnish.vcl with a internal dns.)

varnish v1 -vcl {
  # …some vcl to define backends… #
  include "${pwd}/varnish.vcl";
  backend api01 { .host = "127.0.0.1"; } 
} 
varnish v1 -start

it fails - that Backend host '"api_loadbalancer"' could not be resolved to an IP address

but it does not continue to define the backend above (with 127.0.0.1) - doing the backend before the include, results in a redefinition error.

what is the correct way to mock a backend?

Helmut Januschka
  • 1,578
  • 3
  • 16
  • 34

1 Answers1

0

We have split our VCL code into multiple files and then "include" all of them into a "main.vcl" which we then use to start Varnish. Here is a simplified example structure:

main.vcl
-- backends.vcl
-- directors.vcl
-- mainLogic.vcl

This enables you to only include some of the vcl-files into your test case and allows you to specify the backends. For example if you want to use a real backend:

varnish v1 -vcl {
  backend api01 { .host = "127.0.0.1"; } 
  include "${pwd}/mainLogic.vcl";
} 

or if you want to mock the backends (what we do):

varnish v1 -vcl {
  backend api01 { 
    .host = "${s1_addr}";
    .port = "${s1_port}"; 
  } 
  include "${pwd}/mainLogic.vcl";
}
Ronald
  • 2,864
  • 3
  • 25
  • 36
  • just to give you a further idea: we "meta-program" our varnish tests. what i mean by this is that we have ruby code and configuration in JSON and the ruby code can generate VCL code for backends and directors from the configuration, etc. – Ronald Dec 22 '16 at 12:20
  • that sounds awesome! - is there anything you can share with me? – Helmut Januschka Dec 22 '16 at 13:28
  • sorry, but this would be very much tailored to our needs and is not generic code. what i wanted to add - we have JSON config for each target platform (ci, stage, prod) and generate different VCL for each platform. – Ronald Dec 22 '16 at 17:56