2022-03-24 14:43:41 +00:00
|
|
|
package split
|
2022-03-24 14:26:15 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
golog "log"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/coredns/coredns/plugin/pkg/dnstest"
|
|
|
|
"github.com/coredns/coredns/plugin/test"
|
|
|
|
|
|
|
|
"github.com/miekg/dns"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestExample(t *testing.T) {
|
2022-03-24 14:43:41 +00:00
|
|
|
// Create a new Split Plugin. Use the test.ErrorHandler as the next plugin.
|
|
|
|
x := Split{Next: test.ErrorHandler()}
|
2022-03-24 14:26:15 +00:00
|
|
|
|
|
|
|
// Setup a new output buffer that is *not* standard output, so we can check if
|
|
|
|
// example is really being printed.
|
|
|
|
b := &bytes.Buffer{}
|
|
|
|
golog.SetOutput(b)
|
|
|
|
|
|
|
|
ctx := context.TODO()
|
|
|
|
r := new(dns.Msg)
|
|
|
|
r.SetQuestion("example.org.", dns.TypeA)
|
|
|
|
// 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{})
|
|
|
|
|
|
|
|
// Call our plugin directly, and check the result.
|
|
|
|
x.ServeDNS(ctx, rec, r)
|
2022-03-24 14:43:41 +00:00
|
|
|
if a := b.String(); !strings.Contains(a, "[INFO] plugin/split: example") {
|
|
|
|
t.Errorf("Failed to print '%s', got %s", "[INFO] plugin/split: example", a)
|
2022-03-24 14:26:15 +00:00
|
|
|
}
|
|
|
|
}
|