mirror of
https://github.com/coredns/coredns.git
synced 2025-12-07 02:45:11 -05:00
Identity and version support for the dnstap plugin (#5555)
* Added identity and version support to dnstap plugin Signed-off-by: Daniel Jolly <code@danieljolly.com> * Added missing commas Signed-off-by: Daniel Jolly <code@danieljolly.com> * Moved byte slice conversions to setup rather than handler. Fixed indentation issue. Signed-off-by: Daniel Jolly <code@danieljolly.com> * Improved setup config parsing and added tests to detect various configurations Signed-off-by: Daniel Jolly <code@danieljolly.com> Signed-off-by: Daniel Jolly <code@danieljolly.com> Co-authored-by: Daniel Jolly <code@danieljolly.com>
This commit is contained in:
@@ -1,25 +1,32 @@
|
||||
package dnstap
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/coredns/caddy"
|
||||
)
|
||||
|
||||
func TestConfig(t *testing.T) {
|
||||
hostname, _ := os.Hostname()
|
||||
tests := []struct {
|
||||
in string
|
||||
endpoint string
|
||||
full bool
|
||||
proto string
|
||||
fail bool
|
||||
identity []byte
|
||||
version []byte
|
||||
}{
|
||||
{"dnstap dnstap.sock full", "dnstap.sock", true, "unix", false},
|
||||
{"dnstap unix://dnstap.sock", "dnstap.sock", false, "unix", false},
|
||||
{"dnstap tcp://127.0.0.1:6000", "127.0.0.1:6000", false, "tcp", false},
|
||||
{"dnstap tcp://[::1]:6000", "[::1]:6000", false, "tcp", false},
|
||||
{"dnstap tcp://example.com:6000", "example.com:6000", false, "tcp", false},
|
||||
{"dnstap", "fail", false, "tcp", true},
|
||||
{"dnstap dnstap.sock full", "dnstap.sock", true, "unix", false, []byte(hostname), []byte("-")},
|
||||
{"dnstap unix://dnstap.sock", "dnstap.sock", false, "unix", false, []byte(hostname), []byte("-")},
|
||||
{"dnstap tcp://127.0.0.1:6000", "127.0.0.1:6000", false, "tcp", false, []byte(hostname), []byte("-")},
|
||||
{"dnstap tcp://[::1]:6000", "[::1]:6000", false, "tcp", false, []byte(hostname), []byte("-")},
|
||||
{"dnstap tcp://example.com:6000", "example.com:6000", false, "tcp", false, []byte(hostname), []byte("-")},
|
||||
{"dnstap", "fail", false, "tcp", true, []byte(hostname), []byte("-")},
|
||||
{"dnstap dnstap.sock full {\nidentity NAME\nversion VER\n}\n", "dnstap.sock", true, "unix", false, []byte("NAME"), []byte("VER")},
|
||||
{"dnstap dnstap.sock {\nidentity NAME\nversion VER\n}\n", "dnstap.sock", false, "unix", false, []byte("NAME"), []byte("VER")},
|
||||
{"dnstap {\nidentity NAME\nversion VER\n}\n", "fail", false, "tcp", true, []byte("NAME"), []byte("VER")},
|
||||
}
|
||||
for i, tc := range tests {
|
||||
c := caddy.NewTestController("dns", tc.in)
|
||||
@@ -43,5 +50,11 @@ func TestConfig(t *testing.T) {
|
||||
if x := tap.IncludeRawMessage; x != tc.full {
|
||||
t.Errorf("Test %d: expected IncludeRawMessage %t, got %t", i, tc.full, x)
|
||||
}
|
||||
if x := string(tap.Identity); x != string(tc.identity) {
|
||||
t.Errorf("Test %d: expected identity %s, got %s", i, tc.identity, x)
|
||||
}
|
||||
if x := string(tap.Version); x != string(tc.version) {
|
||||
t.Errorf("Test %d: expected version %s, got %s", i, tc.version, x)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user