mirror of
https://github.com/notherealmarco/coredns-deployment.git
synced 2025-05-05 20:42:33 +02:00
groundwork (#140)
This commit is contained in:
parent
e6c1d12235
commit
ac020ac1bc
6 changed files with 1082 additions and 0 deletions
254
kubernetes/migration/migrate_test.go
Normal file
254
kubernetes/migration/migrate_test.go
Normal file
|
@ -0,0 +1,254 @@
|
|||
package migration
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMigrate(t *testing.T) {
|
||||
startCorefile := `.:53 {
|
||||
#mycomment
|
||||
errors
|
||||
health
|
||||
kubernetes cluster.local in-addr.arpa ip6.arpa {
|
||||
pods insecure
|
||||
upstream
|
||||
fallthrough in-addr.arpa ip6.arpa
|
||||
}
|
||||
prometheus :9153
|
||||
proxy . /etc/resolv.conf
|
||||
cache 30
|
||||
loop
|
||||
reload
|
||||
loadbalance
|
||||
}
|
||||
`
|
||||
|
||||
expected := `.:53 {
|
||||
errors
|
||||
health
|
||||
kubernetes cluster.local in-addr.arpa ip6.arpa {
|
||||
pods insecure
|
||||
fallthrough in-addr.arpa ip6.arpa
|
||||
}
|
||||
prometheus :9153
|
||||
forward . /etc/resolv.conf
|
||||
cache 30
|
||||
loop
|
||||
reload
|
||||
loadbalance
|
||||
}
|
||||
`
|
||||
result, err := Migrate("1.3.1", "1.5.0", startCorefile, true)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
if result != expected {
|
||||
t.Errorf("expected %v; got %v", expected, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeprecated(t *testing.T) {
|
||||
startCorefile := `.:53 {
|
||||
errors
|
||||
health
|
||||
kubernetes cluster.local in-addr.arpa ip6.arpa {
|
||||
pods insecure
|
||||
upstream
|
||||
fallthrough in-addr.arpa ip6.arpa
|
||||
}
|
||||
prometheus :9153
|
||||
proxy . /etc/resolv.conf
|
||||
cache 30
|
||||
loop
|
||||
reload
|
||||
loadbalance
|
||||
}
|
||||
`
|
||||
|
||||
expected := []Notice{
|
||||
{Plugin: "kubernetes", Option: "upstream", Severity: deprecated, Version: "1.4.0"},
|
||||
{Plugin: "proxy", Severity: deprecated, ReplacedBy: "forward", Version: "1.4.0"},
|
||||
}
|
||||
|
||||
result, err := Deprecated("1.3.1", "1.5.0", startCorefile)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(result) != len(expected) {
|
||||
t.Fatalf("expected to find %v deprecations; got %v", len(expected), len(result))
|
||||
}
|
||||
|
||||
for i, dep := range expected {
|
||||
if result[i].ToString() != dep.ToString() {
|
||||
t.Errorf("expected to get '%v'; got '%v'", dep.ToString(), result[i].ToString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoved(t *testing.T) {
|
||||
startCorefile := `.:53 {
|
||||
errors
|
||||
health
|
||||
kubernetes cluster.local in-addr.arpa ip6.arpa {
|
||||
pods insecure
|
||||
upstream
|
||||
fallthrough in-addr.arpa ip6.arpa
|
||||
}
|
||||
prometheus :9153
|
||||
proxy . /etc/resolv.conf
|
||||
cache 30
|
||||
loop
|
||||
reload
|
||||
loadbalance
|
||||
}
|
||||
`
|
||||
|
||||
expected := []Notice{
|
||||
{Plugin: "proxy", Severity: removed, ReplacedBy: "forward", Version: "1.5.0"},
|
||||
}
|
||||
|
||||
result, err := Removed("1.3.1", "1.5.0", startCorefile)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(result) != len(expected) {
|
||||
t.Fatalf("expected to find %v deprecations; got %v", len(expected), len(result))
|
||||
}
|
||||
|
||||
for i, dep := range expected {
|
||||
if result[i].ToString() != dep.ToString() {
|
||||
t.Errorf("expected to get '%v'; got '%v'", dep.ToString(), result[i].ToString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnsupported(t *testing.T) {
|
||||
startCorefile := `.:53 {
|
||||
errors
|
||||
health
|
||||
kubernetes cluster.local in-addr.arpa ip6.arpa {
|
||||
pods insecure
|
||||
upstream
|
||||
fallthrough in-addr.arpa ip6.arpa
|
||||
}
|
||||
route53 example.org.:Z1Z2Z3Z4DZ5Z6Z7
|
||||
prometheus :9153
|
||||
proxy . /etc/resolv.conf
|
||||
cache 30
|
||||
loop
|
||||
reload
|
||||
loadbalance
|
||||
}
|
||||
`
|
||||
|
||||
expected := []Notice{
|
||||
{Plugin: "route53", Severity: unsupported, Version: "1.4.0"},
|
||||
{Plugin: "route53", Severity: unsupported, Version: "1.5.0"},
|
||||
}
|
||||
|
||||
result, err := Unsupported("1.3.1", "1.5.0", startCorefile)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(result) != len(expected) {
|
||||
t.Fatalf("expected to find %v deprecations; got %v", len(expected), len(result))
|
||||
}
|
||||
|
||||
for i, dep := range expected {
|
||||
if result[i].ToString() != dep.ToString() {
|
||||
t.Errorf("expected to get '%v'; got '%v'", dep.ToString(), result[i].ToString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDefault(t *testing.T) {
|
||||
defaultCorefiles := []string{`.:53 {
|
||||
errors
|
||||
health
|
||||
kubernetes cluster.local in-addr.arpa ip6.arpa {
|
||||
pods insecure
|
||||
upstream
|
||||
fallthrough in-addr.arpa ip6.arpa
|
||||
}
|
||||
prometheus :9153
|
||||
forward . /etc/resolv.conf
|
||||
cache 30
|
||||
loop
|
||||
reload
|
||||
loadbalance
|
||||
}
|
||||
`,
|
||||
`.:53 {
|
||||
errors
|
||||
health
|
||||
kubernetes myzone.org in-addr.arpa ip6.arpa {
|
||||
pods insecure
|
||||
upstream
|
||||
fallthrough in-addr.arpa ip6.arpa
|
||||
}
|
||||
prometheus :9153
|
||||
forward . /etc/resolv.conf
|
||||
cache 30
|
||||
loop
|
||||
reload
|
||||
loadbalance
|
||||
}
|
||||
`}
|
||||
|
||||
nonDefaultCorefiles := []string{`.:53 {
|
||||
errors
|
||||
health
|
||||
rewrite name suffix myzone.org cluster.local
|
||||
kubernetes cluster.local in-addr.arpa ip6.arpa {
|
||||
pods insecure
|
||||
upstream
|
||||
fallthrough in-addr.arpa ip6.arpa
|
||||
}
|
||||
prometheus :9153
|
||||
forward . /etc/resolv.conf
|
||||
cache 30
|
||||
loop
|
||||
reload
|
||||
loadbalance
|
||||
}
|
||||
`,
|
||||
`.:53 {
|
||||
errors
|
||||
health
|
||||
kubernetes cluster.local in-addr.arpa ip6.arpa {
|
||||
pods insecure
|
||||
upstream
|
||||
fallthrough in-addr.arpa ip6.arpa
|
||||
}
|
||||
prometheus :9153
|
||||
forward . /etc/resolv.conf
|
||||
cache 30
|
||||
loop
|
||||
reload
|
||||
loadbalance
|
||||
}
|
||||
stubzone.org:53 {
|
||||
forward . 1.2.3.4
|
||||
}
|
||||
`}
|
||||
|
||||
|
||||
for _, d := range defaultCorefiles {
|
||||
if !Default("", d) {
|
||||
t.Errorf("expected config to be identified as a default: %v", d)
|
||||
}
|
||||
}
|
||||
for _, d := range nonDefaultCorefiles {
|
||||
if Default("", d) {
|
||||
t.Errorf("expected config to NOT be identified as a default: %v", d)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue