Skip to content

Commit

Permalink
fix tests, adjust endpoints now filter txt records
Browse files Browse the repository at this point in the history
  • Loading branch information
kokizzu committed Mar 14, 2024
1 parent 9079010 commit 5d8f409
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 53 deletions.
21 changes: 14 additions & 7 deletions gcoreprovider/gcore.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ type dnsManager interface {
zone, recordName, recordType string,
values []gdns.ResourceRecord, ttl int, opts ...gdns.AddZoneOpt) error
ZonesWithRecords(ctx context.Context, filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error)
Zones(ctx context.Context, filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error)
DeleteRRSetRecord(ctx context.Context, zone, name, recordType string, contents ...string) error
}

Expand Down Expand Up @@ -137,7 +136,7 @@ func (p *DnsProvider) ApplyChanges(rootCtx context.Context, changes *plan.Change
gr2.Go(func() error {
err := errSafeWrap(strings.Join(errMsg, "; "),
p.client.DeleteRRSetRecord(ctx, zone, d.DNSName, d.RecordType, recordValues...))
log.Debugf("%s ApplyChanges.updateNew,DeleteRRSetRecord: %s %s %v ERR=%s",
log.Debugf("%s ApplyChanges.updateNew,DeleteRRSetRecord: %s %s %v ERR=%v",
ProviderName, d.DNSName, d.RecordType, recordValues, err)
return err
})
Expand Down Expand Up @@ -166,7 +165,7 @@ func (p *DnsProvider) ApplyChanges(rootCtx context.Context, changes *plan.Change
gr1.Go(func() error {
err := errSafeWrap(strings.Join(errMsg, "; "),
p.client.DeleteRRSetRecord(ctx, zone, d.DNSName, d.RecordType, recordValues...))
log.Debugf("%s ApplyChanges.Delete,DeleteRRSetRecord: %s %s %v ERR=%s",
log.Debugf("%s ApplyChanges.Delete,DeleteRRSetRecord: %s %s %v ERR=%v",
ProviderName, d.DNSName, d.RecordType, recordValues, err)
return err
})
Expand All @@ -175,7 +174,7 @@ func (p *DnsProvider) ApplyChanges(rootCtx context.Context, changes *plan.Change
for _, c := range changes.Create {
c := c
zone := extractZone(c.DNSName)
if zone == "" {
if zone == "" || c.RecordType == "TXT" {
continue
}
recordValues := make([]gdns.ResourceRecord, 0)
Expand All @@ -196,7 +195,7 @@ func (p *DnsProvider) ApplyChanges(rootCtx context.Context, changes *plan.Change
gr1.Go(func() error {
err := errSafeWrap(strings.Join(errMsg, "; "),
p.client.AddZoneRRSet(ctx, zone, c.DNSName, c.RecordType, recordValues, int(c.RecordTTL)))
log.Debugf("%s ApplyChanges.Create,AddZoneRRSet: %s %s %v ERR=%s",
log.Debugf("%s ApplyChanges.Create,AddZoneRRSet: %s %s %v ERR=%v",
ProviderName, c.DNSName, c.RecordType, recordValues, err)
return err
})
Expand Down Expand Up @@ -235,7 +234,7 @@ func (p *DnsProvider) ApplyChanges(rootCtx context.Context, changes *plan.Change
gr1.Go(func() error {
err := errSafeWrap(strings.Join(errMsg, "; "),
p.client.AddZoneRRSet(ctx, zone, c.DNSName, c.RecordType, recordValues, int(c.RecordTTL)))
log.Debugf("%s ApplyChanges.UpdateNew,AddZoneRRSet: %s %s %v ERR=%s",
log.Debugf("%s ApplyChanges.UpdateNew,AddZoneRRSet: %s %s %v ERR=%v",
ProviderName, c.DNSName, c.RecordType, recordValues, err)
return err
})
Expand Down Expand Up @@ -265,7 +264,15 @@ func (p *DnsProvider) GetDomainFilter() endpoint.DomainFilter {
}

func (p *DnsProvider) AdjustEndpoints(endpoints []*endpoint.Endpoint) ([]*endpoint.Endpoint, error) {
return endpoints, nil
adjusted := make([]*endpoint.Endpoint, 0, len(endpoints))
for _, e := range endpoints {
e := e
if e.RecordType != "TXT" {
adjusted = append(adjusted, e)
}
}
return adjusted, nil
//return endpoints, nil
}

func (p *DnsProvider) PropertyValuesEqual(_ string, previous string, current string) bool {
Expand Down
54 changes: 8 additions & 46 deletions gcoreprovider/gcore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
type dnsManagerMock struct {
addZoneRRSet func(ctx context.Context, zone, recordName, recordType string, values []gdns.ResourceRecord, ttl int) error
zonesWithRecords func(ctx context.Context, filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error)
zones func(ctx context.Context, filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error)
deleteRRSetRecord func(ctx context.Context, zone, name, recordType string, contents ...string) error
}

Expand All @@ -39,9 +38,6 @@ func (d dnsManagerMock) AddZoneRRSet(ctx context.Context,
func (d dnsManagerMock) ZonesWithRecords(ctx context.Context, filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
return d.zonesWithRecords(ctx, filters...)
}
func (d dnsManagerMock) Zones(ctx context.Context, filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
return d.zones(ctx, filters...)
}
func (d dnsManagerMock) DeleteRRSetRecord(ctx context.Context, zone, name, recordType string, contents ...string) error {
return d.deleteRRSetRecord(ctx, zone, name, recordType, contents...)
}
Expand Down Expand Up @@ -83,9 +79,6 @@ func Test_dnsProvider_Records(t *testing.T) {
},
}, nil
},
zones: func(ctx context.Context, filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
return []gdns.Zone{}, nil
},
},
dryRun: false,
},
Expand All @@ -105,34 +98,6 @@ func Test_dnsProvider_Records(t *testing.T) {
client: dnsManagerMock{
zonesWithRecords: func(ctx context.Context,
filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
zoneFilter := &gdns.ZonesFilter{}
for _, op := range filters {
op(zoneFilter)
}
val := []gdns.Zone{
{
Name: "example.com",
Records: []gdns.ZoneRecord{
{
Name: "test.example.com",
Type: "A",
TTL: 10,
ShortAnswers: []string{"1.1.1.1"},
},
},
},
}
res := make([]gdns.Zone, 0)
for _, v := range val {
for _, name := range zoneFilter.Names {
if name == v.Name {
res = append(res, v)
}
}
}
return res, nil
},
zones: func(ctx context.Context, filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
return []gdns.Zone{
{
Name: "example.com",
Expand Down Expand Up @@ -168,9 +133,6 @@ func Test_dnsProvider_Records(t *testing.T) {
filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
return nil, fmt.Errorf("test")
},
zones: func(ctx context.Context, filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
return []gdns.Zone{}, nil
},
},
dryRun: false,
},
Expand Down Expand Up @@ -223,7 +185,7 @@ func Test_dnsProvider_GetDomainFilter(t *testing.T) {
fields: fields{
domainFilter: endpoint.DomainFilter{},
client: dnsManagerMock{
zones: func(ctx context.Context,
zonesWithRecords: func(ctx context.Context,
filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
return []gdns.Zone{{Name: "example.com"}}, nil
},
Expand All @@ -237,7 +199,7 @@ func Test_dnsProvider_GetDomainFilter(t *testing.T) {
fields: fields{
domainFilter: endpoint.DomainFilter{},
client: dnsManagerMock{
zones: func(ctx context.Context,
zonesWithRecords: func(ctx context.Context,
filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
return []gdns.Zone{}, nil
},
Expand Down Expand Up @@ -282,7 +244,7 @@ func Test_dnsProvider_ApplyChanges(t *testing.T) {
fields: fields{
domainFilter: endpoint.DomainFilter{},
client: dnsManagerMock{
zones: func(ctx context.Context,
zonesWithRecords: func(ctx context.Context,
filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
return []gdns.Zone{{Name: "test.com"}}, nil
},
Expand Down Expand Up @@ -310,7 +272,7 @@ func Test_dnsProvider_ApplyChanges(t *testing.T) {
fields: fields{
domainFilter: endpoint.DomainFilter{},
client: dnsManagerMock{
zones: func(ctx context.Context,
zonesWithRecords: func(ctx context.Context,
filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
return []gdns.Zone{{Name: "test.com"}}, nil
},
Expand Down Expand Up @@ -338,7 +300,7 @@ func Test_dnsProvider_ApplyChanges(t *testing.T) {
fields: fields{
domainFilter: endpoint.DomainFilter{},
client: dnsManagerMock{
zones: func(ctx context.Context,
zonesWithRecords: func(ctx context.Context,
filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
return []gdns.Zone{{Name: "test.com"}}, nil
},
Expand All @@ -360,7 +322,7 @@ func Test_dnsProvider_ApplyChanges(t *testing.T) {
fields: fields{
domainFilter: endpoint.DomainFilter{},
client: dnsManagerMock{
zones: func(ctx context.Context,
zonesWithRecords: func(ctx context.Context,
filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
return []gdns.Zone{{Name: "test.com"}}, nil
},
Expand Down Expand Up @@ -388,7 +350,7 @@ func Test_dnsProvider_ApplyChanges(t *testing.T) {
fields: fields{
domainFilter: endpoint.DomainFilter{},
client: dnsManagerMock{
zones: func(ctx context.Context,
zonesWithRecords: func(ctx context.Context,
filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
return []gdns.Zone{{Name: "test.com"}}, nil
},
Expand Down Expand Up @@ -420,7 +382,7 @@ func Test_dnsProvider_ApplyChanges(t *testing.T) {
fields: fields{
domainFilter: endpoint.DomainFilter{},
client: dnsManagerMock{
zones: func(ctx context.Context,
zonesWithRecords: func(ctx context.Context,
filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
return []gdns.Zone{{Name: "test.com"}}, nil
},
Expand Down

0 comments on commit 5d8f409

Please sign in to comment.