2019-03-11 18:56:48 +02:00
|
|
|
package dns01
|
2018-12-06 23:50:17 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestToFqdn(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
desc string
|
|
|
|
domain string
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "simple",
|
2024-02-24 21:49:40 +02:00
|
|
|
domain: "foo.example.com",
|
|
|
|
expected: "foo.example.com.",
|
2018-12-06 23:50:17 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "already FQDN",
|
2024-02-24 21:49:40 +02:00
|
|
|
domain: "foo.example.com.",
|
|
|
|
expected: "foo.example.com.",
|
2018-12-06 23:50:17 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
fqdn := ToFqdn(test.domain)
|
|
|
|
assert.Equal(t, test.expected, fqdn)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUnFqdn(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
desc string
|
|
|
|
fqdn string
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "simple",
|
2024-02-24 21:49:40 +02:00
|
|
|
fqdn: "foo.example.",
|
|
|
|
expected: "foo.example",
|
2018-12-06 23:50:17 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "already domain",
|
2024-02-24 21:49:40 +02:00
|
|
|
fqdn: "foo.example",
|
|
|
|
expected: "foo.example",
|
2018-12-06 23:50:17 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
domain := UnFqdn(test.fqdn)
|
|
|
|
|
|
|
|
assert.Equal(t, test.expected, domain)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|