Commit 70fcab50 authored by Geoff Simmons's avatar Geoff Simmons

Test template generation when Services have no Endpoints.

parent af3f7d8d
......@@ -30,6 +30,7 @@ sub vcl_init {
# BAR & BAZ BACKENDS ######################
{{if or (index .Services "bar-service").Endpoints (index .Services "baz-service").Endpoints -}}
probe barbaz_probe {
.url = "/probe.html";
.interval = 5s;
......@@ -37,6 +38,7 @@ probe barbaz_probe {
.window = 10;
.threshold = 1;
}
{{- end}}
{{range $name, $ep := (index .Services "bar-service").Endpoints -}}
backend {{$name}} {
......@@ -57,11 +59,13 @@ backend {{$name}} {
sub vcl_init {
# shard/rr init
new shard_bar_backends = directors.shard();
{{- if (index .Services "bar-service").Endpoints}}
shard_bar_backends.set_rampup(60s);
{{- range $name, $ep := (index .Services "bar-service").Endpoints}}
shard_bar_backends.add_backend({{$name}});
{{- end}}
shard_bar_backends.reconfigure();
{{- end}}
new rr_bar_backends = directors.round_robin();
{{- range $name, $ep := (index .Services "bar-service").Endpoints}}
......@@ -69,11 +73,13 @@ sub vcl_init {
{{- end}}
new shard_baz_backends = directors.shard();
{{- if (index .Services "baz-service").Endpoints}}
shard_baz_backends.set_rampup(60s);
{{- range $name, $ep := (index .Services "baz-service").Endpoints}}
shard_baz_backends.add_backend({{$name}});
{{- end}}
shard_baz_backends.reconfigure();
{{- end}}
new rr_baz_backends = directors.round_robin();
{{- range $name, $ep := (index .Services "baz-service").Endpoints}}
......
# FOO SERVERS #############################
probe foo_probe {
.request = "HEAD /foo_health HTTP/1.1"
"Host: foo"
"Connection: close";
.interval = 3s;
.timeout = 0.3s;
.window = 5;
.threshold = 1;
}
backend foo-stateful-0 {
.host = "172.22.225.25";
.port = "6081";
.probe = foo_probe;
}
backend foo-stateful-1 {
.host = "172.22.225.39";
.port = "6081";
.probe = foo_probe;
}
sub vcl_init {
# foo sharding init
new foo = directors.shard();
foo.set_rampup(0s);
foo.add_backend(foo-stateful-0);
foo.add_backend(foo-stateful-1);
foo.reconfigure();
}
# BAR & BAZ BACKENDS ######################
probe barbaz_probe {
.url = "/probe.html";
.interval = 5s;
.timeout = 3s;
.window = 10;
.threshold = 1;
}
backend baz-5ff49fcd4-hx7lj {
.host = "172.22.225.8";
.port = "8080";
.probe = barbaz_probe;
}
sub vcl_init {
# shard/rr init
new shard_bar_backends = directors.shard();
new rr_bar_backends = directors.round_robin();
new shard_baz_backends = directors.shard();
shard_baz_backends.set_rampup(60s);
shard_baz_backends.add_backend(baz-5ff49fcd4-hx7lj);
shard_baz_backends.reconfigure();
new rr_baz_backends = directors.round_robin();
rr_baz_backends.add_backend(baz-5ff49fcd4-hx7lj);
}
# FOO SERVERS #############################
probe foo_probe {
.request = "HEAD /foo_health HTTP/1.1"
"Host: foo"
"Connection: close";
.interval = 3s;
.timeout = 0.3s;
.window = 5;
.threshold = 1;
}
backend foo-stateful-0 {
.host = "172.22.225.25";
.port = "6081";
.probe = foo_probe;
}
backend foo-stateful-1 {
.host = "172.22.225.39";
.port = "6081";
.probe = foo_probe;
}
sub vcl_init {
# foo sharding init
new foo = directors.shard();
foo.set_rampup(0s);
foo.add_backend(foo-stateful-0);
foo.add_backend(foo-stateful-1);
foo.reconfigure();
}
# BAR & BAZ BACKENDS ######################
sub vcl_init {
# shard/rr init
new shard_bar_backends = directors.shard();
new rr_bar_backends = directors.round_robin();
new shard_baz_backends = directors.shard();
new rr_baz_backends = directors.round_robin();
}
......@@ -196,6 +196,31 @@ func TestTemplate(t *testing.T) {
t.Errorf("Generated VCL at %s does not match gold file %s",
vclPath, filepath.Join("testdata", gold))
}
gold = "backends_nobar.golden"
noEpsSpec := testSpec
svc, _ := noEpsSpec.Services["bar-service"]
svc.Endpoints = map[string]Endpoint{}
noEpsSpec.Services["bar-service"] = svc
if err = noEpsSpec.WriteTemplate(tmpl, vclPath); err != nil {
t.Fatal("WriteTemplate():", err)
}
if !cmpGold(t, vclPath, gold) {
t.Errorf("Generated VCL at %s does not match gold file %s",
vclPath, filepath.Join("testdata", gold))
}
gold = "backends_nosvc.golden"
svc, _ = noEpsSpec.Services["baz-service"]
svc.Endpoints = map[string]Endpoint{}
noEpsSpec.Services["baz-service"] = svc
if err = noEpsSpec.WriteTemplate(tmpl, vclPath); err != nil {
t.Fatal("WriteTemplate():", err)
}
if !cmpGold(t, vclPath, gold) {
t.Errorf("Generated VCL at %s does not match gold file %s",
vclPath, filepath.Join("testdata", gold))
}
}
func TestFQVersion(t *testing.T) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment