mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 16:24:19 -04:00
Add new plugin: traffic
Traffic is a plugin that communicates via the xDS protocol to an Envoy control plane. Using the data from this control plane it hands out IP addresses. This allows you (via controlling the data in the control plane) to drain or send more traffic to specific endpoints. The plugin itself only acts upon this data; it doesn't do anything fancy by itself. Code used here is copied from grpc-go and other places, this is clearly marked in the source files. Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
53
plugin/traffic/setup_test.go
Normal file
53
plugin/traffic/setup_test.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package traffic
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/caddyserver/caddy"
|
||||
)
|
||||
|
||||
func TestSetup(t *testing.T) {
|
||||
/*
|
||||
c := caddy.NewTestController("dns", `traffic grpc://bla`)
|
||||
if err := setup(c); err != nil {
|
||||
t.Fatalf("Test 1, expected no errors, but got: %q", err)
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
func TestParseTraffic(t *testing.T) {
|
||||
tests := []struct {
|
||||
input string
|
||||
shouldErr bool
|
||||
}{
|
||||
// ok
|
||||
{`traffic grpc://127.0.0.1:18000 {
|
||||
id test-id
|
||||
}`, false},
|
||||
|
||||
// fail
|
||||
{`traffic`, true},
|
||||
{`traffic tls://1.1.1.1`, true},
|
||||
{`traffic {
|
||||
id bla bla
|
||||
}`, true},
|
||||
{`traffic {
|
||||
node
|
||||
}`, true},
|
||||
}
|
||||
for i, test := range tests {
|
||||
c := caddy.NewTestController("dns", test.input)
|
||||
_, err := parseTraffic(c)
|
||||
if test.shouldErr && err == nil {
|
||||
t.Errorf("Test %v: Expected error but found nil", i)
|
||||
continue
|
||||
} else if !test.shouldErr && err != nil {
|
||||
t.Errorf("Test %v: Expected no error but found error: %v", i, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if test.shouldErr {
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user