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
55a33aa9
Commit
55a33aa9
authored
Jun 24, 2020
by
Zou Nengren
Committed by
GitHub
Jun 23, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add test case of remote ip (#3964)
Signed-off-by:
zounengren
<
zounengren@cmss.chinamobile.com
>
parent
ba8a567e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
5 deletions
+23
-5
plugin/whoami/whoami.go
plugin/whoami/whoami.go
+2
-1
plugin/whoami/whoami_test.go
plugin/whoami/whoami_test.go
+21
-4
No files found.
plugin/whoami/whoami.go
View file @
55a33aa9
...
@@ -12,6 +12,7 @@ import (
...
@@ -12,6 +12,7 @@ import (
"github.com/miekg/dns"
"github.com/miekg/dns"
)
)
const
name
=
"whoami"
// Whoami is a plugin that returns your IP address, port and the protocol used for connecting
// Whoami is a plugin that returns your IP address, port and the protocol used for connecting
// to CoreDNS.
// to CoreDNS.
type
Whoami
struct
{}
type
Whoami
struct
{}
...
@@ -55,4 +56,4 @@ func (wh Whoami) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
...
@@ -55,4 +56,4 @@ func (wh Whoami) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
}
}
// Name implements the Handler interface.
// Name implements the Handler interface.
func
(
wh
Whoami
)
Name
()
string
{
return
"whoami"
}
func
(
wh
Whoami
)
Name
()
string
{
return
name
}
plugin/whoami/whoami_test.go
View file @
55a33aa9
...
@@ -12,10 +12,13 @@ import (
...
@@ -12,10 +12,13 @@ import (
func
TestWhoami
(
t
*
testing
.
T
)
{
func
TestWhoami
(
t
*
testing
.
T
)
{
wh
:=
Whoami
{}
wh
:=
Whoami
{}
if
wh
.
Name
()
!=
name
{
t
.
Errorf
(
"expected plugin name: %s, got %s"
,
wh
.
Name
(),
name
)
}
tests
:=
[]
struct
{
tests
:=
[]
struct
{
qname
string
qname
string
qtype
uint16
qtype
uint16
remote
string
expectedCode
int
expectedCode
int
expectedReply
[]
string
// ownernames for the records in the additional section.
expectedReply
[]
string
// ownernames for the records in the additional section.
expectedErr
error
expectedErr
error
...
@@ -35,6 +38,22 @@ func TestWhoami(t *testing.T) {
...
@@ -35,6 +38,22 @@ func TestWhoami(t *testing.T) {
expectedReply
:
[]
string
{
"Example.ORG."
,
"_udp.Example.ORG."
},
expectedReply
:
[]
string
{
"Example.ORG."
,
"_udp.Example.ORG."
},
expectedErr
:
nil
,
expectedErr
:
nil
,
},
},
{
qname
:
"example.org"
,
qtype
:
dns
.
TypeA
,
remote
:
"2003::1/64"
,
expectedCode
:
dns
.
RcodeSuccess
,
expectedReply
:
[]
string
{
"example.org."
,
"_udp.example.org."
},
expectedErr
:
nil
,
},
{
qname
:
"Example.ORG"
,
qtype
:
dns
.
TypeA
,
remote
:
"2003::1/64"
,
expectedCode
:
dns
.
RcodeSuccess
,
expectedReply
:
[]
string
{
"Example.ORG."
,
"_udp.Example.ORG."
},
expectedErr
:
nil
,
},
}
}
ctx
:=
context
.
TODO
()
ctx
:=
context
.
TODO
()
...
@@ -42,10 +61,8 @@ func TestWhoami(t *testing.T) {
...
@@ -42,10 +61,8 @@ func TestWhoami(t *testing.T) {
for
i
,
tc
:=
range
tests
{
for
i
,
tc
:=
range
tests
{
req
:=
new
(
dns
.
Msg
)
req
:=
new
(
dns
.
Msg
)
req
.
SetQuestion
(
dns
.
Fqdn
(
tc
.
qname
),
tc
.
qtype
)
req
.
SetQuestion
(
dns
.
Fqdn
(
tc
.
qname
),
tc
.
qtype
)
rec
:=
dnstest
.
NewRecorder
(
&
test
.
ResponseWriter
{
RemoteIP
:
tc
.
remote
})
rec
:=
dnstest
.
NewRecorder
(
&
test
.
ResponseWriter
{})
code
,
err
:=
wh
.
ServeDNS
(
ctx
,
rec
,
req
)
code
,
err
:=
wh
.
ServeDNS
(
ctx
,
rec
,
req
)
if
err
!=
tc
.
expectedErr
{
if
err
!=
tc
.
expectedErr
{
t
.
Errorf
(
"Test %d: Expected error %v, but got %v"
,
i
,
tc
.
expectedErr
,
err
)
t
.
Errorf
(
"Test %d: Expected error %v, but got %v"
,
i
,
tc
.
expectedErr
,
err
)
}
}
...
...
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