2018-07-03 14:44:05 +00:00
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2024-01-09 16:00:07 +00:00
|
|
|
"testing"
|
2018-07-03 14:44:05 +00:00
|
|
|
"time"
|
|
|
|
|
2024-01-09 16:00:07 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/stretchr/testify/suite"
|
2023-02-03 14:24:05 +00:00
|
|
|
"github.com/traefik/traefik/v3/integration/try"
|
2018-07-03 14:44:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type HostResolverSuite struct{ BaseSuite }
|
|
|
|
|
2024-01-09 16:00:07 +00:00
|
|
|
func TestHostResolverSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(HostResolverSuite))
|
2018-07-03 14:44:05 +00:00
|
|
|
}
|
|
|
|
|
2024-01-09 16:00:07 +00:00
|
|
|
func (s *HostResolverSuite) SetupSuite() {
|
|
|
|
s.BaseSuite.SetupSuite()
|
2018-07-03 14:44:05 +00:00
|
|
|
|
2024-01-09 16:00:07 +00:00
|
|
|
s.createComposeProject("hostresolver")
|
|
|
|
s.composeUp()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *HostResolverSuite) TearDownSuite() {
|
|
|
|
s.BaseSuite.TearDownSuite()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *HostResolverSuite) TestSimpleConfig() {
|
|
|
|
s.traefikCmd(withConfigFile("fixtures/simple_hostresolver.toml"))
|
2018-07-03 14:44:05 +00:00
|
|
|
|
|
|
|
testCase := []struct {
|
|
|
|
desc string
|
|
|
|
host string
|
|
|
|
status int
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "host request is resolved",
|
|
|
|
host: "www.github.com",
|
|
|
|
status: http.StatusOK,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "host request is not resolved",
|
|
|
|
host: "frontend.docker.local",
|
|
|
|
status: http.StatusNotFound,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCase {
|
|
|
|
req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8000/", nil)
|
2024-01-09 16:00:07 +00:00
|
|
|
require.NoError(s.T(), err)
|
2018-07-03 14:44:05 +00:00
|
|
|
req.Host = test.host
|
|
|
|
|
2024-01-09 16:00:07 +00:00
|
|
|
err = try.Request(req, 5*time.Second, try.StatusCodeIs(test.status), try.HasBody())
|
|
|
|
require.NoError(s.T(), err)
|
2018-07-03 14:44:05 +00:00
|
|
|
}
|
|
|
|
}
|