Ejemplo n.º 1
0
func TestMarathonTaskConstraints(t *testing.T) {
	cases := []struct {
		applications            []marathon.Application
		filteredTask            marathon.Task
		expected                bool
		marathonLBCompatibility bool
	}{
		{
			applications: []marathon.Application{
				{
					ID:     "bar1",
					Labels: &map[string]string{},
				}, {
					ID: "foo1",
					Labels: &map[string]string{
						"traefik.tags": "other",
					},
				},
			},
			filteredTask: marathon.Task{
				AppID: "foo1",
				Ports: []int{80},
			},
			marathonLBCompatibility: false,
			expected:                false,
		},
		{
			applications: []marathon.Application{
				{
					ID: "foo2",
					Labels: &map[string]string{
						"traefik.tags": "valid",
					},
				},
			},
			filteredTask: marathon.Task{
				AppID: "foo2",
				Ports: []int{80},
			},
			marathonLBCompatibility: false,
			expected:                true,
		},
		{
			applications: []marathon.Application{
				{
					ID: "foo3",
					Labels: &map[string]string{
						"HAPROXY_GROUP": "valid",
						"traefik.tags":  "notvalid",
					},
				}, {
					ID: "foo4",
					Labels: &map[string]string{
						"HAPROXY_GROUP": "notvalid",
						"traefik.tags":  "valid",
					},
				},
			},
			filteredTask: marathon.Task{
				AppID: "foo3",
				Ports: []int{80},
			},
			marathonLBCompatibility: true,
			expected:                true,
		},
	}

	for _, c := range cases {
		provider := &Marathon{
			MarathonLBCompatibility: c.marathonLBCompatibility,
		}
		constraint, _ := types.NewConstraint("tag==valid")
		provider.Constraints = types.Constraints{constraint}
		apps := new(marathon.Applications)
		apps.Apps = c.applications
		actual := provider.taskFilter(c.filteredTask, apps, true)
		if actual != c.expected {
			t.Fatalf("expected %v, got %v: %v", c.expected, actual, c.filteredTask)
		}
	}
}
Ejemplo n.º 2
0
func TestMarathonAppConstraints(t *testing.T) {
	cases := []struct {
		application             marathon.Application
		filteredTasks           []marathon.Task
		expected                bool
		marathonLBCompatibility bool
	}{
		{
			application: marathon.Application{
				ID:     "foo1",
				Labels: &map[string]string{},
			},
			filteredTasks: []marathon.Task{
				{
					AppID: "foo1",
				},
			},
			marathonLBCompatibility: false,
			expected:                false,
		},
		{
			application: marathon.Application{
				ID: "foo2",
				Labels: &map[string]string{
					"traefik.tags": "valid",
				},
			},
			filteredTasks: []marathon.Task{
				{
					AppID: "foo2",
				},
			},
			marathonLBCompatibility: false,
			expected:                true,
		},
		{
			application: marathon.Application{
				ID: "foo3",
				Labels: &map[string]string{
					"HAPROXY_GROUP": "valid",
					"traefik.tags":  "notvalid",
				},
			},
			filteredTasks: []marathon.Task{
				{
					AppID: "foo3",
				},
			},
			marathonLBCompatibility: true,
			expected:                true,
		},
	}

	for _, c := range cases {
		provider := &Marathon{
			MarathonLBCompatibility: c.marathonLBCompatibility,
		}
		constraint, _ := types.NewConstraint("tag==valid")
		provider.Constraints = types.Constraints{constraint}
		actual := provider.applicationFilter(c.application, c.filteredTasks)
		if actual != c.expected {
			t.Fatalf("expected %v, got %v: %v", c.expected, actual, c.application)
		}
	}

}