mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2026-03-04 07:21:01 +01:00
* chore(source): standardize sources Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com> * chore(source): sources to standartise with IsControllerMismatch Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com> * chore(source): sources to standartise with IsControllerMismatch Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com> * chore(source): sources to standartise with IsControllerMismatch Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com> * chore(source): sources to standartise with IsControllerMismatch Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com> * chore(source): sources to standartise with IsControllerMismatch Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com> * chore(source): sources to standartise Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com> * chore(source): sources to standartise Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com> * chore(source): sources to standartise Co-authored-by: vflaux <38909103+vflaux@users.noreply.github.com> * chore(source): sources to standartise Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com> * chore(source): sources to standartise Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com> * chore(source): sources to standartise Co-authored-by: vflaux <38909103+vflaux@users.noreply.github.com> --------- Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com> Co-authored-by: vflaux <38909103+vflaux@users.noreply.github.com>
89 lines
2.3 KiB
Go
89 lines
2.3 KiB
Go
/*
|
|
Copyright 2026 The Kubernetes Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package endpoint
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
)
|
|
|
|
type mockObjectMetaAccessor struct {
|
|
namespace string
|
|
name string
|
|
}
|
|
|
|
func (m *mockObjectMetaAccessor) GetObjectMeta() metav1.Object {
|
|
return &metav1.ObjectMeta{
|
|
Namespace: m.namespace,
|
|
Name: m.name,
|
|
}
|
|
}
|
|
|
|
func TestHasEmptyEndpoints(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
endpoints []*Endpoint
|
|
rType string
|
|
entity metav1.ObjectMetaAccessor
|
|
expected bool
|
|
}{
|
|
{
|
|
name: "nil endpoints returns true",
|
|
endpoints: nil,
|
|
rType: "Service",
|
|
entity: &mockObjectMetaAccessor{namespace: "default", name: "my-service"},
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "empty slice returns true",
|
|
endpoints: []*Endpoint{},
|
|
rType: "Ingress",
|
|
entity: &mockObjectMetaAccessor{namespace: "kube-system", name: "my-ingress"},
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "single endpoint returns false",
|
|
endpoints: []*Endpoint{
|
|
NewEndpoint("example.org", "A", "1.2.3.4"),
|
|
},
|
|
rType: "Service",
|
|
entity: &mockObjectMetaAccessor{namespace: "default", name: "my-service"},
|
|
expected: false,
|
|
},
|
|
{
|
|
name: "multiple endpoints returns false",
|
|
endpoints: []*Endpoint{
|
|
NewEndpoint("example.org", "A", "1.2.3.4"),
|
|
NewEndpoint("test.example.org", "CNAME", "example.org"),
|
|
},
|
|
rType: "Ingress",
|
|
entity: &mockObjectMetaAccessor{namespace: "production", name: "frontend"},
|
|
expected: false,
|
|
},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
result := HasNoEmptyEndpoints(tc.endpoints, tc.rType, tc.entity)
|
|
assert.Equal(t, tc.expected, result)
|
|
// TODO: Add log capture and verification
|
|
})
|
|
}
|
|
}
|