2017-04-17 10:50:02 +00:00
|
|
|
package rancher
|
2017-02-05 23:58:05 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
2017-04-29 19:37:54 +00:00
|
|
|
|
|
|
|
"github.com/containous/traefik/types"
|
2017-02-05 23:58:05 +00:00
|
|
|
)
|
|
|
|
|
2017-04-29 19:37:54 +00:00
|
|
|
func TestRancherServiceFilter(t *testing.T) {
|
|
|
|
provider := &Provider{
|
|
|
|
Domain: "rancher.localhost",
|
|
|
|
EnableServiceHealthFilter: true,
|
|
|
|
}
|
|
|
|
|
2017-05-02 14:51:02 +00:00
|
|
|
constraint, _ := types.NewConstraint("tag==ch*se")
|
|
|
|
provider.Constraints = types.Constraints{constraint}
|
|
|
|
|
2017-04-29 19:37:54 +00:00
|
|
|
services := []struct {
|
|
|
|
service rancherData
|
|
|
|
expected bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Labels: map[string]string{
|
2017-07-10 14:58:12 +00:00
|
|
|
types.LabelEnable: "true",
|
2017-04-29 19:37:54 +00:00
|
|
|
},
|
|
|
|
Health: "healthy",
|
|
|
|
State: "active",
|
|
|
|
},
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Labels: map[string]string{
|
2017-07-10 14:58:12 +00:00
|
|
|
types.LabelPort: "80",
|
|
|
|
types.LabelEnable: "false",
|
2017-04-29 19:37:54 +00:00
|
|
|
},
|
|
|
|
Health: "healthy",
|
|
|
|
State: "active",
|
|
|
|
},
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Labels: map[string]string{
|
2017-07-10 14:58:12 +00:00
|
|
|
types.LabelPort: "80",
|
|
|
|
types.LabelEnable: "true",
|
2017-04-29 19:37:54 +00:00
|
|
|
},
|
|
|
|
Health: "unhealthy",
|
|
|
|
State: "active",
|
|
|
|
},
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Labels: map[string]string{
|
2017-07-10 14:58:12 +00:00
|
|
|
types.LabelTags: "not-cheesy",
|
|
|
|
types.LabelPort: "80",
|
|
|
|
types.LabelEnable: "true",
|
2017-04-29 19:37:54 +00:00
|
|
|
},
|
|
|
|
Health: "healthy",
|
|
|
|
State: "inactive",
|
|
|
|
},
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Labels: map[string]string{
|
2017-07-10 14:58:12 +00:00
|
|
|
types.LabelTags: "cheese",
|
|
|
|
types.LabelPort: "80",
|
|
|
|
types.LabelEnable: "true",
|
2017-04-29 19:37:54 +00:00
|
|
|
},
|
|
|
|
Health: "healthy",
|
|
|
|
State: "active",
|
|
|
|
},
|
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Labels: map[string]string{
|
2017-07-10 14:58:12 +00:00
|
|
|
types.LabelTags: "cheeeeese",
|
|
|
|
types.LabelPort: "80",
|
|
|
|
types.LabelEnable: "true",
|
2017-04-29 19:37:54 +00:00
|
|
|
},
|
|
|
|
Health: "healthy",
|
|
|
|
State: "upgraded",
|
|
|
|
},
|
|
|
|
expected: true,
|
|
|
|
},
|
2017-05-02 14:51:02 +00:00
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Labels: map[string]string{
|
2017-07-10 14:58:12 +00:00
|
|
|
types.LabelTags: "chose",
|
|
|
|
types.LabelPort: "80",
|
|
|
|
types.LabelEnable: "true",
|
2017-05-02 14:51:02 +00:00
|
|
|
},
|
|
|
|
Health: "healthy",
|
|
|
|
State: "active",
|
|
|
|
},
|
|
|
|
expected: true,
|
|
|
|
},
|
2017-04-29 19:37:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, e := range services {
|
|
|
|
actual := provider.serviceFilter(e.service)
|
|
|
|
if actual != e.expected {
|
|
|
|
t.Fatalf("expected %t, got %t", e.expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRancherContainerFilter(t *testing.T) {
|
|
|
|
containers := []struct {
|
2017-05-08 01:20:38 +00:00
|
|
|
name string
|
|
|
|
healthState string
|
|
|
|
state string
|
|
|
|
expected bool
|
2017-04-29 19:37:54 +00:00
|
|
|
}{
|
|
|
|
{
|
2017-05-08 01:20:38 +00:00
|
|
|
healthState: "unhealthy",
|
|
|
|
state: "running",
|
|
|
|
expected: false,
|
2017-04-29 19:37:54 +00:00
|
|
|
},
|
|
|
|
{
|
2017-05-08 01:20:38 +00:00
|
|
|
healthState: "healthy",
|
|
|
|
state: "stopped",
|
|
|
|
expected: false,
|
2017-04-29 19:37:54 +00:00
|
|
|
},
|
|
|
|
{
|
2017-05-08 01:20:38 +00:00
|
|
|
state: "stopped",
|
2017-04-29 19:37:54 +00:00
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
2017-05-08 01:20:38 +00:00
|
|
|
healthState: "healthy",
|
|
|
|
state: "running",
|
|
|
|
expected: true,
|
2017-04-29 19:37:54 +00:00
|
|
|
},
|
|
|
|
{
|
2017-05-08 01:20:38 +00:00
|
|
|
healthState: "updating-healthy",
|
|
|
|
state: "updating-running",
|
|
|
|
expected: true,
|
2017-04-29 19:37:54 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-05-08 01:20:38 +00:00
|
|
|
for _, container := range containers {
|
|
|
|
actual := containerFilter(container.name, container.healthState, container.state)
|
|
|
|
if actual != container.expected {
|
|
|
|
t.Fatalf("expected %t, got %t", container.expected, actual)
|
2017-04-29 19:37:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-05 23:58:05 +00:00
|
|
|
func TestRancherGetFrontendName(t *testing.T) {
|
2017-04-17 10:50:02 +00:00
|
|
|
provider := &Provider{
|
2017-02-05 23:58:05 +00:00
|
|
|
Domain: "rancher.localhost",
|
|
|
|
}
|
|
|
|
|
|
|
|
services := []struct {
|
|
|
|
service rancherData
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Name: "foo",
|
|
|
|
},
|
|
|
|
expected: "Host-foo-rancher-localhost",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Name: "test-service",
|
|
|
|
Labels: map[string]string{
|
2017-07-10 14:58:12 +00:00
|
|
|
types.LabelFrontendRule: "Headers:User-Agent,bat/0.1.0",
|
2017-02-05 23:58:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
expected: "Headers-User-Agent-bat-0-1-0",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Name: "test-service",
|
|
|
|
Labels: map[string]string{
|
2017-07-10 14:58:12 +00:00
|
|
|
types.LabelFrontendRule: "Host:foo.bar",
|
2017-02-05 23:58:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
expected: "Host-foo-bar",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Name: "test-service",
|
|
|
|
Labels: map[string]string{
|
2017-07-10 14:58:12 +00:00
|
|
|
types.LabelFrontendRule: "Path:/test",
|
2017-02-05 23:58:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
expected: "Path-test",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Name: "test-service",
|
|
|
|
Labels: map[string]string{
|
2017-07-10 14:58:12 +00:00
|
|
|
types.LabelFrontendRule: "PathPrefix:/test2",
|
2017-02-05 23:58:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
expected: "PathPrefix-test2",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, e := range services {
|
|
|
|
actual := provider.getFrontendName(e.service)
|
|
|
|
if actual != e.expected {
|
|
|
|
t.Fatalf("expected %q, got %q", e.expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRancherGetFrontendRule(t *testing.T) {
|
2017-04-17 10:50:02 +00:00
|
|
|
provider := &Provider{
|
2017-02-05 23:58:05 +00:00
|
|
|
Domain: "rancher.localhost",
|
|
|
|
}
|
|
|
|
|
|
|
|
services := []struct {
|
|
|
|
service rancherData
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Name: "foo",
|
|
|
|
},
|
|
|
|
expected: "Host:foo.rancher.localhost",
|
|
|
|
},
|
2017-02-20 19:41:28 +00:00
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Name: "foo/bar",
|
|
|
|
},
|
|
|
|
expected: "Host:foo.bar.rancher.localhost",
|
|
|
|
},
|
2017-02-05 23:58:05 +00:00
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Name: "test-service",
|
|
|
|
Labels: map[string]string{
|
2017-07-10 14:58:12 +00:00
|
|
|
types.LabelFrontendRule: "Host:foo.bar.com",
|
2017-02-05 23:58:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
expected: "Host:foo.bar.com",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Name: "test-service",
|
|
|
|
Labels: map[string]string{
|
2017-07-10 14:58:12 +00:00
|
|
|
types.LabelFrontendRule: "Path:/test",
|
2017-02-05 23:58:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
expected: "Path:/test",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Name: "test-service",
|
|
|
|
Labels: map[string]string{
|
2017-07-10 14:58:12 +00:00
|
|
|
types.LabelFrontendRule: "PathPrefix:/test2",
|
2017-02-05 23:58:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
expected: "PathPrefix:/test2",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, e := range services {
|
|
|
|
actual := provider.getFrontendRule(e.service)
|
|
|
|
if actual != e.expected {
|
|
|
|
t.Fatalf("expected %q, got %q", e.expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRancherGetBackend(t *testing.T) {
|
2017-04-17 10:50:02 +00:00
|
|
|
provider := &Provider{
|
2017-02-05 23:58:05 +00:00
|
|
|
Domain: "rancher.localhost",
|
|
|
|
}
|
|
|
|
|
|
|
|
services := []struct {
|
|
|
|
service rancherData
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Name: "test-service",
|
|
|
|
},
|
|
|
|
expected: "test-service",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Name: "test-service",
|
|
|
|
Labels: map[string]string{
|
2017-07-10 14:58:12 +00:00
|
|
|
types.LabelBackend: "foobar",
|
2017-02-05 23:58:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
expected: "foobar",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, e := range services {
|
|
|
|
actual := provider.getBackend(e.service)
|
|
|
|
if actual != e.expected {
|
|
|
|
t.Fatalf("expected %q, got %q", e.expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRancherGetWeight(t *testing.T) {
|
2017-04-17 10:50:02 +00:00
|
|
|
provider := &Provider{
|
2017-02-05 23:58:05 +00:00
|
|
|
Domain: "rancher.localhost",
|
|
|
|
}
|
|
|
|
|
|
|
|
services := []struct {
|
|
|
|
service rancherData
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Name: "test-service",
|
|
|
|
},
|
|
|
|
expected: "0",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Name: "test-service",
|
|
|
|
Labels: map[string]string{
|
2017-07-10 14:58:12 +00:00
|
|
|
types.LabelWeight: "5",
|
2017-02-05 23:58:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
expected: "5",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, e := range services {
|
|
|
|
actual := provider.getWeight(e.service)
|
|
|
|
if actual != e.expected {
|
|
|
|
t.Fatalf("expected %q, got %q", e.expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRancherGetPort(t *testing.T) {
|
2017-04-17 10:50:02 +00:00
|
|
|
provider := &Provider{
|
2017-02-05 23:58:05 +00:00
|
|
|
Domain: "rancher.localhost",
|
|
|
|
}
|
|
|
|
|
|
|
|
services := []struct {
|
|
|
|
service rancherData
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Name: "test-service",
|
|
|
|
},
|
|
|
|
expected: "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Name: "test-service",
|
|
|
|
Labels: map[string]string{
|
2017-07-10 14:58:12 +00:00
|
|
|
types.LabelPort: "1337",
|
2017-02-05 23:58:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
expected: "1337",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, e := range services {
|
|
|
|
actual := provider.getPort(e.service)
|
|
|
|
if actual != e.expected {
|
|
|
|
t.Fatalf("expected %q, got %q", e.expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRancherGetDomain(t *testing.T) {
|
2017-04-17 10:50:02 +00:00
|
|
|
provider := &Provider{
|
2017-02-05 23:58:05 +00:00
|
|
|
Domain: "rancher.localhost",
|
|
|
|
}
|
|
|
|
|
|
|
|
services := []struct {
|
|
|
|
service rancherData
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Name: "test-service",
|
|
|
|
},
|
|
|
|
expected: "rancher.localhost",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Name: "test-service",
|
|
|
|
Labels: map[string]string{
|
2017-07-10 14:58:12 +00:00
|
|
|
types.LabelDomain: "foo.bar",
|
2017-02-05 23:58:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
expected: "foo.bar",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, e := range services {
|
|
|
|
actual := provider.getDomain(e.service)
|
|
|
|
if actual != e.expected {
|
|
|
|
t.Fatalf("expected %q, got %q", e.expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRancherGetProtocol(t *testing.T) {
|
2017-04-17 10:50:02 +00:00
|
|
|
provider := &Provider{
|
2017-02-05 23:58:05 +00:00
|
|
|
Domain: "rancher.localhost",
|
|
|
|
}
|
|
|
|
|
|
|
|
services := []struct {
|
|
|
|
service rancherData
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Name: "test-service",
|
|
|
|
},
|
|
|
|
expected: "http",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Name: "test-service",
|
|
|
|
Labels: map[string]string{
|
2017-07-10 14:58:12 +00:00
|
|
|
types.LabelProtocol: "https",
|
2017-02-05 23:58:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
expected: "https",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, e := range services {
|
|
|
|
actual := provider.getProtocol(e.service)
|
|
|
|
if actual != e.expected {
|
|
|
|
t.Fatalf("expected %q, got %q", e.expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRancherGetPassHostHeader(t *testing.T) {
|
2017-04-17 10:50:02 +00:00
|
|
|
provider := &Provider{
|
2017-02-05 23:58:05 +00:00
|
|
|
Domain: "rancher.localhost",
|
|
|
|
}
|
|
|
|
|
|
|
|
services := []struct {
|
|
|
|
service rancherData
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Name: "test-service",
|
|
|
|
},
|
|
|
|
expected: "true",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Name: "test-service",
|
|
|
|
Labels: map[string]string{
|
2017-07-10 14:58:12 +00:00
|
|
|
types.LabelFrontendPassHostHeader: "false",
|
2017-02-05 23:58:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
expected: "false",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, e := range services {
|
|
|
|
actual := provider.getPassHostHeader(e.service)
|
|
|
|
if actual != e.expected {
|
|
|
|
t.Fatalf("expected %q, got %q", e.expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRancherGetLabel(t *testing.T) {
|
|
|
|
services := []struct {
|
|
|
|
service rancherData
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Name: "test-service",
|
|
|
|
},
|
2017-05-08 01:20:38 +00:00
|
|
|
expected: "label not found",
|
2017-02-05 23:58:05 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
service: rancherData{
|
|
|
|
Name: "test-service",
|
|
|
|
Labels: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
expected: "",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, e := range services {
|
|
|
|
label, err := getServiceLabel(e.service, "foo")
|
|
|
|
if e.expected != "" {
|
|
|
|
if err == nil || !strings.Contains(err.Error(), e.expected) {
|
|
|
|
t.Fatalf("expected an error with %q, got %v", e.expected, err)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if label != "bar" {
|
|
|
|
t.Fatalf("expected label 'bar', got %s", label)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRancherLoadRancherConfig(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
services []rancherData
|
|
|
|
expectedFrontends map[string]*types.Frontend
|
|
|
|
expectedBackends map[string]*types.Backend
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
services: []rancherData{},
|
|
|
|
expectedFrontends: map[string]*types.Frontend{},
|
|
|
|
expectedBackends: map[string]*types.Backend{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
services: []rancherData{
|
|
|
|
{
|
2017-02-20 19:41:28 +00:00
|
|
|
Name: "test/service",
|
2017-02-05 23:58:05 +00:00
|
|
|
Labels: map[string]string{
|
2017-07-10 14:58:12 +00:00
|
|
|
types.LabelPort: "80",
|
|
|
|
types.LabelFrontendAuthBasic: "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/,test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0",
|
2017-02-05 23:58:05 +00:00
|
|
|
},
|
|
|
|
Health: "healthy",
|
|
|
|
Containers: []string{"127.0.0.1"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectedFrontends: map[string]*types.Frontend{
|
|
|
|
"frontend-Host-test-service-rancher-localhost": {
|
|
|
|
Backend: "backend-test-service",
|
|
|
|
PassHostHeader: true,
|
|
|
|
EntryPoints: []string{},
|
2017-04-19 09:14:05 +00:00
|
|
|
BasicAuth: []string{"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/", "test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0"},
|
2017-02-05 23:58:05 +00:00
|
|
|
Priority: 0,
|
|
|
|
|
|
|
|
Routes: map[string]types.Route{
|
|
|
|
"route-frontend-Host-test-service-rancher-localhost": {
|
2017-02-20 19:41:28 +00:00
|
|
|
Rule: "Host:test.service.rancher.localhost",
|
2017-02-05 23:58:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectedBackends: map[string]*types.Backend{
|
|
|
|
"backend-test-service": {
|
|
|
|
Servers: map[string]types.Server{
|
|
|
|
"server-0": {
|
|
|
|
URL: "http://127.0.0.1:80",
|
|
|
|
Weight: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
CircuitBreaker: nil,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-04-17 10:50:02 +00:00
|
|
|
provider := &Provider{
|
2017-02-05 23:58:05 +00:00
|
|
|
Domain: "rancher.localhost",
|
|
|
|
ExposedByDefault: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range cases {
|
|
|
|
var rancherDataList []rancherData
|
2017-05-08 01:20:38 +00:00
|
|
|
rancherDataList = append(rancherDataList, c.services...)
|
2017-02-05 23:58:05 +00:00
|
|
|
|
|
|
|
actualConfig := provider.loadRancherConfig(rancherDataList)
|
|
|
|
|
|
|
|
// Compare backends
|
|
|
|
if !reflect.DeepEqual(actualConfig.Backends, c.expectedBackends) {
|
|
|
|
t.Fatalf("expected %#v, got %#v", c.expectedBackends, actualConfig.Backends)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(actualConfig.Frontends, c.expectedFrontends) {
|
|
|
|
t.Fatalf("expected %#v, got %#v", c.expectedFrontends, actualConfig.Frontends)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|