diff options
author | 2020-06-24 05:37:00 +0800 | |
---|---|---|
committer | 2020-06-23 14:37:00 -0700 | |
commit | 55a33aa9d2c90fb2e7ddbe8d091a7dbc03af78d9 (patch) | |
tree | 6d6f5f2b91b6eed197ff92a8c3c8213649d11e8d /plugin | |
parent | ba8a567e389c9c7274376bf5c7f2a9ce65fb44d4 (diff) | |
download | coredns-55a33aa9d2c90fb2e7ddbe8d091a7dbc03af78d9.tar.gz coredns-55a33aa9d2c90fb2e7ddbe8d091a7dbc03af78d9.tar.zst coredns-55a33aa9d2c90fb2e7ddbe8d091a7dbc03af78d9.zip |
add test case of remote ip (#3964)
Signed-off-by: zounengren <zounengren@cmss.chinamobile.com>
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/whoami/whoami.go | 3 | ||||
-rw-r--r-- | plugin/whoami/whoami_test.go | 25 |
2 files changed, 23 insertions, 5 deletions
diff --git a/plugin/whoami/whoami.go b/plugin/whoami/whoami.go index 155880eae..34f24272a 100644 --- a/plugin/whoami/whoami.go +++ b/plugin/whoami/whoami.go @@ -12,6 +12,7 @@ import ( "github.com/miekg/dns" ) +const name = "whoami" // Whoami is a plugin that returns your IP address, port and the protocol used for connecting // to CoreDNS. type Whoami struct{} @@ -55,4 +56,4 @@ func (wh Whoami) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) } // Name implements the Handler interface. -func (wh Whoami) Name() string { return "whoami" } +func (wh Whoami) Name() string { return name } diff --git a/plugin/whoami/whoami_test.go b/plugin/whoami/whoami_test.go index 0db207586..055f267a4 100644 --- a/plugin/whoami/whoami_test.go +++ b/plugin/whoami/whoami_test.go @@ -12,10 +12,13 @@ import ( func TestWhoami(t *testing.T) { wh := Whoami{} - + if wh.Name() != name { + t.Errorf("expected plugin name: %s, got %s", wh.Name(), name) + } tests := []struct { qname string qtype uint16 + remote string expectedCode int expectedReply []string // ownernames for the records in the additional section. expectedErr error @@ -35,6 +38,22 @@ func TestWhoami(t *testing.T) { 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, + }, + { + 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() @@ -42,10 +61,8 @@ func TestWhoami(t *testing.T) { for i, tc := range tests { req := new(dns.Msg) req.SetQuestion(dns.Fqdn(tc.qname), tc.qtype) - - rec := dnstest.NewRecorder(&test.ResponseWriter{}) + rec := dnstest.NewRecorder(&test.ResponseWriter{RemoteIP: tc.remote}) code, err := wh.ServeDNS(ctx, rec, req) - if err != tc.expectedErr { t.Errorf("Test %d: Expected error %v, but got %v", i, tc.expectedErr, err) } |