Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
k8s-ingress
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
3
Merge Requests
3
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
uplex-varnish
k8s-ingress
Commits
9d62af99
Commit
9d62af99
authored
Dec 10, 2018
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use a golden file to test VCL generation for Ingress rules.
parent
6217f87e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
103 additions
and
3 deletions
+103
-3
ingressrule.golden
cmd/varnish/vcl/testdata/ingressrule.golden
+85
-0
vcl_test.go
cmd/varnish/vcl/vcl_test.go
+18
-3
No files found.
cmd/varnish/vcl/testdata/ingressrule.golden
0 → 100644
View file @
9d62af99
vcl 4.0;
import std;
import directors;
import re2;
backend notfound {
# 192.0.2.0/24 reserved for docs & examples (RFC5737).
.host = "192.0.2.255";
.port = "80";
}
backend coffee-svc_192_2e_0_2e_2_2e_4 {
.host = "192.0.2.4";
.port = "80";
}
backend coffee-svc_192_2e_0_2e_2_2e_5 {
.host = "192.0.2.5";
.port = "80";
}
backend tea-svc_192_2e_0_2e_2_2e_1 {
.host = "192.0.2.1";
.port = "80";
}
backend tea-svc_192_2e_0_2e_2_2e_2 {
.host = "192.0.2.2";
.port = "80";
}
backend tea-svc_192_2e_0_2e_2_2e_3 {
.host = "192.0.2.3";
.port = "80";
}
sub vcl_init {
new hosts = re2.set(posix_syntax=true, literal=true, anchor=both);
hosts.add("cafe.example.com");
hosts.compile();
new coffee-svc_director = directors.round_robin();
coffee-svc_director.add_backend(coffee-svc_192_2e_0_2e_2_2e_4);
coffee-svc_director.add_backend(coffee-svc_192_2e_0_2e_2_2e_5);
new tea-svc_director = directors.round_robin();
tea-svc_director.add_backend(tea-svc_192_2e_0_2e_2_2e_1);
tea-svc_director.add_backend(tea-svc_192_2e_0_2e_2_2e_2);
tea-svc_director.add_backend(tea-svc_192_2e_0_2e_2_2e_3);
new cafe_2e_example_2e_com_url = re2.set(posix_syntax=true, anchor=start);
cafe_2e_example_2e_com_url.add("/coffee",
backend=coffee-svc_director.backend());
cafe_2e_example_2e_com_url.add("/tea",
backend=tea-svc_director.backend());
cafe_2e_example_2e_com_url.compile();
}
sub set_backend {
set req.backend_hint = notfound;
if (hosts.match(req.http.Host)) {
if (hosts.nmatches() != 1) {
# Fail fast when the match was not unique.
return (fail);
}
if (0 != 0) {
#
}
elsif (hosts.which() == 1) {
if (cafe_2e_example_2e_com_url.match(req.url)) {
set req.backend_hint = cafe_2e_example_2e_com_url.backend(select=FIRST);
}
}
}
if (req.backend_hint == notfound) {
return (synth(404));
}
}
sub vcl_miss {
call set_backend;
}
sub vcl_pass {
call set_backend;
}
cmd/varnish/vcl/vcl_test.go
View file @
9d62af99
...
...
@@ -30,6 +30,8 @@ package vcl
import
(
"bytes"
"io/ioutil"
"path/filepath"
"testing"
)
...
...
@@ -118,12 +120,25 @@ func TestTemplate(t *testing.T) {
if
err
:=
Tmpl
.
Execute
(
&
buf
,
cafeSpec
);
err
!=
nil
{
t
.
Error
(
"Execute():"
,
err
)
}
t
.
Log
(
string
(
buf
.
Bytes
()))
goldpath
:=
filepath
.
Join
(
"testdata"
,
"ingressrule.golden"
)
gold
,
err
:=
ioutil
.
ReadFile
(
goldpath
)
if
err
!=
nil
{
t
.
Fatalf
(
"Error reading %s: %v"
,
goldpath
,
err
)
}
if
!
bytes
.
Equal
(
buf
.
Bytes
(),
gold
)
{
t
.
Errorf
(
"Generated VCL for IngressSpec does not match gold "
+
"file: %s"
,
goldpath
)
if
testing
.
Verbose
()
{
t
.
Log
(
"Generated VCL:"
,
string
(
buf
.
Bytes
()))
t
.
Log
(
goldpath
,
":"
,
string
(
gold
))
}
}
}
func
TestDeepHash
(
t
*
testing
.
T
)
{
t
.
Log
(
"cafeSpec.DeepHash():
"
,
cafeSpec
.
DeepHash
())
t
.
Log
(
"cafeSpec2.DeepHash():
"
,
cafeSpec2
.
DeepHash
())
t
.
Log
f
(
"cafeSpec.DeepHash(): %0x
"
,
cafeSpec
.
DeepHash
())
t
.
Log
f
(
"cafeSpec2.DeepHash() %0x
"
,
cafeSpec2
.
DeepHash
())
if
cafeSpec
.
DeepHash
()
==
cafeSpec2
.
DeepHash
()
{
t
.
Errorf
(
"Distinct specs with different hashes: spec1=%+v "
+
"spec2=%+v hash=%0x"
,
cafeSpec
,
cafeSpec2
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment