added dns unit tests

This commit is contained in:
Kwitsch 2024-04-17 18:57:10 +00:00
parent 46441bafa1
commit f28e58c689
1 changed files with 37 additions and 0 deletions

37
util/dns_test.go Normal file
View File

@ -0,0 +1,37 @@
package util
import (
"math"
"time"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("EDNS0 utils", func() {
DescribeTable("ToTTL",
func(input interface{}, expected int) {
res := uint32(0)
switch it := input.(type) {
case uint32:
res = ToTTL(it)
case int:
res = ToTTL(it)
case int64:
res = ToTTL(it)
case time.Duration:
res = ToTTL(it)
default:
Fail("unsupported type")
}
Expect(ToTTL(res)).Should(Equal(uint32(expected)))
},
Entry("should return 0 for negative input", -1, 0),
Entry("should return uint32 for uint32 input", uint32(1), 1),
Entry("should return uint32 for int input", 1, 1),
Entry("should return uint32 for int64 input", int64(1), 1),
Entry("should return seconds for time.Duration input", time.Second, 1),
Entry("should return math.MaxUint32 for too large input", int64(math.MaxUint32)+1, math.MaxUint32),
)
})