coredns-ldap/ldap_test.go

36 lines
945 B
Go
Raw Normal View History

2020-06-01 07:48:07 +00:00
package ldap
import (
"bytes"
"context"
"testing"
"github.com/coredns/coredns/plugin/pkg/dnstest"
"github.com/coredns/coredns/plugin/test"
"github.com/miekg/dns"
)
2020-06-01 07:48:07 +00:00
func TestLdap(t *testing.T) {
// Create a new Ldap Plugin. Use the test.ErrorHandler as the next plugin.
x := Ldap{Next: test.ErrorHandler()}
2018-02-25 08:52:52 +00:00
// Setup a new output buffer that is *not* standard output, so we can check if
2020-06-01 07:48:07 +00:00
// ldap is really being printed.
b := &bytes.Buffer{}
out = b
ctx := context.TODO()
r := new(dns.Msg)
2020-06-01 07:48:07 +00:00
r.SetQuestion("ldap.org.", dns.TypeA)
2018-02-25 08:52:52 +00:00
// Create a new Recorder that captures the result, this isn't actually used in this test
// as it just serves as something that implements the dns.ResponseWriter interface.
rec := dnstest.NewRecorder(&test.ResponseWriter{})
2018-02-25 08:52:52 +00:00
// Call our plugin directly, and check the result.
x.ServeDNS(ctx, rec, r)
2020-06-01 07:48:07 +00:00
if a := b.String(); a != "ldap\n" {
t.Errorf("Failed to print '%s', got %s", ldap, a)
}
}