Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 3a0b160

Browse files
committed
Allow testing of vmods
1 parent 6951f18 commit 3a0b160

3 files changed

Lines changed: 41 additions & 3 deletions

File tree

configure.ac

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
AC_PREREQ(2.59)
22
AC_COPYRIGHT([Copyright (c) 2011 Varnish Software AS])
3-
AC_INIT([libvmod-example], [0.1])
3+
AC_INIT([libvmod-example], [trunk])
44
AC_CONFIG_MACRO_DIR([m4])
55
AC_CONFIG_SRCDIR(src/vmod_example.vcc)
66
AM_CONFIG_HEADER(config.h)
@@ -43,6 +43,12 @@ AC_CHECK_FILE([$VARNISHSRC/include/varnishapi.h],
4343
[AC_MSG_FAILURE(["$VARNISHSRC" is not a Varnish source directory])]
4444
)
4545

46+
# Check that varnishtest is built in the varnish source directory
47+
AC_CHECK_FILE([$VARNISHSRC/bin/varnishtest/varnishtest],
48+
[],
49+
[AC_MSG_FAILURE([Can't find "$VARNISHSRC/bin/varnishtest/varnishtest". Please build your varnish source directory])]
50+
)
51+
4652
# vmod installation dir
4753
AC_ARG_VAR([VMODDIR], [vmod installation directory @<:@LIBDIR/varnish/vmods@:>@])
4854
if test "x$VMODDIR" = x; then

src/Makefile.am

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ INCLUDES = -I$(VARNISHSRC)/include -I$(VARNISHSRC)
33
vmoddir = $(VMODDIR)
44
vmod_LTLIBRARIES = libvmod_example.la
55

6-
libvmod_example_la_LDFLAGS = -version-info 1:0:0
6+
libvmod_example_la_LDFLAGS = -avoid-version
77

88
libvmod_example_la_SOURCES = \
99
vcc_if.c \
@@ -13,6 +13,16 @@ libvmod_example_la_SOURCES = \
1313
vcc_if.c vcc_if.h: $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod_example.vcc
1414
@PYTHON@ $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod_example.vcc
1515

16-
EXTRA_DIST = vmod_example.vcc
16+
MYTESTS = tests/*.vtc
17+
.PHONY: $(MYTESTS)
18+
19+
tests/*.vtc:
20+
cd $(VARNISHSRC)/bin/varnishtest && ./varnishtest -D vmod_topbuild=$(abs_top_builddir) $(abs_srcdir)/$@
21+
22+
check: $(MYTESTS)
23+
24+
EXTRA_DIST = \
25+
$(MYTESTS) \
26+
vmod_example.vcc
1727

1828
CLEANFILES = $(builddir)/vcc_if.c $(builddir)/vcc_if.h

src/tests/test01.vtc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
varnishtest "Test example vmod"
2+
3+
server s1 {
4+
rxreq
5+
txresp
6+
} -start
7+
8+
varnish v1 -vcl+backend {
9+
import example from "${vmod_topbuild}/src/.libs/libvmod_example.so";
10+
11+
sub vcl_deliver {
12+
set resp.http.val = example.abs(2-3);
13+
}
14+
} -start
15+
16+
client c1 {
17+
txreq -url "/"
18+
rxresp
19+
expect resp.http.val == "1"
20+
}
21+
22+
client c1 -run

0 commit comments

Comments
 (0)