2018-04-16 16:14:04 +00:00
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
2019-11-14 15:40:05 +00:00
|
|
|
"strings"
|
2024-01-09 16:00:07 +00:00
|
|
|
"testing"
|
2018-04-16 16:14:04 +00:00
|
|
|
"time"
|
|
|
|
|
2024-01-09 16:00:07 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/stretchr/testify/suite"
|
2020-09-16 13:46:04 +00:00
|
|
|
"github.com/traefik/traefik/v2/integration/try"
|
|
|
|
"github.com/traefik/traefik/v2/pkg/api"
|
|
|
|
"github.com/traefik/traefik/v2/pkg/testhelpers"
|
2018-04-16 16:14:04 +00:00
|
|
|
)
|
|
|
|
|
2020-05-11 10:06:07 +00:00
|
|
|
// Docker tests suite.
|
2018-04-16 16:14:04 +00:00
|
|
|
type DockerComposeSuite struct {
|
|
|
|
BaseSuite
|
|
|
|
}
|
|
|
|
|
2024-01-09 16:00:07 +00:00
|
|
|
func TestDockerComposeSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(DockerComposeSuite))
|
2018-04-16 16:14:04 +00:00
|
|
|
}
|
|
|
|
|
2024-01-09 16:00:07 +00:00
|
|
|
func (s *DockerComposeSuite) SetupSuite() {
|
|
|
|
s.BaseSuite.SetupSuite()
|
|
|
|
s.createComposeProject("minimal")
|
|
|
|
s.composeUp()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerComposeSuite) TearDownSuite() {
|
|
|
|
s.BaseSuite.TearDownSuite()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerComposeSuite) TestComposeScale() {
|
2019-01-21 18:06:02 +00:00
|
|
|
tempObjects := struct {
|
|
|
|
DockerHost string
|
|
|
|
DefaultRule string
|
|
|
|
}{
|
|
|
|
DockerHost: s.getDockerHost(),
|
2019-01-30 15:24:07 +00:00
|
|
|
DefaultRule: "Host(`{{ normalize .Name }}.docker.localhost`)",
|
2019-01-21 18:06:02 +00:00
|
|
|
}
|
2024-01-09 16:00:07 +00:00
|
|
|
file := s.adaptFile("fixtures/docker/minimal.toml", tempObjects)
|
2018-04-16 16:14:04 +00:00
|
|
|
|
2024-01-09 16:00:07 +00:00
|
|
|
s.traefikCmd(withConfigFile(file))
|
2018-04-16 16:14:04 +00:00
|
|
|
|
|
|
|
req := testhelpers.MustNewRequest(http.MethodGet, "http://127.0.0.1:8000/whoami", nil)
|
|
|
|
req.Host = "my.super.host"
|
|
|
|
|
2024-01-09 16:00:07 +00:00
|
|
|
_, err := try.ResponseUntilStatusCode(req, 5*time.Second, http.StatusOK)
|
|
|
|
require.NoError(s.T(), err)
|
2018-04-16 16:14:04 +00:00
|
|
|
|
2019-05-16 08:58:06 +00:00
|
|
|
resp, err := http.Get("http://127.0.0.1:8080/api/rawdata")
|
2024-01-09 16:00:07 +00:00
|
|
|
require.NoError(s.T(), err)
|
2018-04-16 16:14:04 +00:00
|
|
|
defer resp.Body.Close()
|
2019-01-18 14:18:04 +00:00
|
|
|
|
2019-05-16 08:58:06 +00:00
|
|
|
var rtconf api.RunTimeRepresentation
|
|
|
|
err = json.NewDecoder(resp.Body).Decode(&rtconf)
|
2024-01-09 16:00:07 +00:00
|
|
|
require.NoError(s.T(), err)
|
2018-04-16 16:14:04 +00:00
|
|
|
|
2019-11-14 15:40:05 +00:00
|
|
|
// check that we have only three routers (the one from this test + 2 unrelated internal ones)
|
2024-01-09 16:00:07 +00:00
|
|
|
assert.Len(s.T(), rtconf.Routers, 3)
|
2019-05-16 08:58:06 +00:00
|
|
|
|
2019-11-14 15:40:05 +00:00
|
|
|
// check that we have only one service (not counting the internal ones) with n servers
|
2019-05-16 08:58:06 +00:00
|
|
|
services := rtconf.Services
|
2024-01-09 16:00:07 +00:00
|
|
|
assert.Len(s.T(), services, 4)
|
2019-11-14 15:40:05 +00:00
|
|
|
for name, service := range services {
|
|
|
|
if strings.HasSuffix(name, "@internal") {
|
|
|
|
continue
|
|
|
|
}
|
2024-01-09 16:00:07 +00:00
|
|
|
assert.Equal(s.T(), "service-mini@docker", name)
|
|
|
|
assert.Len(s.T(), service.LoadBalancer.Servers, 2)
|
2019-05-16 08:58:06 +00:00
|
|
|
// We could break here, but we don't just to keep us honest.
|
|
|
|
}
|
2018-04-16 16:14:04 +00:00
|
|
|
}
|