Commit 25b93d75 authored by Geoff Simmons's avatar Geoff Simmons

Add e2e tests for Ingresses without host fields.

Forgot it in the previous commit.
parent c126ae04
# Copyright (c) 2020 UPLEX Nils Goroll Systemoptimierung
# All rights reserved
#
# Author: Geoffrey Simmons <geoffrey.simmons@uplex.de>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
# GNU make is required.
mkpath := $(abspath $(lastword $(MAKEFILE_LIST)))
mkdir := $(dir $(mkpath))
CHARTDIR=$(mkdir)/../../../charts
TESTDIR=$(mkdir)/../..
all: deploy
no-kubectl:
$(warning This test runs with helm only)
@true
ifeq ($(DEPLOY),kubectl)
deploy-fanout-nohost verify-fanout-nohost wait uninstall undeploy: no-kubectl
deploy-vhost-nohost verify-vhost-nohost: no-kubectl
else
deploy-fanout-nohost:
@helm install viking-ingress $(CHARTDIR)/viking-test-app \
--values values-fanout-nohost.yaml
deploy-vhost-nohost:
@helm install viking-ingress $(CHARTDIR)/viking-test-app \
--values values-vhost-nohost.yaml
# TESTOPTS are passed to varnishtest, e.g.: make TESTOPTS=-v verify
verify-fanout-nohost:
$(mkdir)/verify.sh fanout-nohost.vtc
verify-vhost-nohost:
$(mkdir)/verify.sh vhost-nohost.vtc
wait:
@echo Waiting until varnish-ingress Pods are not configured for Ingress
$(TESTDIR)/wait.sh app=varnish-ingress
uninstall:
@helm uninstall viking-ingress
undeploy: uninstall wait
endif
no-example:
$(error EXAMPLE must be set to fanout-nohost or vhost-nohost)
ifeq ($(EXAMPLE),fanout-nohost)
deploy: deploy-fanout-nohost
verify: verify-fanout-nohost
else ifeq ($(EXAMPLE),vhost-nohost)
deploy: deploy-vhost-nohost
verify: verify-vhost-nohost
else
deploy verify: no-example
endif
.PHONY: all $(MAKECMDGOALS)
# looks like -*- vcl -*-
varnishtest "simple fanout by path with no host specified in Ingress"
client c1 -connect "${localhost} ${localport}" {
txreq -url /coffee/foo/bar -hdr "Host: example.com"
rxresp
expect resp.status == 200
expect resp.body ~ "(?m)^URI: /coffee/foo/bar$"
expect resp.body ~ "(?m)^Server name: coffee-[a-z0-9]+-[a-z0-9]+$"
txreq -url /tea/baz/quux -hdr "Host: example.org"
rxresp
expect resp.status == 200
expect resp.body ~ "(?m)^URI: /tea/baz/quux$"
expect resp.body ~ "(?m)^Server name: tea-[a-z0-9]+-[a-z0-9]+$"
txreq -url /coffee/foo/bar
rxresp
expect resp.status == 200
expect resp.body ~ "(?m)^URI: /coffee/foo/bar$"
expect resp.body ~ "(?m)^Server name: coffee-[a-z0-9]+-[a-z0-9]+$"
txreq -url /tea/baz/quux
rxresp
expect resp.status == 200
expect resp.body ~ "(?m)^URI: /tea/baz/quux$"
expect resp.body ~ "(?m)^Server name: tea-[a-z0-9]+-[a-z0-9]+$"
txreq -url /milk
rxresp
expect resp.status == 404
} -run
apps:
coffee:
image: uplex/http-echo
replicas: 2
targetPort: 7357
tea:
image: uplex/http-echo
replicas: 3
targetPort: 7357
ingress:
name: fanout-nohost-ingress
rules:
- paths:
- path: /tea
app: tea
- path: /coffee
app: coffee
apps:
coffee:
image: uplex/http-echo
replicas: 2
targetPort: 7357
tea:
image: uplex/http-echo
replicas: 3
targetPort: 7357
milk:
image: uplex/http-echo
replicas: 2
targetPort: 7357
# Routing by host, where one rule specifies no host.
ingress:
name: vhost-nohost-ingress
rules:
- host: coffee.example.com
paths:
- path: /
app: coffee
- host: tea.example.com
paths:
- path: /
app: tea
- paths:
- path: /
app: milk
#! /bin/bash -ex
if [ $# -ne 1 ]; then
echo "Usage: $0 file.vtc"
exit 1
fi
MYDIR=$(dirname ${BASH_SOURCE[0]})
source ${MYDIR}/../../utils.sh
LOCALPORT=${LOCALPORT:-8888}
wait_until_ready app=varnish-ingress
wait_until_configured app=varnish-ingress
kubectl port-forward svc/varnish-ingress ${LOCALPORT}:80 >/dev/null &
trap 'kill $(jobs -p)' EXIT
wait_for_port ${LOCALPORT}
varnishtest ${TESTOPTS} -Dlocalport=${LOCALPORT} $1
# looks like -*- vcl -*-
varnishtest "simple fanout by path with no host specified in Ingress"
client c1 -connect "${localhost} ${localport}" {
txreq -url /foo/bar -hdr "Host: coffee.example.com"
rxresp
expect resp.status == 200
expect resp.body ~ "(?m)^URI: /foo/bar$"
expect resp.body ~ "(?m)^Server name: coffee-[a-z0-9]+-[a-z0-9]+$"
txreq -url /baz/quux -hdr "Host: tea.example.com"
rxresp
expect resp.status == 200
expect resp.body ~ "(?m)^URI: /baz/quux$"
expect resp.body ~ "(?m)^Server name: tea-[a-z0-9]+-[a-z0-9]+$"
txreq -url / -hdr "Host: other.example.com"
rxresp
expect resp.status == 200
expect resp.body ~ "(?m)^URI: /"
expect resp.body ~ "(?m)^Server name: milk-[a-z0-9]+-[a-z0-9]+$"
txreq -url /foo/bar/baz/quux
rxresp
expect resp.status == 200
expect resp.body ~ "(?m)^URI: /foo/bar/baz/quux$"
expect resp.body ~ "(?m)^Server name: milk-[a-z0-9]+-[a-z0-9]+$"
} -run
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