external-dns/source/fake_test.go
Ivan Ka e9983a5726
feat(events): raise k8s events with fake provider (#5659)
* feat(events): publish k8s events

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>

* feat(events): publish k8s events

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>

* feat(events): publish k8s events

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>

* feat(events): publish k8s events

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>

* feat(events): publish k8s events

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>

* feat(events): raise k8s events with fake provider

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>

* feat(events): raise k8s events with fake provider

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>

* feat(events): raise k8s events with fake provider

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>

* feat(events): raise k8s events with fake provider

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>

* feat(events): raise k8s events with fake provider

Co-authored-by: Michel Loiseleur <97035654+mloiseleur@users.noreply.github.com>

* feat(events): raise k8s events with fake provider

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>

* feat(events): raise k8s events with fake provide

Co-authored-by: Michel Loiseleur <97035654+mloiseleur@users.noreply.github.com>

* feat(events): raise k8s events with fake provider

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>

* feat(events): raise k8s events with fake provider

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>

---------

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
Co-authored-by: Michel Loiseleur <97035654+mloiseleur@users.noreply.github.com>
2025-08-20 00:37:07 -07:00

86 lines
1.8 KiB
Go

/*
Copyright 2017 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 source
import (
"context"
"net"
"regexp"
"testing"
"github.com/stretchr/testify/require"
"sigs.k8s.io/external-dns/endpoint"
)
// Validate that FakeSource is a source
var _ Source = &fakeSource{}
func generateTestEndpoints() []*endpoint.Endpoint {
sc, _ := NewFakeSource("")
endpoints, _ := sc.Endpoints(context.Background())
return endpoints
}
func TestFakeSourceReturnsTenEndpoints(t *testing.T) {
endpoints := generateTestEndpoints()
count := len(endpoints)
if count != 10 {
t.Error(count)
}
}
func TestFakeEndpointsBelongToDomain(t *testing.T) {
validRecord := regexp.MustCompile(`^[a-z]{4}\.example\.com$`)
endpoints := generateTestEndpoints()
for _, e := range endpoints {
valid := validRecord.MatchString(e.DNSName)
if !valid {
t.Error(e.DNSName)
}
}
}
func TestFakeEndpointsResolveToIPAddresses(t *testing.T) {
endpoints := generateTestEndpoints()
for _, e := range endpoints {
ip := net.ParseIP(e.Targets[0])
if ip == nil {
t.Error(e)
}
}
}
func TestFakeSource_GenerateEndpoint_RefObject(t *testing.T) {
sc, _ := NewFakeSource("example.com")
fs := sc.(*fakeSource)
ep := fs.generateEndpoint()
require.NotNil(t, ep, "endpoint should not be nil")
require.NotNil(t, ep.RefObject())
require.Equal(t, "Pod", ep.RefObject().Kind)
}