package controller import ( "context" "strings" "testing" bindv1alpha1 "git.unkin.net/unkin/bind-operator/api/v1alpha1" ) // A primary zone with known secondaries renders notify explicit + also-notify // so a dynamic update NOTIFYs the secondaries immediately. func TestBuildZoneConfigPrimaryAlsoNotify(t *testing.T) { r := &BindZoneReconciler{} zone := &bindv1alpha1.BindZone{ Spec: bindv1alpha1.BindZoneSpec{ ZoneName: "main.unkin.net", Type: bindv1alpha1.ZonePrimary, }, } cfg, err := r.buildZoneConfig(context.Background(), zone, "transfer-key", []string{"10.42.2.6", "10.42.1.5"}) if err != nil { t.Fatalf("buildZoneConfig: %v", err) } if !strings.Contains(cfg, "notify explicit") { t.Errorf("expected notify explicit in %q", cfg) } if !strings.Contains(cfg, "also-notify { 10.42.2.6; 10.42.1.5; }") { t.Errorf("expected also-notify with the secondary IPs in %q", cfg) } } // With no secondaries, no also-notify is emitted (single-replica cluster). func TestBuildZoneConfigPrimaryNoNotifyTargets(t *testing.T) { r := &BindZoneReconciler{} zone := &bindv1alpha1.BindZone{ Spec: bindv1alpha1.BindZoneSpec{ZoneName: "main.unkin.net", Type: bindv1alpha1.ZonePrimary}, } cfg, err := r.buildZoneConfig(context.Background(), zone, "transfer-key", nil) if err != nil { t.Fatalf("buildZoneConfig: %v", err) } if strings.Contains(cfg, "also-notify") || strings.Contains(cfg, "notify explicit") { t.Errorf("did not expect notify clauses with no targets: %q", cfg) } }