Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Coredns
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
Coredns
Commits
2b651129
Commit
2b651129
authored
Jan 30, 2019
by
ckcd
Committed by
Miek Gieben
Jan 30, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
plugin/log: add test and benchmark (#2515)
parent
68e09f00
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
156 additions
and
3 deletions
+156
-3
plugin/log/log_test.go
plugin/log/log_test.go
+156
-3
No files found.
plugin/log/log_test.go
View file @
2b651129
...
@@ -21,7 +21,7 @@ func TestLoggedStatus(t *testing.T) {
...
@@ -21,7 +21,7 @@ func TestLoggedStatus(t *testing.T) {
rule
:=
Rule
{
rule
:=
Rule
{
NameScope
:
"."
,
NameScope
:
"."
,
Format
:
DefaultLogFormat
,
Format
:
DefaultLogFormat
,
Class
:
map
[
response
.
Class
]
struct
{}{
response
.
All
:
struct
{}
{}},
Class
:
map
[
response
.
Class
]
struct
{}{
response
.
All
:
{}},
}
}
var
f
bytes
.
Buffer
var
f
bytes
.
Buffer
...
@@ -53,7 +53,7 @@ func TestLoggedClassDenial(t *testing.T) {
...
@@ -53,7 +53,7 @@ func TestLoggedClassDenial(t *testing.T) {
rule
:=
Rule
{
rule
:=
Rule
{
NameScope
:
"."
,
NameScope
:
"."
,
Format
:
DefaultLogFormat
,
Format
:
DefaultLogFormat
,
Class
:
map
[
response
.
Class
]
struct
{}{
response
.
Denial
:
struct
{}
{}},
Class
:
map
[
response
.
Class
]
struct
{}{
response
.
Denial
:
{}},
}
}
var
f
bytes
.
Buffer
var
f
bytes
.
Buffer
...
@@ -82,7 +82,7 @@ func TestLoggedClassError(t *testing.T) {
...
@@ -82,7 +82,7 @@ func TestLoggedClassError(t *testing.T) {
rule
:=
Rule
{
rule
:=
Rule
{
NameScope
:
"."
,
NameScope
:
"."
,
Format
:
DefaultLogFormat
,
Format
:
DefaultLogFormat
,
Class
:
map
[
response
.
Class
]
struct
{}{
response
.
Error
:
struct
{}
{}},
Class
:
map
[
response
.
Class
]
struct
{}{
response
.
Error
:
{}},
}
}
var
f
bytes
.
Buffer
var
f
bytes
.
Buffer
...
@@ -106,3 +106,156 @@ func TestLoggedClassError(t *testing.T) {
...
@@ -106,3 +106,156 @@ func TestLoggedClassError(t *testing.T) {
t
.
Errorf
(
"Expected it to be logged. Logged string: %s"
,
logged
)
t
.
Errorf
(
"Expected it to be logged. Logged string: %s"
,
logged
)
}
}
}
}
func
TestLogged
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
Rules
[]
Rule
Domain
string
ShouldLog
bool
ShouldString
string
ShouldNOTString
string
// for test format
}{
// case for NameScope
{
Rules
:
[]
Rule
{
{
NameScope
:
"example.org."
,
Format
:
DefaultLogFormat
,
Class
:
map
[
response
.
Class
]
struct
{}{
response
.
All
:
{}},
},
},
Domain
:
"example.org."
,
ShouldLog
:
true
,
ShouldString
:
"A IN example.org."
,
},
{
Rules
:
[]
Rule
{
{
NameScope
:
"example.org."
,
Format
:
DefaultLogFormat
,
Class
:
map
[
response
.
Class
]
struct
{}{
response
.
All
:
{}},
},
},
Domain
:
"example.net."
,
ShouldLog
:
false
,
ShouldString
:
""
,
},
{
Rules
:
[]
Rule
{
{
NameScope
:
"example.org."
,
Format
:
DefaultLogFormat
,
Class
:
map
[
response
.
Class
]
struct
{}{
response
.
All
:
{}},
},
{
NameScope
:
"example.net."
,
Format
:
DefaultLogFormat
,
Class
:
map
[
response
.
Class
]
struct
{}{
response
.
All
:
{}},
},
},
Domain
:
"example.net."
,
ShouldLog
:
true
,
ShouldString
:
"A IN example.net."
,
},
// case for format
{
Rules
:
[]
Rule
{
{
NameScope
:
"."
,
Format
:
"{type} {class}"
,
Class
:
map
[
response
.
Class
]
struct
{}{
response
.
All
:
{}},
},
},
Domain
:
"example.org."
,
ShouldLog
:
true
,
ShouldString
:
"A IN"
,
ShouldNOTString
:
"example.org"
,
},
{
Rules
:
[]
Rule
{
{
NameScope
:
"."
,
Format
:
"{remote}:{port}"
,
Class
:
map
[
response
.
Class
]
struct
{}{
response
.
All
:
{}},
},
},
Domain
:
"example.org."
,
ShouldLog
:
true
,
ShouldString
:
"10.240.0.1:40212"
,
ShouldNOTString
:
"A IN example.org"
,
},
{
Rules
:
[]
Rule
{
{
NameScope
:
"."
,
Format
:
CombinedLogFormat
,
Class
:
map
[
response
.
Class
]
struct
{}{
response
.
All
:
{}},
},
},
Domain
:
"example.org."
,
ShouldLog
:
true
,
ShouldString
:
"
\"
0
\"
"
,
},
}
for
_
,
tc
:=
range
tests
{
var
f
bytes
.
Buffer
log
.
SetOutput
(
&
f
)
logger
:=
Logger
{
Rules
:
tc
.
Rules
,
Next
:
test
.
ErrorHandler
(),
}
ctx
:=
context
.
TODO
()
r
:=
new
(
dns
.
Msg
)
r
.
SetQuestion
(
tc
.
Domain
,
dns
.
TypeA
)
rec
:=
dnstest
.
NewRecorder
(
&
test
.
ResponseWriter
{})
_
,
err
:=
logger
.
ServeDNS
(
ctx
,
rec
,
r
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
logged
:=
f
.
String
()
if
!
tc
.
ShouldLog
&&
len
(
logged
)
!=
0
{
t
.
Errorf
(
"Expected it not to be logged, but got string: %s"
,
logged
)
}
if
tc
.
ShouldLog
&&
!
strings
.
Contains
(
logged
,
tc
.
ShouldString
)
{
t
.
Errorf
(
"Expected it to contains: %s. Logged string: %s"
,
tc
.
ShouldString
,
logged
)
}
if
tc
.
ShouldLog
&&
tc
.
ShouldNOTString
!=
""
&&
strings
.
Contains
(
logged
,
tc
.
ShouldNOTString
)
{
t
.
Errorf
(
"Expected it to NOT contains: %s. Logged string: %s"
,
tc
.
ShouldNOTString
,
logged
)
}
}
}
func
BenchmarkLogged
(
b
*
testing
.
B
)
{
var
f
bytes
.
Buffer
log
.
SetOutput
(
&
f
)
rule
:=
Rule
{
NameScope
:
"."
,
Format
:
DefaultLogFormat
,
Class
:
map
[
response
.
Class
]
struct
{}{
response
.
All
:
{}},
}
logger
:=
Logger
{
Rules
:
[]
Rule
{
rule
},
Next
:
test
.
ErrorHandler
(),
}
ctx
:=
context
.
TODO
()
r
:=
new
(
dns
.
Msg
)
r
.
SetQuestion
(
"example.org."
,
dns
.
TypeA
)
rec
:=
dnstest
.
NewRecorder
(
&
test
.
ResponseWriter
{})
b
.
StartTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
logger
.
ServeDNS
(
ctx
,
rec
,
r
)
}
}
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