Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnishevent
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
varnishevent
Commits
836e8247
Commit
836e8247
authored
Mar 30, 2015
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add a test for format.c/get_hdr()
parent
df791ef3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
3 deletions
+48
-3
format.c
src/format.c
+2
-2
test_format.c
src/test/test_format.c
+46
-1
No files found.
src/format.c
View file @
836e8247
...
@@ -136,8 +136,8 @@ get_hdr(tx_t *tx, enum VSL_tag_e tag, vre_t *hdr_re)
...
@@ -136,8 +136,8 @@ get_hdr(tx_t *tx, enum VSL_tag_e tag, vre_t *hdr_re)
if
(
rec
->
tag
!=
tag
)
if
(
rec
->
tag
!=
tag
)
continue
;
continue
;
get_payload
(
rec
);
get_payload
(
rec
);
s
=
VRE_exec
(
hdr_re
,
VSB_data
(
payload
),
rec
->
len
,
0
,
VRE_CASELESS
,
s
=
VRE_exec
(
hdr_re
,
VSB_data
(
payload
),
rec
->
len
,
0
,
0
,
ov
,
OV_SIZE
,
ov
,
OV_SIZE
,
NULL
);
NULL
);
assert
(
s
>=
VRE_ERROR_NOMATCH
&&
s
!=
0
);
assert
(
s
>=
VRE_ERROR_NOMATCH
&&
s
!=
0
);
if
(
s
==
VRE_ERROR_NOMATCH
)
if
(
s
==
VRE_ERROR_NOMATCH
)
continue
;
continue
;
...
...
src/test/test_format.c
View file @
836e8247
...
@@ -37,6 +37,8 @@
...
@@ -37,6 +37,8 @@
#include "../varnishevent.h"
#include "../varnishevent.h"
#include "../format.h"
#include "../format.h"
#define NRECORDS 10
int
tests_run
=
0
;
int
tests_run
=
0
;
/* N.B.: Always run the tests in this order */
/* N.B.: Always run the tests in this order */
...
@@ -120,7 +122,6 @@ static const char
...
@@ -120,7 +122,6 @@ static const char
*
test_format_get_tag
(
void
)
*
test_format_get_tag
(
void
)
{
{
tx_t
tx
;
tx_t
tx
;
#define NRECORDS 10
logline_t
recs
[
NRECORDS
],
*
rec
;
logline_t
recs
[
NRECORDS
],
*
rec
;
printf
(
"... testing get_tag()
\n
"
);
printf
(
"... testing get_tag()
\n
"
);
...
@@ -151,12 +152,56 @@ static const char
...
@@ -151,12 +152,56 @@ static const char
return
NULL
;
return
NULL
;
}
}
static
const
char
*
test_format_get_hdr
(
void
)
{
tx_t
tx
;
#define HDR_REGEX "^\\s*Foo\\s*:\\s*(.+)$"
logline_t
recs
[
NRECORDS
];
chunk_t
c
[
NRECORDS
];
vre_t
*
hdr_re
;
const
char
*
error
;
char
*
hdr
;
int
erroroffset
;
printf
(
"... testing get_hdr()
\n
"
);
hdr_re
=
VRE_compile
(
HDR_REGEX
,
VRE_CASELESS
,
&
error
,
&
erroroffset
);
VMASSERT
(
hdr_re
!=
NULL
,
"Error compiling
\"
"
HDR_REGEX
"
\"
: %s (offset %d)"
,
error
,
erroroffset
);
tx
.
magic
=
TX_MAGIC
;
VSTAILQ_INIT
(
&
tx
.
lines
);
for
(
int
i
=
0
;
i
<
NRECORDS
;
i
++
)
{
recs
[
i
].
magic
=
LOGLINE_MAGIC
;
recs
[
i
].
tag
=
SLT_ReqHeader
;
recs
[
i
].
len
=
strlen
(
"Bar: baz"
);
VSTAILQ_INSERT_TAIL
(
&
tx
.
lines
,
&
recs
[
i
],
linelist
);
VSTAILQ_INIT
(
&
recs
[
i
].
chunks
);
c
[
i
].
magic
=
CHUNK_MAGIC
;
c
[
i
].
data
=
(
char
*
)
calloc
(
1
,
config
.
chunk_size
);
strcpy
(
c
[
i
].
data
,
"Bar: baz"
);
VSTAILQ_INSERT_TAIL
(
&
recs
[
i
].
chunks
,
&
c
[
i
],
chunklist
);
}
recs
[
NRECORDS
/
2
].
len
=
strlen
(
"Foo: quux"
);
strcpy
(
c
[
NRECORDS
/
2
].
data
,
"Foo: quux"
);
recs
[
NRECORDS
-
1
].
len
=
strlen
(
"Foo: wilco"
);
strcpy
(
c
[
NRECORDS
-
1
].
data
,
"Foo: wilco"
);
hdr
=
get_hdr
(
&
tx
,
SLT_ReqHeader
,
hdr_re
);
MAN
(
hdr
);
MASSERT
(
strcmp
(
hdr
,
"wilco"
)
==
0
);
return
NULL
;
}
static
const
char
static
const
char
*
all_tests
(
void
)
*
all_tests
(
void
)
{
{
mu_run_test
(
test_format_init
);
mu_run_test
(
test_format_init
);
mu_run_test
(
test_format_get_payload
);
mu_run_test
(
test_format_get_payload
);
mu_run_test
(
test_format_get_tag
);
mu_run_test
(
test_format_get_tag
);
mu_run_test
(
test_format_get_hdr
);
return
NULL
;
return
NULL
;
}
}
...
...
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