traefik/integration/hostresolver_test.go

59 lines
1.2 KiB
Go
Raw Normal View History

2018-07-03 14:44:05 +00:00
package integration
import (
"net/http"
"testing"
2018-07-03 14:44:05 +00:00
"time"
"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 }
func TestHostResolverSuite(t *testing.T) {
suite.Run(t, new(HostResolverSuite))
2018-07-03 14:44:05 +00:00
}
func (s *HostResolverSuite) SetupSuite() {
s.BaseSuite.SetupSuite()
2018-07-03 14:44:05 +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)
require.NoError(s.T(), err)
2018-07-03 14:44:05 +00:00
req.Host = test.host
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
}
}