2019-03-11 16:56:48 +00:00
|
|
|
package dns01
|
2018-12-06 21:50:17 +00: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 19:49:40 +00:00
|
|
|
domain: "foo.example.com",
|
|
|
|
expected: "foo.example.com.",
|
2018-12-06 21:50:17 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "already FQDN",
|
2024-02-24 19:49:40 +00:00
|
|
|
domain: "foo.example.com.",
|
|
|
|
expected: "foo.example.com.",
|
2018-12-06 21:50:17 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
test := test
|
|
|
|
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 19:49:40 +00:00
|
|
|
fqdn: "foo.example.",
|
|
|
|
expected: "foo.example",
|
2018-12-06 21:50:17 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "already domain",
|
2024-02-24 19:49:40 +00:00
|
|
|
fqdn: "foo.example",
|
|
|
|
expected: "foo.example",
|
2018-12-06 21:50:17 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
test := test
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
domain := UnFqdn(test.fqdn)
|
|
|
|
|
|
|
|
assert.Equal(t, test.expected, domain)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|