1
0
mirror of https://github.com/containous/traefik.git synced 2025-11-16 04:23:54 +03:00
Files
traefik/pkg/middlewares/requestdecorator/hostresolver_test.go
Kevin Pollet cd16321dd9 Bump to go1.24
Co-authored-by: Romain <rtribotte@users.noreply.github.com>
2025-06-02 10:36:05 +02:00

50 lines
1.0 KiB
Go

package requestdecorator
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCNAMEFlatten(t *testing.T) {
testCases := []struct {
desc string
resolvFile string
domain string
expectedDomain string
}{
{
desc: "host request is CNAME record",
resolvFile: "/etc/resolv.conf",
domain: "www.github.com",
expectedDomain: "github.com",
},
{
desc: "resolve file not found",
resolvFile: "/etc/resolv.oops",
domain: "www.github.com",
expectedDomain: "www.github.com",
},
{
desc: "host request is not CNAME record",
resolvFile: "/etc/resolv.conf",
domain: "github.com",
expectedDomain: "github.com",
},
}
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
hostResolver := &Resolver{
ResolvConfig: test.resolvFile,
ResolvDepth: 5,
}
flatH := hostResolver.CNAMEFlatten(t.Context(), test.domain)
assert.Equal(t, test.expectedDomain, flatH)
})
}
}