Commit 56fe060c authored by Nils Goroll's avatar Nils Goroll

extend test coverage for vmod named arguments and defaults

parent 44fed1db
varnishtest "Test var args"
varnishtest "Test vmod functions/contructor named arguments and defaults"
server s1 {
rxreq
......@@ -8,6 +8,15 @@ server s1 {
varnish v1 -vcl+backend {
import debug;
sub vcl_init {
new obj0 = debug.obj();
new obj1 = debug.obj("only_argument");
new obj2 = debug.obj("string", one);
new obj3 = debug.obj(string="s_two", number=two);
new obj4 = debug.obj(number=three, string="s_three");
new obj5 = debug.obj(number=three);
}
sub vcl_deliver {
set resp.http.foo1 = debug.argtest("1", 2.1, "3a");
set resp.http.foo2 = debug.argtest("1", two=2.2, three="3b");
......@@ -15,6 +24,13 @@ varnish v1 -vcl+backend {
set resp.http.foo4 = debug.argtest("1", 2.4, three="3d");
set resp.http.foo5 = debug.argtest("1", 2.5);
set resp.http.foo6 = debug.argtest("1", four=6);
set resp.http.obj0 = obj0.string() + ", " + obj0.number();
set resp.http.obj1 = obj1.string() + ", " + obj1.number();
set resp.http.obj2 = obj2.string() + ", " + obj2.number();
set resp.http.obj3 = obj3.string() + ", " + obj3.number();
set resp.http.obj4 = obj4.string() + ", " + obj4.number();
set resp.http.obj5 = obj5.string() + ", " + obj5.number();
}
} -start
......@@ -28,6 +44,13 @@ client c1 {
expect resp.http.foo4 == "1 2.4 3d , 4"
expect resp.http.foo5 == "1 2.5 3 , 4"
expect resp.http.foo6 == "1 2 3 , 6"
expect resp.http.obj0 == "default, one"
expect resp.http.obj1 == "only_argument, one"
expect resp.http.obj2 == "string, one"
expect resp.http.obj3 == "s_two, two"
expect resp.http.obj4 == "s_three, three"
expect resp.http.obj5 == "default, three"
} -run
delay .1
......
......@@ -71,7 +71,7 @@ $Function BACKEND no_backend()
Fails at backend selection
$Object obj(STRING, ENUM { one, two, three } number="one")
$Object obj(STRING string="default", ENUM { one, two, three } number="one")
Test object
......@@ -81,6 +81,14 @@ $Method VOID .enum(ENUM { phk, des, kristian, mithrandir, martin })
Testing that enums work as part of object and that the parser isn't
(too) buggy.
$Method STRING .string()
getter for string
$Method STRING .number()
getter for number
$Method STRING .foo(STRING why)
Foo indeed.
......
......@@ -39,6 +39,7 @@ struct vmod_debug_obj {
unsigned magic;
#define VMOD_DEBUG_OBJ_MAGIC 0xccbd9b77
int foobar;
const char *string, *number;
};
VCL_VOID
......@@ -49,14 +50,14 @@ vmod_obj__init(VRT_CTX, struct vmod_debug_obj **op,
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
(void)vcl_name;
(void)s;
(void)e;
AN(op);
AZ(*op);
ALLOC_OBJ(o, VMOD_DEBUG_OBJ_MAGIC);
AN(o);
*op = o;
o->foobar = 42;
o->string = s;
o->number = e;
AN(*op);
}
......@@ -99,3 +100,23 @@ vmod_obj_date(VRT_CTX, struct vmod_debug_obj *o)
assert(o->foobar == 42);
return (21.4);
}
VCL_STRING __match_proto__()
vmod_obj_string(VRT_CTX, struct vmod_debug_obj *o)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(o, VMOD_DEBUG_OBJ_MAGIC);
assert(o->foobar == 42);
return (o->string);
}
VCL_STRING __match_proto__()
vmod_obj_number(VRT_CTX, struct vmod_debug_obj *o)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(o, VMOD_DEBUG_OBJ_MAGIC);
assert(o->foobar == 42);
return (o->number);
}
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