update-ip/label_test.go
2024-07-24 15:38:56 +02:00

92 lines
1.3 KiB
Go

package updateip
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCompressLabel(t *testing.T) {
testCases := []struct {
desc string
domain, record string
expected string
}{
{
"same",
"example.org",
"example.org",
"@",
},
{
"same_fqdn",
"example.org.",
"example.org",
"@",
},
{
"simple",
"example.org",
"www.example.org",
"www",
},
{
"unrelated",
"example.org",
"example.net",
"example.net",
},
}
for _, test := range testCases {
t.Run(test.desc, func(it *testing.T) {
it.Parallel()
result := CompressLabel(test.domain, test.record)
assert.Equal(it, test.expected, result)
})
}
}
func TestExpandLabel(t *testing.T) {
testCases := []struct {
desc string
domain, record string
expected string
}{
{
"same",
"example.org",
"@",
"example.org",
},
{
"simple",
"example.org",
"www",
"www.example.org",
},
{
"unrelated",
"example.org",
"example.net",
"example.net.example.org",
},
{
"using_at",
"example.org",
"www.@",
"www.example.org",
},
}
for _, test := range testCases {
t.Run(test.desc, func(it *testing.T) {
it.Parallel()
result := ExapandLabel(test.domain, test.record)
assert.Equal(it, test.expected, result)
})
}
}