mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-20 08:00:30 +08:00
62 lines
1.2 KiB
Go
62 lines
1.2 KiB
Go
|
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||
|
|
|
||
|
|
package domainutils
|
||
|
|
|
||
|
|
import (
|
||
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
||
|
|
"github.com/iwind/TeaGo/assert"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestValidateRecordValue(t *testing.T) {
|
||
|
|
a := assert.NewAssertion(t)
|
||
|
|
|
||
|
|
// A
|
||
|
|
{
|
||
|
|
_, ok := ValidateRecordValue(dnsconfigs.RecordTypeA, "1.2")
|
||
|
|
a.IsFalse(ok)
|
||
|
|
}
|
||
|
|
{
|
||
|
|
_, ok := ValidateRecordValue(dnsconfigs.RecordTypeA, "1.2.3.400")
|
||
|
|
a.IsFalse(ok)
|
||
|
|
}
|
||
|
|
{
|
||
|
|
_, ok := ValidateRecordValue(dnsconfigs.RecordTypeA, "1.2.3.4")
|
||
|
|
a.IsTrue(ok)
|
||
|
|
}
|
||
|
|
|
||
|
|
// CNAME
|
||
|
|
{
|
||
|
|
_, ok := ValidateRecordValue(dnsconfigs.RecordTypeCNAME, "example.com")
|
||
|
|
a.IsTrue(ok)
|
||
|
|
}
|
||
|
|
{
|
||
|
|
_, ok := ValidateRecordValue(dnsconfigs.RecordTypeCNAME, "example.com.")
|
||
|
|
a.IsTrue(ok)
|
||
|
|
}
|
||
|
|
{
|
||
|
|
_, ok := ValidateRecordValue(dnsconfigs.RecordTypeCNAME, "hello, world")
|
||
|
|
a.IsFalse(ok)
|
||
|
|
}
|
||
|
|
|
||
|
|
// AAAA
|
||
|
|
{
|
||
|
|
_, ok := ValidateRecordValue(dnsconfigs.RecordTypeAAAA, "1.2.3.4")
|
||
|
|
a.IsFalse(ok)
|
||
|
|
}
|
||
|
|
{
|
||
|
|
_, ok := ValidateRecordValue(dnsconfigs.RecordTypeAAAA, "2001:0db8:85a3:0000:0000:8a2e:0370:7334")
|
||
|
|
a.IsTrue(ok)
|
||
|
|
}
|
||
|
|
|
||
|
|
// NS
|
||
|
|
{
|
||
|
|
_, ok := ValidateRecordValue(dnsconfigs.RecordTypeNS, "1.2.3.4")
|
||
|
|
a.IsFalse(ok)
|
||
|
|
}
|
||
|
|
{
|
||
|
|
_, ok := ValidateRecordValue(dnsconfigs.RecordTypeNS, "example.com")
|
||
|
|
a.IsTrue(ok)
|
||
|
|
}
|
||
|
|
}
|