Skip to content

Commit

Permalink
refactor test following review
Browse files Browse the repository at this point in the history
  • Loading branch information
mloiseleur committed Jan 19, 2025
1 parent cc54682 commit 5561d91
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
8 changes: 0 additions & 8 deletions endpoint/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,6 @@ func NewTargets(target ...string) Targets {
return t
}

func NewTargetsFromAddr(targets []netip.Addr) Targets {
t := make(Targets, 0, len(targets))
for _, target := range targets {
t = append(t, target.String())
}
return t
}

func (t Targets) String() string {
return strings.Join(t, ";")
}
Expand Down
10 changes: 10 additions & 0 deletions internal/testutils/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package testutils

import (
"net/netip"
"reflect"
"sort"

Expand Down Expand Up @@ -122,3 +123,12 @@ func SameProviderSpecific(a, b endpoint.ProviderSpecific) bool {
sort.Sort(byNames(sb))
return reflect.DeepEqual(sa, sb)
}

// NewTargetsFromAddr convert an array of netip.Addr to Targets (array of string)
func NewTargetsFromAddr(targets []netip.Addr) endpoint.Targets {
t := make(endpoint.Targets, len(targets))
for i, target := range targets {
t[i] = target.String()
}
return t
}
5 changes: 3 additions & 2 deletions source/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"k8s.io/client-go/kubernetes/fake"

"sigs.k8s.io/external-dns/endpoint"
"sigs.k8s.io/external-dns/internal/testutils"
)

type ServiceSuite struct {
Expand Down Expand Up @@ -411,8 +412,8 @@ func testServiceSourceEndpoints(t *testing.T) {
serviceTypesFilter: []string{},
resolveLoadBalancerHostname: true,
expected: []*endpoint.Endpoint{
{DNSName: "foo.example.org", RecordType: endpoint.RecordTypeA, Targets: endpoint.NewTargetsFromAddr(exampleDotComIP4)},
{DNSName: "foo.example.org", RecordType: endpoint.RecordTypeAAAA, Targets: endpoint.NewTargetsFromAddr(exampleDotComIP6)},
{DNSName: "foo.example.org", RecordType: endpoint.RecordTypeA, Targets: testutils.NewTargetsFromAddr(exampleDotComIP4)},
{DNSName: "foo.example.org", RecordType: endpoint.RecordTypeAAAA, Targets: testutils.NewTargetsFromAddr(exampleDotComIP6)},
},
},
{
Expand Down

0 comments on commit 5561d91

Please sign in to comment.