Add unit tests for upserting existing TXT records

This commit is contained in:
Christoph Petrausch 2022-09-28 09:44:08 +02:00
parent b1e6627a3e
commit e52431f9ca
2 changed files with 19 additions and 15 deletions

View File

@ -415,6 +415,10 @@ func (p designateProvider) ApplyChanges(ctx context.Context, changes *plan.Chang
}
endpoints, err := p.Records(ctx)
if err != nil {
return fmt.Errorf("failed to fetch active records: %w", err)
}
recordSets := map[string]*recordSet{}
for _, ep := range changes.Create {
addEndpoint(ep, recordSets, endpoints, false)
@ -429,9 +433,6 @@ func (p designateProvider) ApplyChanges(ctx context.Context, changes *plan.Chang
addEndpoint(ep, recordSets, endpoints, true)
}
if err != nil {
return fmt.Errorf("failed to fetch active records: %w", err)
}
for _, rs := range recordSets {
if err2 := p.upsertRecordSet(rs, managedZones); err == nil {
err = err2

View File

@ -275,17 +275,7 @@ func TestDesignateRecords(t *testing.T) {
{
DNSName: "srv.test.net",
RecordType: endpoint.RecordTypeA,
Targets: endpoint.Targets{"10.2.1.1"},
Labels: map[string]string{
designateRecordSetID: rs21ID,
designateZoneID: zone2ID,
designateOriginalRecords: "10.2.1.1\00010.2.1.2",
},
},
{
DNSName: "srv.test.net",
RecordType: endpoint.RecordTypeA,
Targets: endpoint.Targets{"10.2.1.2"},
Targets: endpoint.Targets{"10.2.1.1", "10.2.1.2"},
Labels: map[string]string{
designateRecordSetID: rs21ID,
designateZoneID: zone2ID,
@ -337,6 +327,19 @@ func testDesignateCreateRecords(t *testing.T, client *fakeDesignateClient) []*re
Status: "ACTIVE",
})
}
_, err := client.CreateRecordSet("zone-1", recordsets.CreateOpts{
Name: "www.example.com.",
Description: "",
Records: []string{"foo"},
TTL: 60,
Type: endpoint.RecordTypeTXT,
})
if err != nil {
t.Fatal("failed to prefil records")
}
endpoints := []*endpoint.Endpoint{
{
DNSName: "www.example.com",
@ -410,7 +413,7 @@ func testDesignateCreateRecords(t *testing.T, client *fakeDesignateClient) []*re
expectedCopy := make([]*recordsets.RecordSet, len(expected))
copy(expectedCopy, expected)
err := client.ToProvider().ApplyChanges(context.Background(), &plan.Changes{Create: endpoints})
err = client.ToProvider().ApplyChanges(context.Background(), &plan.Changes{Create: endpoints})
if err != nil {
t.Fatal(err)
}