mirror of
https://github.com/containous/traefik.git
synced 2025-01-11 05:17:52 +03:00
refactor(ecs): template readability.
This commit is contained in:
parent
7e5c258266
commit
f195ef27f3
@ -12,7 +12,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestBuildConfiguration(t *testing.T) {
|
func TestBuildConfiguration(t *testing.T) {
|
||||||
provider := &Provider{}
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
desc string
|
desc string
|
||||||
services map[string][]ecsInstance
|
services map[string][]ecsInstance
|
||||||
@ -134,6 +133,9 @@ func TestBuildConfiguration(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.desc, func(t *testing.T) {
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
provider := &Provider{}
|
||||||
got, err := provider.buildConfiguration(test.services)
|
got, err := provider.buildConfiguration(test.services)
|
||||||
assert.Equal(t, test.err, err)
|
assert.Equal(t, test.err, err)
|
||||||
assert.Equal(t, test.expected, got)
|
assert.Equal(t, test.expected, got)
|
||||||
@ -317,6 +319,8 @@ func TestChunkedTaskArns(t *testing.T) {
|
|||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
test := test
|
test := test
|
||||||
t.Run(test.desc, func(t *testing.T) {
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
var tasks []*string
|
var tasks []*string
|
||||||
for v := 0; v < test.count; v++ {
|
for v := 0; v < test.count; v++ {
|
||||||
tasks = append(tasks, &testVal)
|
tasks = append(tasks, &testVal)
|
||||||
@ -331,7 +335,6 @@ func TestChunkedTaskArns(t *testing.T) {
|
|||||||
|
|
||||||
assert.Equal(t, test.expectedLengths, outCount, "Chunking %d elements", test.count)
|
assert.Equal(t, test.expectedLengths, outCount, "Chunking %d elements", test.count)
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -352,6 +355,7 @@ func TestGetHost(t *testing.T) {
|
|||||||
test := test
|
test := test
|
||||||
t.Run(test.desc, func(t *testing.T) {
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
actual := getHost(test.instanceInfo)
|
actual := getHost(test.instanceInfo)
|
||||||
assert.Equal(t, test.expected, actual)
|
assert.Equal(t, test.expected, actual)
|
||||||
})
|
})
|
||||||
@ -389,6 +393,7 @@ func TestGetPort(t *testing.T) {
|
|||||||
test := test
|
test := test
|
||||||
t.Run(test.desc, func(t *testing.T) {
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
actual := getPort(test.instanceInfo)
|
actual := getPort(test.instanceInfo)
|
||||||
assert.Equal(t, test.expected, actual)
|
assert.Equal(t, test.expected, actual)
|
||||||
})
|
})
|
||||||
@ -464,6 +469,7 @@ func TestGetFuncSliceString(t *testing.T) {
|
|||||||
test := test
|
test := test
|
||||||
t.Run(test.desc, func(t *testing.T) {
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
actual := getFuncSliceString(label.TraefikFrontendEntryPoints)(test.instanceInfo)
|
actual := getFuncSliceString(label.TraefikFrontendEntryPoints)(test.instanceInfo)
|
||||||
assert.Equal(t, test.expected, actual)
|
assert.Equal(t, test.expected, actual)
|
||||||
})
|
})
|
||||||
|
@ -1,37 +1,47 @@
|
|||||||
[backends]{{range $serviceName, $instances := .Services}}
|
[backends]
|
||||||
[backends.backend-{{ $serviceName }}.loadbalancer]
|
{{range $serviceName, $instances := .Services}}
|
||||||
|
|
||||||
|
[backends.backend-{{ $serviceName }}.loadBalancer]
|
||||||
method = "{{ getLoadBalancerMethod $instances}}"
|
method = "{{ getLoadBalancerMethod $instances}}"
|
||||||
sticky = {{ getSticky $instances}}
|
sticky = {{ getSticky $instances}}
|
||||||
{{if hasStickinessLabel $instances}}
|
{{if hasStickinessLabel $instances}}
|
||||||
[backends.backend-{{ $serviceName }}.loadbalancer.stickiness]
|
[backends.backend-{{ $serviceName }}.loadBalancer.stickiness]
|
||||||
cookieName = "{{getStickinessCookieName $instances}}"
|
cookieName = "{{getStickinessCookieName $instances}}"
|
||||||
{{end}}
|
{{end}}
|
||||||
{{ if hasHealthCheckLabels $instances }}
|
|
||||||
[backends.backend-{{ $serviceName }}.healthcheck]
|
|
||||||
path = "{{getHealthCheckPath $instances }}"
|
|
||||||
interval = "{{getHealthCheckInterval $instances }}"
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{range $index, $i := $instances}}
|
{{ if hasHealthCheckLabels $instances }}
|
||||||
[backends.backend-{{ $i.Name }}.servers.server-{{ $i.Name }}{{ $i.ID }}]
|
[backends.backend-{{ $serviceName }}.healthCheck]
|
||||||
url = "{{ getProtocol $i }}://{{ getHost $i }}:{{ getPort $i }}"
|
path = "{{getHealthCheckPath $instances }}"
|
||||||
weight = {{ getWeight $i}}
|
interval = "{{getHealthCheckInterval $instances }}"
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
{{range $index, $instance := $instances}}
|
||||||
|
[backends.backend-{{ $instance.Name }}.servers.server-{{ $instance.Name }}{{ $instance.ID }}]
|
||||||
|
url = "{{ getProtocol $instance }}://{{ getHost $instance }}:{{ getPort $instance }}"
|
||||||
|
weight = {{ getWeight $instance}}
|
||||||
|
{{end}}
|
||||||
|
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
[frontends]{{range $serviceName, $instances := .Services}}
|
[frontends]
|
||||||
{{range filterFrontends $instances}}
|
{{range $serviceName, $instances := .Services}}
|
||||||
[frontends.frontend-{{ $serviceName }}]
|
{{range filterFrontends $instances}}
|
||||||
backend = "backend-{{ $serviceName }}"
|
|
||||||
passHostHeader = {{ getPassHostHeader .}}
|
[frontends.frontend-{{ $serviceName }}]
|
||||||
priority = {{ getPriority .}}
|
backend = "backend-{{ $serviceName }}"
|
||||||
entryPoints = [{{range getEntryPoints .}}
|
priority = {{ getPriority .}}
|
||||||
|
passHostHeader = {{ getPassHostHeader .}}
|
||||||
|
|
||||||
|
entryPoints = [{{range getEntryPoints .}}
|
||||||
"{{.}}",
|
"{{.}}",
|
||||||
{{end}}]
|
{{end}}]
|
||||||
basicAuth = [{{range getBasicAuth .}}
|
|
||||||
|
basicAuth = [{{range getBasicAuth .}}
|
||||||
"{{.}}",
|
"{{.}}",
|
||||||
{{end}}]
|
{{end}}]
|
||||||
|
|
||||||
[frontends.frontend-{{ $serviceName }}.routes.route-frontend-{{ $serviceName }}]
|
[frontends.frontend-{{ $serviceName }}.routes.route-frontend-{{ $serviceName }}]
|
||||||
rule = "{{getFrontendRule .}}"
|
rule = "{{getFrontendRule .}}"
|
||||||
{{end}}
|
|
||||||
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
Loading…
Reference in New Issue
Block a user