Segment labels: Docker
This commit is contained in:
parent
c762b9bb2e
commit
4802484729
28 changed files with 4095 additions and 2464 deletions
|
@ -331,7 +331,7 @@ func TestSwarmBuildConfiguration(t *testing.T) {
|
|||
SwarmMode: true,
|
||||
}
|
||||
|
||||
actualConfig := provider.buildConfiguration(dockerDataList)
|
||||
actualConfig := provider.buildConfigurationV2(dockerDataList)
|
||||
require.NotNil(t, actualConfig, "actualConfig")
|
||||
|
||||
assert.EqualValues(t, test.expectedBackends, actualConfig.Backends)
|
||||
|
@ -465,7 +465,11 @@ func TestSwarmTraefikFilter(t *testing.T) {
|
|||
test := test
|
||||
t.Run(strconv.Itoa(serviceID), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
dData := parseService(test.service, test.networks)
|
||||
segmentProperties := label.ExtractTraefikLabels(dData.Labels)
|
||||
dData.SegmentLabels = segmentProperties[""]
|
||||
|
||||
actual := test.provider.containerFilter(dData)
|
||||
if actual != test.expected {
|
||||
t.Errorf("expected %v for %+v, got %+v", test.expected, test, actual)
|
||||
|
@ -474,47 +478,6 @@ func TestSwarmTraefikFilter(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestSwarmGetFuncStringLabel(t *testing.T) {
|
||||
testCases := []struct {
|
||||
service swarm.Service
|
||||
labelName string
|
||||
defaultValue string
|
||||
networks map[string]*docker.NetworkResource
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
service: swarmService(),
|
||||
labelName: label.TraefikWeight,
|
||||
defaultValue: label.DefaultWeight,
|
||||
networks: map[string]*docker.NetworkResource{},
|
||||
expected: "0",
|
||||
},
|
||||
{
|
||||
service: swarmService(serviceLabels(map[string]string{
|
||||
label.TraefikWeight: "10",
|
||||
})),
|
||||
labelName: label.TraefikWeight,
|
||||
defaultValue: label.DefaultWeight,
|
||||
networks: map[string]*docker.NetworkResource{},
|
||||
expected: "10",
|
||||
},
|
||||
}
|
||||
|
||||
for serviceID, test := range testCases {
|
||||
test := test
|
||||
t.Run(test.labelName+strconv.Itoa(serviceID), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
dData := parseService(test.service, test.networks)
|
||||
|
||||
actual := getFuncStringLabel(test.labelName, test.defaultValue)(dData)
|
||||
if actual != test.expected {
|
||||
t.Errorf("got %q, expected %q", actual, test.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSwarmGetFrontendName(t *testing.T) {
|
||||
testCases := []struct {
|
||||
service swarm.Service
|
||||
|
@ -563,15 +526,18 @@ func TestSwarmGetFrontendName(t *testing.T) {
|
|||
test := test
|
||||
t.Run(strconv.Itoa(serviceID), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
dData := parseService(test.service, test.networks)
|
||||
segmentProperties := label.ExtractTraefikLabels(dData.Labels)
|
||||
dData.SegmentLabels = segmentProperties[""]
|
||||
|
||||
provider := &Provider{
|
||||
Domain: "docker.localhost",
|
||||
SwarmMode: true,
|
||||
}
|
||||
|
||||
actual := provider.getFrontendName(dData, 0)
|
||||
if actual != test.expected {
|
||||
t.Errorf("expected %q, got %q", test.expected, actual)
|
||||
}
|
||||
assert.Equal(t, test.expected, actual)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -612,15 +578,18 @@ func TestSwarmGetFrontendRule(t *testing.T) {
|
|||
test := test
|
||||
t.Run(strconv.Itoa(serviceID), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
dData := parseService(test.service, test.networks)
|
||||
segmentProperties := label.ExtractTraefikLabels(dData.Labels)
|
||||
dData.SegmentLabels = segmentProperties[""]
|
||||
|
||||
provider := &Provider{
|
||||
Domain: "docker.localhost",
|
||||
SwarmMode: true,
|
||||
}
|
||||
|
||||
actual := provider.getFrontendRule(dData)
|
||||
if actual != test.expected {
|
||||
t.Errorf("expected %q, got %q", test.expected, actual)
|
||||
}
|
||||
assert.Equal(t, test.expected, actual)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -654,11 +623,13 @@ func TestSwarmGetBackendName(t *testing.T) {
|
|||
test := test
|
||||
t.Run(strconv.Itoa(serviceID), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
dData := parseService(test.service, test.networks)
|
||||
segmentProperties := label.ExtractTraefikLabels(dData.Labels)
|
||||
dData.SegmentLabels = segmentProperties[""]
|
||||
|
||||
actual := getBackendName(dData)
|
||||
if actual != test.expected {
|
||||
t.Errorf("expected %q, got %q", test.expected, actual)
|
||||
}
|
||||
assert.Equal(t, test.expected, actual)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -713,14 +684,17 @@ func TestSwarmGetIPAddress(t *testing.T) {
|
|||
test := test
|
||||
t.Run(strconv.Itoa(serviceID), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
dData := parseService(test.service, test.networks)
|
||||
|
||||
provider := &Provider{
|
||||
SwarmMode: true,
|
||||
}
|
||||
|
||||
dData := parseService(test.service, test.networks)
|
||||
segmentProperties := label.ExtractTraefikLabels(dData.Labels)
|
||||
dData.SegmentLabels = segmentProperties[""]
|
||||
|
||||
actual := provider.getIPAddress(dData)
|
||||
if actual != test.expected {
|
||||
t.Errorf("expected %q, got %q", test.expected, actual)
|
||||
}
|
||||
assert.Equal(t, test.expected, actual)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -747,11 +721,13 @@ func TestSwarmGetPort(t *testing.T) {
|
|||
test := test
|
||||
t.Run(strconv.Itoa(serviceID), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
dData := parseService(test.service, test.networks)
|
||||
segmentProperties := label.ExtractTraefikLabels(dData.Labels)
|
||||
dData.SegmentLabels = segmentProperties[""]
|
||||
|
||||
actual := getPort(dData)
|
||||
if actual != test.expected {
|
||||
t.Errorf("expected %q, got %q", test.expected, actual)
|
||||
}
|
||||
assert.Equal(t, test.expected, actual)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue