<commit_before>package source

import (
	"testing"

	"k8s.io/client-go/kubernetes/fake"
	"k8s.io/client-go/pkg/api/v1"

	"github.com/kubernetes-incubator/external-dns/endpoint"
)

// TestEndpoints tests that various services generate the correct endpoints.
func TestEndpoints(t *testing.T) {
	for _, tc := range []struct {
		msg         string
		namespace   string
		name        string
		annotations map[string]string
		lbs         []string
		expected    []endpoint.Endpoint
	}{
		{
			"no annotated services return no endpoints",
			"testing",
			"foo",
			map[string]string{},
			[]string{"172.16.58.3"},
			[]endpoint.Endpoint{},
		},
		{
			"annotated services return an endpoint",
			"testing",
			"foo",
			map[string]string{
				"external-dns.kubernetes.io/hostname": "foo.example.org",
			},
			[]string{"172.16.58.3"},
			[]endpoint.Endpoint{
				{DNSName: "foo.example.org", Target: "172.16.58.3"},
			},
		},
		{
			"our controller type is dns-controller",
			"testing",
			"foo",
			map[string]string{
				"external-dns.kubernetes.io/controller": "dns-controller",
				"external-dns.kubernetes.io/hostname":   "foo.example.org",
			},
			[]string{"172.16.58.3"},
			[]endpoint.Endpoint{
				{DNSName: "foo.example.org", Target: "172.16.58.3"},
			},
		},
		{
			"different controller types are ignored",
			"testing",
			"foo",
			map[string]string{
				"external-dns.kubernetes.io/controller": "some-other-tool",
				"external-dns.kubernetes.io/hostname":   "foo.example.org",
			},
			[]string{"172.16.58.3"},
			[]endpoint.Endpoint{},
		},
		{
			"services are found in all namespaces",
			"other-testing",
			"foo",
			map[string]string{
				"external-dns.kubernetes.io/hostname": "foo.example.org",
			},
			[]string{"172.16.58.3"},
			[]endpoint.Endpoint{
				{DNSName: "foo.example.org", Target: "172.16.58.3"},
			},
		},
		{
			"no external entrypoints return no endpoints",
			"testing",
			"foo",
			map[string]string{
				"external-dns.kubernetes.io/hostname": "foo.example.org",
			},
			[]string{},
			[]endpoint.Endpoint{},
		},
		{
			"multiple external entrypoints return multiple endpoints",
			"testing",
			"foo",
			map[string]string{
				"external-dns.kubernetes.io/hostname": "foo.example.org",
			},
			[]string{"172.16.58.3", "8.8.8.8"},
			[]endpoint.Endpoint{
				{DNSName: "foo.example.org", Target: "172.16.58.3"},
				{DNSName: "foo.example.org", Target: "8.8.8.8"},
			},
		},
	} {
		t.Run(tc.msg, func(t *testing.T) {
			// Create a Kubernetes testing client
			kubernetes := fake.NewSimpleClientset()

			// Create a service to test against
			ingresses := []v1.LoadBalancerIngress{}
			for _, lb := range tc.lbs {
				ingresses = append(ingresses, v1.LoadBalancerIngress{IP: lb})
			}

			service := &v1.Service{
				ObjectMeta: v1.ObjectMeta{
					Namespace:   tc.namespace,
					Name:        tc.name,
					Annotations: tc.annotations,
				},
				Status: v1.ServiceStatus{<commit_msg>ref: rename test message to test title<commit_after>package source

import (
	"testing"

	"k8s.io/client-go/kubernetes/fake"
	"k8s.io/client-go/pkg/api/v1"

	"github.com/kubernetes-incubator/external-dns/endpoint"
)

// TestEndpoints tests that various services generate the correct endpoints.
func TestEndpoints(t *testing.T) {
	for _, tc := range []struct {
		title       string
		namespace   string
		name        string
		annotations map[string]string
		lbs         []string
		expected    []endpoint.Endpoint
	}{
		{
			"no annotated services return no endpoints",
			"testing",
			"foo",
			map[string]string{},
			[]string{"172.16.58.3"},
			[]endpoint.Endpoint{},
		},
		{
			"annotated services return an endpoint",
			"testing",
			"foo",
			map[string]string{
				"external-dns.kubernetes.io/hostname": "foo.example.org",
			},
			[]string{"172.16.58.3"},
			[]endpoint.Endpoint{
				{DNSName: "foo.example.org", Target: "172.16.58.3"},
			},
		},
		{
			"our controller type is dns-controller",
			"testing",
			"foo",
			map[string]string{
				"external-dns.kubernetes.io/controller": "dns-controller",
				"external-dns.kubernetes.io/hostname":   "foo.example.org",
			},
			[]string{"172.16.58.3"},
			[]endpoint.Endpoint{
				{DNSName: "foo.<EMAIL>.<EMAIL>", Target: "172.16.58.3"},
			},
		},
		{
			"different controller types are ignored",
			"testing",
			"foo",
			map[string]string{
				"external-dns.kubernetes.io/controller": "some-other-tool",
				"external-dns.kubernetes.io/hostname":   "foo.example.org",
			},
			[]string{"172.16.58.3"},
			[]endpoint.Endpoint{},
		},
		{
			"services are found in all namespaces",
			"other-testing",
			"foo",
			map[string]string{
				"external-dns.kubernetes.io/hostname": "foo.example.org",
			},
			[]string{"172.16.58.3"},
			[]endpoint.Endpoint{
				{DNSName: "foo.example.org", Target: "172.16.58.3"},
			},
		},
		{
			"no external entrypoints return no endpoints",
			"testing",
			"foo",
			map[string]string{
				"external-dns.kubernetes.io/hostname": "foo.example.org",
			},
			[]string{},
			[]endpoint.Endpoint{},
		},
		{
			"multiple external entrypoints return multiple endpoints",
			"testing",
			"foo",
			map[string]string{
				"external-dns.kubernetes.io/hostname": "foo.example.org",
			},
			[]string{"172.16.58.3", "8.8.8.8"},
			[]endpoint.Endpoint{
				{DNSName: "foo.example.org", Target: "172.16.58.3"},
				{DNSName: "foo.example.org", Target: "8.8.8.8"},
			},
		},
	} {
		t.Run(tc.title, func(t *testing.T) {
			// Create a Kubernetes testing client
			kubernetes := fake.NewSimpleClientset()

			// Create a service to test against
			ingresses := []v1.LoadBalancerIngress{}
			for _, lb := range tc.lbs {
				ingresses = append(ingresses, v1.LoadBalancerIngress{IP: lb})
			}

			service := &v1.Service{
				ObjectMeta: v1.ObjectMeta{
					Namespace:   tc.namespace,
					Name:        tc.name,
					Annotations: tc.annotations,
				},
				Status: v1.ServiceStatus{
{'fraction_non_alphanumeric': 0.17732903444764975, 'fraction_numerical': 0.03258102833870694, 'mean_word_length': 3.045298558682224, 'pattern_counts': {'":': 16, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 24, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3588554', 'n_tokens_mistral': 2610, 'n_tokens_neox': 2092, 'n_words': 373}