Skip to content

Commit 5d8f409

Browse files
committed
fix tests, adjust endpoints now filter txt records
1 parent 9079010 commit 5d8f409

File tree

2 files changed

+22
-53
lines changed

2 files changed

+22
-53
lines changed

gcoreprovider/gcore.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ type dnsManager interface {
3939
zone, recordName, recordType string,
4040
values []gdns.ResourceRecord, ttl int, opts ...gdns.AddZoneOpt) error
4141
ZonesWithRecords(ctx context.Context, filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error)
42-
Zones(ctx context.Context, filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error)
4342
DeleteRRSetRecord(ctx context.Context, zone, name, recordType string, contents ...string) error
4443
}
4544

@@ -137,7 +136,7 @@ func (p *DnsProvider) ApplyChanges(rootCtx context.Context, changes *plan.Change
137136
gr2.Go(func() error {
138137
err := errSafeWrap(strings.Join(errMsg, "; "),
139138
p.client.DeleteRRSetRecord(ctx, zone, d.DNSName, d.RecordType, recordValues...))
140-
log.Debugf("%s ApplyChanges.updateNew,DeleteRRSetRecord: %s %s %v ERR=%s",
139+
log.Debugf("%s ApplyChanges.updateNew,DeleteRRSetRecord: %s %s %v ERR=%v",
141140
ProviderName, d.DNSName, d.RecordType, recordValues, err)
142141
return err
143142
})
@@ -166,7 +165,7 @@ func (p *DnsProvider) ApplyChanges(rootCtx context.Context, changes *plan.Change
166165
gr1.Go(func() error {
167166
err := errSafeWrap(strings.Join(errMsg, "; "),
168167
p.client.DeleteRRSetRecord(ctx, zone, d.DNSName, d.RecordType, recordValues...))
169-
log.Debugf("%s ApplyChanges.Delete,DeleteRRSetRecord: %s %s %v ERR=%s",
168+
log.Debugf("%s ApplyChanges.Delete,DeleteRRSetRecord: %s %s %v ERR=%v",
170169
ProviderName, d.DNSName, d.RecordType, recordValues, err)
171170
return err
172171
})
@@ -175,7 +174,7 @@ func (p *DnsProvider) ApplyChanges(rootCtx context.Context, changes *plan.Change
175174
for _, c := range changes.Create {
176175
c := c
177176
zone := extractZone(c.DNSName)
178-
if zone == "" {
177+
if zone == "" || c.RecordType == "TXT" {
179178
continue
180179
}
181180
recordValues := make([]gdns.ResourceRecord, 0)
@@ -196,7 +195,7 @@ func (p *DnsProvider) ApplyChanges(rootCtx context.Context, changes *plan.Change
196195
gr1.Go(func() error {
197196
err := errSafeWrap(strings.Join(errMsg, "; "),
198197
p.client.AddZoneRRSet(ctx, zone, c.DNSName, c.RecordType, recordValues, int(c.RecordTTL)))
199-
log.Debugf("%s ApplyChanges.Create,AddZoneRRSet: %s %s %v ERR=%s",
198+
log.Debugf("%s ApplyChanges.Create,AddZoneRRSet: %s %s %v ERR=%v",
200199
ProviderName, c.DNSName, c.RecordType, recordValues, err)
201200
return err
202201
})
@@ -235,7 +234,7 @@ func (p *DnsProvider) ApplyChanges(rootCtx context.Context, changes *plan.Change
235234
gr1.Go(func() error {
236235
err := errSafeWrap(strings.Join(errMsg, "; "),
237236
p.client.AddZoneRRSet(ctx, zone, c.DNSName, c.RecordType, recordValues, int(c.RecordTTL)))
238-
log.Debugf("%s ApplyChanges.UpdateNew,AddZoneRRSet: %s %s %v ERR=%s",
237+
log.Debugf("%s ApplyChanges.UpdateNew,AddZoneRRSet: %s %s %v ERR=%v",
239238
ProviderName, c.DNSName, c.RecordType, recordValues, err)
240239
return err
241240
})
@@ -265,7 +264,15 @@ func (p *DnsProvider) GetDomainFilter() endpoint.DomainFilter {
265264
}
266265

267266
func (p *DnsProvider) AdjustEndpoints(endpoints []*endpoint.Endpoint) ([]*endpoint.Endpoint, error) {
268-
return endpoints, nil
267+
adjusted := make([]*endpoint.Endpoint, 0, len(endpoints))
268+
for _, e := range endpoints {
269+
e := e
270+
if e.RecordType != "TXT" {
271+
adjusted = append(adjusted, e)
272+
}
273+
}
274+
return adjusted, nil
275+
//return endpoints, nil
269276
}
270277

271278
func (p *DnsProvider) PropertyValuesEqual(_ string, previous string, current string) bool {

gcoreprovider/gcore_test.go

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
type dnsManagerMock struct {
2828
addZoneRRSet func(ctx context.Context, zone, recordName, recordType string, values []gdns.ResourceRecord, ttl int) error
2929
zonesWithRecords func(ctx context.Context, filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error)
30-
zones func(ctx context.Context, filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error)
3130
deleteRRSetRecord func(ctx context.Context, zone, name, recordType string, contents ...string) error
3231
}
3332

@@ -39,9 +38,6 @@ func (d dnsManagerMock) AddZoneRRSet(ctx context.Context,
3938
func (d dnsManagerMock) ZonesWithRecords(ctx context.Context, filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
4039
return d.zonesWithRecords(ctx, filters...)
4140
}
42-
func (d dnsManagerMock) Zones(ctx context.Context, filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
43-
return d.zones(ctx, filters...)
44-
}
4541
func (d dnsManagerMock) DeleteRRSetRecord(ctx context.Context, zone, name, recordType string, contents ...string) error {
4642
return d.deleteRRSetRecord(ctx, zone, name, recordType, contents...)
4743
}
@@ -83,9 +79,6 @@ func Test_dnsProvider_Records(t *testing.T) {
8379
},
8480
}, nil
8581
},
86-
zones: func(ctx context.Context, filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
87-
return []gdns.Zone{}, nil
88-
},
8982
},
9083
dryRun: false,
9184
},
@@ -105,34 +98,6 @@ func Test_dnsProvider_Records(t *testing.T) {
10598
client: dnsManagerMock{
10699
zonesWithRecords: func(ctx context.Context,
107100
filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
108-
zoneFilter := &gdns.ZonesFilter{}
109-
for _, op := range filters {
110-
op(zoneFilter)
111-
}
112-
val := []gdns.Zone{
113-
{
114-
Name: "example.com",
115-
Records: []gdns.ZoneRecord{
116-
{
117-
Name: "test.example.com",
118-
Type: "A",
119-
TTL: 10,
120-
ShortAnswers: []string{"1.1.1.1"},
121-
},
122-
},
123-
},
124-
}
125-
res := make([]gdns.Zone, 0)
126-
for _, v := range val {
127-
for _, name := range zoneFilter.Names {
128-
if name == v.Name {
129-
res = append(res, v)
130-
}
131-
}
132-
}
133-
return res, nil
134-
},
135-
zones: func(ctx context.Context, filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
136101
return []gdns.Zone{
137102
{
138103
Name: "example.com",
@@ -168,9 +133,6 @@ func Test_dnsProvider_Records(t *testing.T) {
168133
filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
169134
return nil, fmt.Errorf("test")
170135
},
171-
zones: func(ctx context.Context, filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
172-
return []gdns.Zone{}, nil
173-
},
174136
},
175137
dryRun: false,
176138
},
@@ -223,7 +185,7 @@ func Test_dnsProvider_GetDomainFilter(t *testing.T) {
223185
fields: fields{
224186
domainFilter: endpoint.DomainFilter{},
225187
client: dnsManagerMock{
226-
zones: func(ctx context.Context,
188+
zonesWithRecords: func(ctx context.Context,
227189
filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
228190
return []gdns.Zone{{Name: "example.com"}}, nil
229191
},
@@ -237,7 +199,7 @@ func Test_dnsProvider_GetDomainFilter(t *testing.T) {
237199
fields: fields{
238200
domainFilter: endpoint.DomainFilter{},
239201
client: dnsManagerMock{
240-
zones: func(ctx context.Context,
202+
zonesWithRecords: func(ctx context.Context,
241203
filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
242204
return []gdns.Zone{}, nil
243205
},
@@ -282,7 +244,7 @@ func Test_dnsProvider_ApplyChanges(t *testing.T) {
282244
fields: fields{
283245
domainFilter: endpoint.DomainFilter{},
284246
client: dnsManagerMock{
285-
zones: func(ctx context.Context,
247+
zonesWithRecords: func(ctx context.Context,
286248
filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
287249
return []gdns.Zone{{Name: "test.com"}}, nil
288250
},
@@ -310,7 +272,7 @@ func Test_dnsProvider_ApplyChanges(t *testing.T) {
310272
fields: fields{
311273
domainFilter: endpoint.DomainFilter{},
312274
client: dnsManagerMock{
313-
zones: func(ctx context.Context,
275+
zonesWithRecords: func(ctx context.Context,
314276
filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
315277
return []gdns.Zone{{Name: "test.com"}}, nil
316278
},
@@ -338,7 +300,7 @@ func Test_dnsProvider_ApplyChanges(t *testing.T) {
338300
fields: fields{
339301
domainFilter: endpoint.DomainFilter{},
340302
client: dnsManagerMock{
341-
zones: func(ctx context.Context,
303+
zonesWithRecords: func(ctx context.Context,
342304
filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
343305
return []gdns.Zone{{Name: "test.com"}}, nil
344306
},
@@ -360,7 +322,7 @@ func Test_dnsProvider_ApplyChanges(t *testing.T) {
360322
fields: fields{
361323
domainFilter: endpoint.DomainFilter{},
362324
client: dnsManagerMock{
363-
zones: func(ctx context.Context,
325+
zonesWithRecords: func(ctx context.Context,
364326
filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
365327
return []gdns.Zone{{Name: "test.com"}}, nil
366328
},
@@ -388,7 +350,7 @@ func Test_dnsProvider_ApplyChanges(t *testing.T) {
388350
fields: fields{
389351
domainFilter: endpoint.DomainFilter{},
390352
client: dnsManagerMock{
391-
zones: func(ctx context.Context,
353+
zonesWithRecords: func(ctx context.Context,
392354
filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
393355
return []gdns.Zone{{Name: "test.com"}}, nil
394356
},
@@ -420,7 +382,7 @@ func Test_dnsProvider_ApplyChanges(t *testing.T) {
420382
fields: fields{
421383
domainFilter: endpoint.DomainFilter{},
422384
client: dnsManagerMock{
423-
zones: func(ctx context.Context,
385+
zonesWithRecords: func(ctx context.Context,
424386
filters ...func(zone *gdns.ZonesFilter)) ([]gdns.Zone, error) {
425387
return []gdns.Zone{{Name: "test.com"}}, nil
426388
},

0 commit comments

Comments
 (0)