Skip to content

Commit 7576e8b

Browse files
committed
add testcases
1 parent 437a826 commit 7576e8b

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

provider/alibabacloud/alibaba_cloud_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,64 @@ func TestAlibabaCloudProvider_ApplyChanges(t *testing.T) {
325325
}
326326
}
327327

328+
func TestAlibabaCloudProvider_ApplyChanges_HaveNoDefinedZoneDomain(t *testing.T) {
329+
p := newTestAlibabaCloudProvider(false)
330+
defaultTtlPlan := &endpoint.Endpoint{
331+
DNSName: "ttl.container-service.top",
332+
RecordType: "A",
333+
RecordTTL: defaultTTL,
334+
Targets: endpoint.NewTargets("4.3.2.1"),
335+
}
336+
changes := plan.Changes{
337+
Create: []*endpoint.Endpoint{
338+
{
339+
DNSName: "www.example.com", //no found this zone by API: DescribeDomains
340+
RecordType: "A",
341+
RecordTTL: 300,
342+
Targets: endpoint.NewTargets("9.9.9.9"),
343+
},
344+
defaultTtlPlan,
345+
},
346+
UpdateNew: []*endpoint.Endpoint{
347+
{
348+
DNSName: "abc.container-service.top",
349+
RecordType: "A",
350+
RecordTTL: 500,
351+
Targets: endpoint.NewTargets("1.2.3.4", "5.6.7.8"),
352+
},
353+
},
354+
Delete: []*endpoint.Endpoint{
355+
{
356+
DNSName: "abc.container-service.top",
357+
RecordType: "TXT",
358+
RecordTTL: 300,
359+
Targets: endpoint.NewTargets("\"heritage=external-dns,external-dns/owner=default\""),
360+
},
361+
},
362+
}
363+
ctx := context.Background()
364+
err := p.ApplyChanges(ctx, &changes)
365+
assert.NoError(t, err)
366+
endpoints, err := p.Records(ctx)
367+
if err != nil {
368+
t.Errorf("Failed to get records: %v", err)
369+
} else {
370+
if len(endpoints) != 2 {
371+
t.Errorf("Incorrect number of records: %d", len(endpoints))
372+
}
373+
for _, ep := range endpoints {
374+
t.Logf("Endpoint for %++v", *ep)
375+
}
376+
}
377+
for _, ep := range endpoints {
378+
if ep.DNSName == defaultTtlPlan.DNSName {
379+
if ep.RecordTTL != defaultTtlPlan.RecordTTL {
380+
t.Error("default ttl execute error")
381+
}
382+
}
383+
}
384+
}
385+
328386
func TestAlibabaCloudProvider_Records_PrivateZone(t *testing.T) {
329387
p := newTestAlibabaCloudProvider(true)
330388
endpoints, err := p.Records(context.Background())
@@ -389,6 +447,8 @@ func TestAlibabaCloudProvider_splitDNSName(t *testing.T) {
389447
endpoint := &endpoint.Endpoint{}
390448
hostedZoneDomains := []string{"container-service.top", "example.org"}
391449

450+
var emptyZoneDomains []string
451+
392452
endpoint.DNSName = "www.example.org"
393453
rr, domain := p.splitDNSName(endpoint.DNSName, hostedZoneDomains)
394454
if rr != "www" || domain != "example.org" {
@@ -440,6 +500,14 @@ func TestAlibabaCloudProvider_splitDNSName(t *testing.T) {
440500
if rr != "a.b" || domain != "c.container-service.top" {
441501
t.Errorf("Failed to splitDNSName for %s: rr=%s, domain=%s", endpoint.DNSName, rr, domain)
442502
}
503+
rr, domain = p.splitDNSName(endpoint.DNSName, emptyZoneDomains)
504+
if rr != "@" || domain != "" {
505+
t.Errorf("Failed to splitDNSName with emptyZoneDomains for %s: rr=%s, domain=%s", endpoint.DNSName, rr, domain)
506+
}
507+
rr, domain = p.splitDNSName(endpoint.DNSName, []string{"example.com"})
508+
if rr != "@" || domain != "" {
509+
t.Errorf("Failed to splitDNSName for %s: rr=%s, domain=%s", endpoint.DNSName, rr, domain)
510+
}
443511
}
444512

445513
func TestAlibabaCloudProvider_TXTEndpoint(t *testing.T) {

0 commit comments

Comments
 (0)