Fix marathon tests

Signed-off-by: Emile Vauge <emile@vauge.com>
This commit is contained in:
Emile Vauge 2016-06-20 17:11:07 +02:00
parent 4ca2ff0495
commit b586df6689
No known key found for this signature in database
GPG key ID: D808B4C167352E59
4 changed files with 124 additions and 85 deletions

13
glide.lock generated
View file

@ -1,5 +1,5 @@
hash: 5a6dbc30a69abd002736bd5113e0f783c448faee20a0791c724ec2c3c1cfb8bb hash: cba5a5482db5b6b3857187d401d8e47f9b36f00e7acdf6aba0174707cc8c8b8a
updated: 2016-06-03T18:11:43.839017153+02:00 updated: 2016-06-20T23:18:44.178752884+02:00
imports: imports:
- name: github.com/boltdb/bolt - name: github.com/boltdb/bolt
version: 3f7947a25d970e1e5f512276c14d5dcf731ccd5e version: 3f7947a25d970e1e5f512276c14d5dcf731ccd5e
@ -21,15 +21,6 @@ imports:
version: b98687da5c323650f4513fda6b6203fcbdec9313 version: b98687da5c323650f4513fda6b6203fcbdec9313
- name: github.com/containous/mux - name: github.com/containous/mux
version: a819b77bba13f0c0cbe36e437bc2e948411b3996 version: a819b77bba13f0c0cbe36e437bc2e948411b3996
- name: github.com/containous/oxy
version: 183212964e13e7b8afe01a08b193d04300554a68
subpackages:
- cbreaker
- connlimit
- forward
- roundrobin
- stream
- utils
- name: github.com/containous/staert - name: github.com/containous/staert
version: e2aa88e235a02dd52aa1d5d9de75f9d9139d1602 version: e2aa88e235a02dd52aa1d5d9de75f9d9139d1602
- name: github.com/coreos/etcd - name: github.com/coreos/etcd

View file

@ -60,7 +60,7 @@ import:
subpackages: subpackages:
- plugin/rewrite - plugin/rewrite
- package: github.com/xenolf/lego - package: github.com/xenolf/lego
version: 30a7a8e8821de3532192d1240a45e53c6204f603 version: b2fad6198110326662e9e356a97199078a4a775c
subpackages: subpackages:
- acme - acme
- package: golang.org/x/net - package: golang.org/x/net

View file

@ -169,13 +169,13 @@ func (_m *Marathon) DeleteApplication(name string) (*marathon.DeploymentID, erro
return r0, r1 return r0, r1
} }
// UpdateApplication provides a mock function with given fields: application // UpdateApplication provides a mock function with given fields: application, force
func (_m *Marathon) UpdateApplication(application *marathon.Application) (*marathon.DeploymentID, error) { func (_m *Marathon) UpdateApplication(application *marathon.Application, force bool) (*marathon.DeploymentID, error) {
ret := _m.Called(application) ret := _m.Called(application, force)
var r0 *marathon.DeploymentID var r0 *marathon.DeploymentID
if rf, ok := ret.Get(0).(func(*marathon.Application) *marathon.DeploymentID); ok { if rf, ok := ret.Get(0).(func(*marathon.Application, bool) *marathon.DeploymentID); ok {
r0 = rf(application) r0 = rf(application, force)
} else { } else {
if ret.Get(0) != nil { if ret.Get(0) != nil {
r0 = ret.Get(0).(*marathon.DeploymentID) r0 = ret.Get(0).(*marathon.DeploymentID)
@ -183,8 +183,8 @@ func (_m *Marathon) UpdateApplication(application *marathon.Application) (*marat
} }
var r1 error var r1 error
if rf, ok := ret.Get(1).(func(*marathon.Application) error); ok { if rf, ok := ret.Get(1).(func(*marathon.Application, bool) error); ok {
r1 = rf(application) r1 = rf(application, force)
} else { } else {
r1 = ret.Error(1) r1 = ret.Error(1)
} }
@ -307,6 +307,29 @@ func (_m *Marathon) Application(name string) (*marathon.Application, error) {
return r0, r1 return r0, r1
} }
// ApplicationByVersion provides a mock function with given fields: name, version
func (_m *Marathon) ApplicationByVersion(name string, version string) (*marathon.Application, error) {
ret := _m.Called(name, version)
var r0 *marathon.Application
if rf, ok := ret.Get(0).(func(string, string) *marathon.Application); ok {
r0 = rf(name, version)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*marathon.Application)
}
}
var r1 error
if rf, ok := ret.Get(1).(func(string, string) error); ok {
r1 = rf(name, version)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// WaitOnApplication provides a mock function with given fields: name, timeout // WaitOnApplication provides a mock function with given fields: name, timeout
func (_m *Marathon) WaitOnApplication(name string, timeout time.Duration) error { func (_m *Marathon) WaitOnApplication(name string, timeout time.Duration) error {
ret := _m.Called(name, timeout) ret := _m.Called(name, timeout)

View file

@ -19,13 +19,17 @@ func newFakeClient(applicationsError bool, applications *marathon.Applications,
// create an instance of our test object // create an instance of our test object
fakeClient := new(fakeClient) fakeClient := new(fakeClient)
if applicationsError { if applicationsError {
fakeClient.On("Applications", mock.AnythingOfType("url.Values")).Return(nil, errors.New("error")) fakeClient.On("Applications", mock.Anything).Return(nil, errors.New("error"))
} else {
fakeClient.On("Applications", mock.Anything).Return(applications, nil)
} }
fakeClient.On("Applications", mock.AnythingOfType("url.Values")).Return(applications, nil) if !applicationsError {
if tasksError { if tasksError {
fakeClient.On("AllTasks", mock.AnythingOfType("*marathon.AllTasksOpts")).Return(nil, errors.New("error")) fakeClient.On("AllTasks", mock.Anything).Return(nil, errors.New("error"))
} else {
fakeClient.On("AllTasks", mock.Anything).Return(tasks, nil)
}
} }
fakeClient.On("AllTasks", mock.AnythingOfType("*marathon.AllTasksOpts")).Return(tasks, nil)
return fakeClient return fakeClient
} }
@ -67,6 +71,7 @@ func TestMarathonLoadConfig(t *testing.T) {
{ {
ID: "/test", ID: "/test",
Ports: []int{80}, Ports: []int{80},
Labels: &map[string]string{},
}, },
}, },
}, },
@ -115,6 +120,7 @@ func TestMarathonLoadConfig(t *testing.T) {
marathonClient: fakeClient, marathonClient: fakeClient,
} }
actualConfig := provider.loadMarathonConfig() actualConfig := provider.loadMarathonConfig()
fakeClient.AssertExpectations(t)
if c.expectedNil { if c.expectedNil {
if actualConfig != nil { if actualConfig != nil {
t.Fatalf("Should have been nil, got %v", actualConfig) t.Fatalf("Should have been nil, got %v", actualConfig)
@ -162,6 +168,7 @@ func TestMarathonTaskFilter(t *testing.T) {
Apps: []marathon.Application{ Apps: []marathon.Application{
{ {
ID: "foo", ID: "foo",
Labels: &map[string]string{},
}, },
}, },
}, },
@ -178,6 +185,7 @@ func TestMarathonTaskFilter(t *testing.T) {
{ {
ID: "foo", ID: "foo",
Ports: []int{80, 443}, Ports: []int{80, 443},
Labels: &map[string]string{},
}, },
}, },
}, },
@ -194,7 +202,7 @@ func TestMarathonTaskFilter(t *testing.T) {
{ {
ID: "foo", ID: "foo",
Ports: []int{80}, Ports: []int{80},
Labels: map[string]string{ Labels: &map[string]string{
"traefik.enable": "false", "traefik.enable": "false",
}, },
}, },
@ -213,7 +221,7 @@ func TestMarathonTaskFilter(t *testing.T) {
{ {
ID: "specify-port-number", ID: "specify-port-number",
Ports: []int{80, 443}, Ports: []int{80, 443},
Labels: map[string]string{ Labels: &map[string]string{
"traefik.port": "80", "traefik.port": "80",
}, },
}, },
@ -232,7 +240,7 @@ func TestMarathonTaskFilter(t *testing.T) {
{ {
ID: "specify-unknown-port-number", ID: "specify-unknown-port-number",
Ports: []int{80, 443}, Ports: []int{80, 443},
Labels: map[string]string{ Labels: &map[string]string{
"traefik.port": "8080", "traefik.port": "8080",
}, },
}, },
@ -251,7 +259,7 @@ func TestMarathonTaskFilter(t *testing.T) {
{ {
ID: "specify-port-index", ID: "specify-port-index",
Ports: []int{80, 443}, Ports: []int{80, 443},
Labels: map[string]string{ Labels: &map[string]string{
"traefik.portIndex": "0", "traefik.portIndex": "0",
}, },
}, },
@ -270,7 +278,7 @@ func TestMarathonTaskFilter(t *testing.T) {
{ {
ID: "specify-out-of-range-port-index", ID: "specify-out-of-range-port-index",
Ports: []int{80, 443}, Ports: []int{80, 443},
Labels: map[string]string{ Labels: &map[string]string{
"traefik.portIndex": "2", "traefik.portIndex": "2",
}, },
}, },
@ -289,7 +297,7 @@ func TestMarathonTaskFilter(t *testing.T) {
{ {
ID: "specify-both-port-index-and-number", ID: "specify-both-port-index-and-number",
Ports: []int{80, 443}, Ports: []int{80, 443},
Labels: map[string]string{ Labels: &map[string]string{
"traefik.port": "443", "traefik.port": "443",
"traefik.portIndex": "1", "traefik.portIndex": "1",
}, },
@ -309,8 +317,9 @@ func TestMarathonTaskFilter(t *testing.T) {
{ {
ID: "foo", ID: "foo",
Ports: []int{80}, Ports: []int{80},
HealthChecks: []*marathon.HealthCheck{ Labels: &map[string]string{},
marathon.NewDefaultHealthCheck(), HealthChecks: &[]marathon.HealthCheck{
*marathon.NewDefaultHealthCheck(),
}, },
}, },
}, },
@ -333,8 +342,9 @@ func TestMarathonTaskFilter(t *testing.T) {
{ {
ID: "foo", ID: "foo",
Ports: []int{80}, Ports: []int{80},
HealthChecks: []*marathon.HealthCheck{ Labels: &map[string]string{},
marathon.NewDefaultHealthCheck(), HealthChecks: &[]marathon.HealthCheck{
*marathon.NewDefaultHealthCheck(),
}, },
}, },
}, },
@ -360,8 +370,9 @@ func TestMarathonTaskFilter(t *testing.T) {
{ {
ID: "foo", ID: "foo",
Ports: []int{80}, Ports: []int{80},
HealthChecks: []*marathon.HealthCheck{ Labels: &map[string]string{},
marathon.NewDefaultHealthCheck(), HealthChecks: &[]marathon.HealthCheck{
*marathon.NewDefaultHealthCheck(),
}, },
}, },
}, },
@ -379,6 +390,7 @@ func TestMarathonTaskFilter(t *testing.T) {
{ {
ID: "foo", ID: "foo",
Ports: []int{80}, Ports: []int{80},
Labels: &map[string]string{},
}, },
}, },
}, },
@ -400,8 +412,9 @@ func TestMarathonTaskFilter(t *testing.T) {
{ {
ID: "foo", ID: "foo",
Ports: []int{80}, Ports: []int{80},
HealthChecks: []*marathon.HealthCheck{ Labels: &map[string]string{},
marathon.NewDefaultHealthCheck(), HealthChecks: &[]marathon.HealthCheck{
*marathon.NewDefaultHealthCheck(),
}, },
}, },
}, },
@ -419,6 +432,7 @@ func TestMarathonTaskFilter(t *testing.T) {
{ {
ID: "disable-default-expose", ID: "disable-default-expose",
Ports: []int{80}, Ports: []int{80},
Labels: &map[string]string{},
}, },
}, },
}, },
@ -435,7 +449,7 @@ func TestMarathonTaskFilter(t *testing.T) {
{ {
ID: "disable-default-expose-disable-in-label", ID: "disable-default-expose-disable-in-label",
Ports: []int{80}, Ports: []int{80},
Labels: map[string]string{ Labels: &map[string]string{
"traefik.enable": "false", "traefik.enable": "false",
}, },
}, },
@ -454,7 +468,7 @@ func TestMarathonTaskFilter(t *testing.T) {
{ {
ID: "disable-default-expose-enable-in-label", ID: "disable-default-expose-enable-in-label",
Ports: []int{80}, Ports: []int{80},
Labels: map[string]string{ Labels: &map[string]string{
"traefik.enable": "true", "traefik.enable": "true",
}, },
}, },
@ -487,6 +501,7 @@ func TestMarathonApplicationFilter(t *testing.T) {
{ {
application: marathon.Application{ application: marathon.Application{
ID: "test", ID: "test",
Labels: &map[string]string{},
}, },
filteredTasks: []marathon.Task{}, filteredTasks: []marathon.Task{},
expected: false, expected: false,
@ -494,6 +509,7 @@ func TestMarathonApplicationFilter(t *testing.T) {
{ {
application: marathon.Application{ application: marathon.Application{
ID: "foo", ID: "foo",
Labels: &map[string]string{},
}, },
filteredTasks: []marathon.Task{ filteredTasks: []marathon.Task{
{ {
@ -505,6 +521,7 @@ func TestMarathonApplicationFilter(t *testing.T) {
{ {
application: marathon.Application{ application: marathon.Application{
ID: "foo", ID: "foo",
Labels: &map[string]string{},
}, },
filteredTasks: []marathon.Task{ filteredTasks: []marathon.Task{
{ {
@ -540,6 +557,7 @@ func TestMarathonGetPort(t *testing.T) {
applications: []marathon.Application{ applications: []marathon.Application{
{ {
ID: "test1", ID: "test1",
Labels: &map[string]string{},
}, },
}, },
task: marathon.Task{ task: marathon.Task{
@ -551,6 +569,7 @@ func TestMarathonGetPort(t *testing.T) {
applications: []marathon.Application{ applications: []marathon.Application{
{ {
ID: "test1", ID: "test1",
Labels: &map[string]string{},
}, },
}, },
task: marathon.Task{ task: marathon.Task{
@ -563,6 +582,7 @@ func TestMarathonGetPort(t *testing.T) {
applications: []marathon.Application{ applications: []marathon.Application{
{ {
ID: "test1", ID: "test1",
Labels: &map[string]string{},
}, },
}, },
task: marathon.Task{ task: marathon.Task{
@ -575,7 +595,7 @@ func TestMarathonGetPort(t *testing.T) {
applications: []marathon.Application{ applications: []marathon.Application{
{ {
ID: "specify-port-number", ID: "specify-port-number",
Labels: map[string]string{ Labels: &map[string]string{
"traefik.port": "443", "traefik.port": "443",
}, },
}, },
@ -590,7 +610,7 @@ func TestMarathonGetPort(t *testing.T) {
applications: []marathon.Application{ applications: []marathon.Application{
{ {
ID: "specify-port-index", ID: "specify-port-index",
Labels: map[string]string{ Labels: &map[string]string{
"traefik.portIndex": "1", "traefik.portIndex": "1",
}, },
}, },
@ -628,7 +648,7 @@ func TestMarathonGetWeigh(t *testing.T) {
applications: []marathon.Application{ applications: []marathon.Application{
{ {
ID: "test1", ID: "test1",
Labels: map[string]string{ Labels: &map[string]string{
"traefik.weight": "10", "traefik.weight": "10",
}, },
}, },
@ -642,7 +662,7 @@ func TestMarathonGetWeigh(t *testing.T) {
applications: []marathon.Application{ applications: []marathon.Application{
{ {
ID: "test", ID: "test",
Labels: map[string]string{ Labels: &map[string]string{
"traefik.test": "10", "traefik.test": "10",
}, },
}, },
@ -656,7 +676,7 @@ func TestMarathonGetWeigh(t *testing.T) {
applications: []marathon.Application{ applications: []marathon.Application{
{ {
ID: "test", ID: "test",
Labels: map[string]string{ Labels: &map[string]string{
"traefik.weight": "10", "traefik.weight": "10",
}, },
}, },
@ -686,12 +706,13 @@ func TestMarathonGetDomain(t *testing.T) {
expected string expected string
}{ }{
{ {
application: marathon.Application{}, application: marathon.Application{
Labels: &map[string]string{}},
expected: "docker.localhost", expected: "docker.localhost",
}, },
{ {
application: marathon.Application{ application: marathon.Application{
Labels: map[string]string{ Labels: &map[string]string{
"traefik.domain": "foo.bar", "traefik.domain": "foo.bar",
}, },
}, },
@ -724,7 +745,7 @@ func TestMarathonGetProtocol(t *testing.T) {
applications: []marathon.Application{ applications: []marathon.Application{
{ {
ID: "test1", ID: "test1",
Labels: map[string]string{ Labels: &map[string]string{
"traefik.protocol": "https", "traefik.protocol": "https",
}, },
}, },
@ -738,7 +759,7 @@ func TestMarathonGetProtocol(t *testing.T) {
applications: []marathon.Application{ applications: []marathon.Application{
{ {
ID: "test", ID: "test",
Labels: map[string]string{ Labels: &map[string]string{
"traefik.foo": "bar", "traefik.foo": "bar",
}, },
}, },
@ -752,7 +773,7 @@ func TestMarathonGetProtocol(t *testing.T) {
applications: []marathon.Application{ applications: []marathon.Application{
{ {
ID: "test", ID: "test",
Labels: map[string]string{ Labels: &map[string]string{
"traefik.protocol": "https", "traefik.protocol": "https",
}, },
}, },
@ -780,12 +801,13 @@ func TestMarathonGetPassHostHeader(t *testing.T) {
expected string expected string
}{ }{
{ {
application: marathon.Application{}, application: marathon.Application{
Labels: &map[string]string{}},
expected: "true", expected: "true",
}, },
{ {
application: marathon.Application{ application: marathon.Application{
Labels: map[string]string{ Labels: &map[string]string{
"traefik.frontend.passHostHeader": "false", "traefik.frontend.passHostHeader": "false",
}, },
}, },
@ -809,12 +831,13 @@ func TestMarathonGetEntryPoints(t *testing.T) {
expected []string expected []string
}{ }{
{ {
application: marathon.Application{}, application: marathon.Application{
Labels: &map[string]string{}},
expected: []string{}, expected: []string{},
}, },
{ {
application: marathon.Application{ application: marathon.Application{
Labels: map[string]string{ Labels: &map[string]string{
"traefik.frontend.entryPoints": "http,https", "traefik.frontend.entryPoints": "http,https",
}, },
}, },
@ -841,18 +864,20 @@ func TestMarathonGetFrontendRule(t *testing.T) {
expected string expected string
}{ }{
{ {
application: marathon.Application{}, application: marathon.Application{
Labels: &map[string]string{}},
expected: "Host:.docker.localhost", expected: "Host:.docker.localhost",
}, },
{ {
application: marathon.Application{ application: marathon.Application{
ID: "test", ID: "test",
Labels: &map[string]string{},
}, },
expected: "Host:test.docker.localhost", expected: "Host:test.docker.localhost",
}, },
{ {
application: marathon.Application{ application: marathon.Application{
Labels: map[string]string{ Labels: &map[string]string{
"traefik.frontend.rule": "Host:foo.bar", "traefik.frontend.rule": "Host:foo.bar",
}, },
}, },
@ -878,7 +903,7 @@ func TestMarathonGetBackend(t *testing.T) {
{ {
application: marathon.Application{ application: marathon.Application{
ID: "foo", ID: "foo",
Labels: map[string]string{ Labels: &map[string]string{
"traefik.backend": "bar", "traefik.backend": "bar",
}, },
}, },