@@ -325,6 +325,64 @@ func TestAlibabaCloudProvider_ApplyChanges(t *testing.T) {
325
325
}
326
326
}
327
327
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
+
328
386
func TestAlibabaCloudProvider_Records_PrivateZone (t * testing.T ) {
329
387
p := newTestAlibabaCloudProvider (true )
330
388
endpoints , err := p .Records (context .Background ())
@@ -389,6 +447,8 @@ func TestAlibabaCloudProvider_splitDNSName(t *testing.T) {
389
447
endpoint := & endpoint.Endpoint {}
390
448
hostedZoneDomains := []string {"container-service.top" , "example.org" }
391
449
450
+ var emptyZoneDomains []string
451
+
392
452
endpoint .DNSName = "www.example.org"
393
453
rr , domain := p .splitDNSName (endpoint .DNSName , hostedZoneDomains )
394
454
if rr != "www" || domain != "example.org" {
@@ -440,6 +500,14 @@ func TestAlibabaCloudProvider_splitDNSName(t *testing.T) {
440
500
if rr != "a.b" || domain != "c.container-service.top" {
441
501
t .Errorf ("Failed to splitDNSName for %s: rr=%s, domain=%s" , endpoint .DNSName , rr , domain )
442
502
}
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
+ }
443
511
}
444
512
445
513
func TestAlibabaCloudProvider_TXTEndpoint (t * testing.T ) {
0 commit comments