Stickiness cookie name.

This commit is contained in:
Ludovic Fernandez 2017-10-12 17:50:03 +02:00 committed by Traefiker
parent cba0898e4f
commit 8cb3f0835a
21 changed files with 525 additions and 148 deletions

View file

@ -10,6 +10,7 @@ import (
docker "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/go-connections/nat"
"github.com/stretchr/testify/assert"
)
func TestDockerGetFrontendName(t *testing.T) {
@ -1051,3 +1052,80 @@ func TestDockerLoadDockerConfig(t *testing.T) {
})
}
}
func TestDockerHasStickinessLabel(t *testing.T) {
testCases := []struct {
desc string
container docker.ContainerJSON
expected bool
}{
{
desc: "no sticky/stickiness-label",
container: containerJSON(),
expected: false,
},
{
desc: "sticky true",
container: containerJSON(labels(map[string]string{
types.LabelBackendLoadbalancerSticky: "true",
})),
expected: true,
},
{
desc: "sticky false",
container: containerJSON(labels(map[string]string{
types.LabelBackendLoadbalancerSticky: "false",
})),
expected: false,
},
{
desc: "stickiness true",
container: containerJSON(labels(map[string]string{
types.LabelBackendLoadbalancerStickiness: "true",
})),
expected: true,
},
{
desc: "stickiness false",
container: containerJSON(labels(map[string]string{
types.LabelBackendLoadbalancerStickiness: "false",
})),
expected: false,
},
{
desc: "sticky true + stickiness false",
container: containerJSON(labels(map[string]string{
types.LabelBackendLoadbalancerSticky: "true",
types.LabelBackendLoadbalancerStickiness: "false",
})),
expected: true,
},
{
desc: "sticky false + stickiness true",
container: containerJSON(labels(map[string]string{
types.LabelBackendLoadbalancerSticky: "false",
types.LabelBackendLoadbalancerStickiness: "true",
})),
expected: true,
},
{
desc: "sticky false + stickiness false",
container: containerJSON(labels(map[string]string{
types.LabelBackendLoadbalancerSticky: "false",
types.LabelBackendLoadbalancerStickiness: "false",
})),
expected: false,
},
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
dockerData := parseContainer(test.container)
provider := &Provider{}
actual := provider.hasStickinessLabel(dockerData)
assert.Equal(t, actual, test.expected)
})
}
}