40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
package nameserver
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/maspend/hostora/internal/store"
|
|
)
|
|
|
|
// v0.4.2: zona harus memakai SELURUH nameserver global, bukan hanya yang
|
|
// ditandai default. Sebelumnya zona dengan ns1 (default) + ns2 (bukan
|
|
// default) hanya mendapat 1 NS record.
|
|
func TestEffectiveNameserversUsesAllGlobal(t *testing.T) {
|
|
global := []store.Nameserver{
|
|
{Hostname: "ns1.hostora.xyz", IPv4: "49.128.189.171", IsDefault: true},
|
|
{Hostname: "ns2.hostora.xyz", IPv4: "49.128.189.171", IsDefault: false},
|
|
}
|
|
eff := EffectiveNameservers("hostora.test", nil, global)
|
|
if len(eff) != 2 {
|
|
t.Fatalf("ingin 2 nameserver efektif, dapat %d: %+v", len(eff), eff)
|
|
}
|
|
if eff[0].Hostname != "ns1.hostora.xyz" || eff[1].Hostname != "ns2.hostora.xyz" {
|
|
t.Fatalf("urutan salah: %+v", eff)
|
|
}
|
|
hosts := ZoneNSHostnames("hostora.test", nil, global)
|
|
if len(hosts) != 2 || hosts[0] != "ns1.hostora.xyz" || hosts[1] != "ns2.hostora.xyz" {
|
|
t.Fatalf("ZoneNSHostnames salah: %v", hosts)
|
|
}
|
|
// SOA MNAME tetap nameserver default pertama.
|
|
if m := SOAMName("hostora.test", eff); m != "ns1.hostora.xyz" {
|
|
t.Fatalf("SOA MNAME salah: %s", m)
|
|
}
|
|
}
|
|
|
|
func TestEffectiveNameserversFallbackWhenEmpty(t *testing.T) {
|
|
eff := EffectiveNameservers("hostora.test", nil, nil)
|
|
if len(eff) == 0 {
|
|
t.Fatal("fallback tidak boleh kosong")
|
|
}
|
|
}
|