create shared_test and scope service tests

This commit is contained in:
ideahitme 2017-03-02 11:24:23 +01:00
parent 99371a1e83
commit 014982cafc
2 changed files with 36 additions and 25 deletions

View File

@ -26,8 +26,12 @@ import (
"github.com/kubernetes-incubator/external-dns/endpoint"
)
// TestEndpoints tests that various services generate the correct endpoints.
func TestEndpoints(t *testing.T) {
func TestService(t *testing.T) {
t.Run("Endpoints", testServiceEndpoints)
}
// testServiceEndpoints tests that various services generate the correct endpoints.
func testServiceEndpoints(t *testing.T) {
for _, tc := range []struct {
title string
namespace string
@ -176,7 +180,7 @@ func TestEndpoints(t *testing.T) {
}
}
func BenchmarkEndpoints(b *testing.B) {
func BenchmarkServiceEndpoints(b *testing.B) {
kubernetes := fake.NewSimpleClientset()
service := &v1.Service{
@ -213,25 +217,3 @@ func BenchmarkEndpoints(b *testing.B) {
}
}
}
// test helper functions
func validateEndpoints(t *testing.T, endpoints, expected []endpoint.Endpoint) {
if len(endpoints) != len(expected) {
t.Fatalf("expected %d endpoints, got %d", len(expected), len(endpoints))
}
for i := range endpoints {
validateEndpoint(t, endpoints[i], expected[i])
}
}
func validateEndpoint(t *testing.T, endpoint, expected endpoint.Endpoint) {
if endpoint.DNSName != expected.DNSName {
t.Errorf("expected %s, got %s", expected.DNSName, endpoint.DNSName)
}
if endpoint.Target != expected.Target {
t.Errorf("expected %s, got %s", expected.Target, endpoint.Target)
}
}

29
source/shared_test.go Normal file
View File

@ -0,0 +1,29 @@
package source
import (
"testing"
"github.com/kubernetes-incubator/external-dns/endpoint"
)
// test helper functions
func validateEndpoints(t *testing.T, endpoints, expected []endpoint.Endpoint) {
if len(endpoints) != len(expected) {
t.Fatalf("expected %d endpoints, got %d", len(expected), len(endpoints))
}
for i := range endpoints {
validateEndpoint(t, endpoints[i], expected[i])
}
}
func validateEndpoint(t *testing.T, endpoint, expected endpoint.Endpoint) {
if endpoint.DNSName != expected.DNSName {
t.Errorf("expected %s, got %s", expected.DNSName, endpoint.DNSName)
}
if endpoint.Target != expected.Target {
t.Errorf("expected %s, got %s", expected.Target, endpoint.Target)
}
}