Skip to content

Commit

Permalink
GH-36 integration tests update
Browse files Browse the repository at this point in the history
  • Loading branch information
maksymvavilov committed Apr 4, 2024
1 parent b9f137a commit 65e7936
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
4 changes: 2 additions & 2 deletions internal/controller/dnsrecord_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func (r *DNSRecordReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
}
}
dnsRecord := previous.DeepCopy()
dnsRecord.Status.QueuedAt = reconcileStart

if dnsRecord.DeletionTimestamp != nil && !dnsRecord.DeletionTimestamp.IsZero() {
if err = r.deleteRecord(ctx, dnsRecord); err != nil {
Expand Down Expand Up @@ -326,14 +325,15 @@ func (r *DNSRecordReconciler) applyChanges(ctx context.Context, dnsRecord *v1alp
plan = plan.Calculate()

dnsRecord.Status.ValidFor = defaultRequeueTime.String()
dnsRecord.Status.QueuedAt = reconcileStart
if plan.Changes.HasChanges() {
// generation has not changed but there are changes.
// implies that they were overridden - bump write counter
if !generationChanged(dnsRecord) {
dnsRecord.Status.WriteCounter++
}
dnsRecord.Status.ValidFor = validationRequeueTime.String()
setDNSRecordCondition(dnsRecord, string(v1alpha1.ConditionTypeReady), metav1.ConditionFalse, "Awaiting validation", "Awaiting validation")
setDNSRecordCondition(dnsRecord, string(v1alpha1.ConditionTypeReady), metav1.ConditionFalse, "AwaitingValidation", "Awaiting validation")
logger.Info("Applying changes")
err = registry.ApplyChanges(ctx, plan.Changes)
if err != nil {
Expand Down
15 changes: 1 addition & 14 deletions internal/controller/dnsrecord_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"
externaldnsendpoint "sigs.k8s.io/external-dns/endpoint"

"github.com/kuadrant/dns-operator/api/v1alpha1"
)
Expand All @@ -53,19 +52,7 @@ var _ = Describe("DNSRecordReconciler", func() {
ManagedZoneRef: &v1alpha1.ManagedZoneReference{
Name: managedZone.Name,
},
Endpoints: []*externaldnsendpoint.Endpoint{
{
DNSName: "foo.example.com",
Targets: []string{
"127.0.0.1",
},
RecordType: "A",
SetIdentifier: "",
RecordTTL: 60,
Labels: nil,
ProviderSpecific: nil,
},
},
Endpoints: getTestEndpoints(),
},
}
})
Expand Down
23 changes: 21 additions & 2 deletions internal/controller/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import (
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
externaldnsendpoint "sigs.k8s.io/external-dns/endpoint"

kuadrantdnsv1alpha1 "github.com/kuadrant/dns-operator/api/v1alpha1"
)

const (
TestTimeoutMedium = time.Second * 10
TestTimeoutLong = time.Second * 30
TestTimeoutMedium = time.Second * 20
TestTimeoutLong = time.Second * 60
TestRetryIntervalMedium = time.Millisecond * 250
RequeueDuration = time.Second * 10
ValidityDuration = time.Second * 5
defaultNS = "default"
providerCredential = "secretname"
)
Expand All @@ -34,3 +37,19 @@ func testBuildManagedZone(name, ns, domainName string) *kuadrantdnsv1alpha1.Mana
},
}
}

func getTestEndpoints() []*externaldnsendpoint.Endpoint {
return []*externaldnsendpoint.Endpoint{
{
DNSName: "foo.example.com",
Targets: []string{
"127.0.0.1",
},
RecordType: "A",
SetIdentifier: "",
RecordTTL: 60,
Labels: nil,
ProviderSpecific: nil,
},
}
}
7 changes: 1 addition & 6 deletions internal/controller/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ import (
// These tests use Ginkgo (BDD-style Go testing framework). Refer to
// http://onsi.github.io/ginkgo/ to learn more about Ginkgo.

const (
RequeueDuration = time.Minute * 1
ValidityDuration = time.Second * 30
)

var cfg *rest.Config
var k8sClient client.Client
var testEnv *envtest.Environment
Expand All @@ -67,7 +62,7 @@ var dnsProviderFactory = &providerFake.Factory{
ProviderForFunc: func(ctx context.Context, pa v1alpha1.ProviderAccessor, c provider.Config) (provider.Provider, error) {
return &providerFake.Provider{
RecordsFunc: func(context.Context) ([]*externaldnsendpoint.Endpoint, error) {
return []*externaldnsendpoint.Endpoint{}, nil
return getTestEndpoints(), nil
},
ApplyChangesFunc: func(context.Context, *externaldnsplan.Changes) error {
return nil
Expand Down

0 comments on commit 65e7936

Please sign in to comment.