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

View file

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

View file

@ -169,13 +169,13 @@ func (_m *Marathon) DeleteApplication(name string) (*marathon.DeploymentID, erro
return r0, r1
}
// UpdateApplication provides a mock function with given fields: application
func (_m *Marathon) UpdateApplication(application *marathon.Application) (*marathon.DeploymentID, error) {
ret := _m.Called(application)
// UpdateApplication provides a mock function with given fields: application, force
func (_m *Marathon) UpdateApplication(application *marathon.Application, force bool) (*marathon.DeploymentID, error) {
ret := _m.Called(application, force)
var r0 *marathon.DeploymentID
if rf, ok := ret.Get(0).(func(*marathon.Application) *marathon.DeploymentID); ok {
r0 = rf(application)
if rf, ok := ret.Get(0).(func(*marathon.Application, bool) *marathon.DeploymentID); ok {
r0 = rf(application, force)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*marathon.DeploymentID)
@ -183,8 +183,8 @@ func (_m *Marathon) UpdateApplication(application *marathon.Application) (*marat
}
var r1 error
if rf, ok := ret.Get(1).(func(*marathon.Application) error); ok {
r1 = rf(application)
if rf, ok := ret.Get(1).(func(*marathon.Application, bool) error); ok {
r1 = rf(application, force)
} else {
r1 = ret.Error(1)
}
@ -307,6 +307,29 @@ func (_m *Marathon) Application(name string) (*marathon.Application, error) {
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
func (_m *Marathon) WaitOnApplication(name string, timeout time.Duration) error {
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
fakeClient := new(fakeClient)
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 tasksError {
fakeClient.On("AllTasks", mock.AnythingOfType("*marathon.AllTasksOpts")).Return(nil, errors.New("error"))
if !applicationsError {
if tasksError {
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
}
@ -65,8 +69,9 @@ func TestMarathonLoadConfig(t *testing.T) {
applications: &marathon.Applications{
Apps: []marathon.Application{
{
ID: "/test",
Ports: []int{80},
ID: "/test",
Ports: []int{80},
Labels: &map[string]string{},
},
},
},
@ -115,6 +120,7 @@ func TestMarathonLoadConfig(t *testing.T) {
marathonClient: fakeClient,
}
actualConfig := provider.loadMarathonConfig()
fakeClient.AssertExpectations(t)
if c.expectedNil {
if actualConfig != nil {
t.Fatalf("Should have been nil, got %v", actualConfig)
@ -161,7 +167,8 @@ func TestMarathonTaskFilter(t *testing.T) {
applications: &marathon.Applications{
Apps: []marathon.Application{
{
ID: "foo",
ID: "foo",
Labels: &map[string]string{},
},
},
},
@ -176,8 +183,9 @@ func TestMarathonTaskFilter(t *testing.T) {
applications: &marathon.Applications{
Apps: []marathon.Application{
{
ID: "foo",
Ports: []int{80, 443},
ID: "foo",
Ports: []int{80, 443},
Labels: &map[string]string{},
},
},
},
@ -194,7 +202,7 @@ func TestMarathonTaskFilter(t *testing.T) {
{
ID: "foo",
Ports: []int{80},
Labels: map[string]string{
Labels: &map[string]string{
"traefik.enable": "false",
},
},
@ -213,7 +221,7 @@ func TestMarathonTaskFilter(t *testing.T) {
{
ID: "specify-port-number",
Ports: []int{80, 443},
Labels: map[string]string{
Labels: &map[string]string{
"traefik.port": "80",
},
},
@ -232,7 +240,7 @@ func TestMarathonTaskFilter(t *testing.T) {
{
ID: "specify-unknown-port-number",
Ports: []int{80, 443},
Labels: map[string]string{
Labels: &map[string]string{
"traefik.port": "8080",
},
},
@ -251,7 +259,7 @@ func TestMarathonTaskFilter(t *testing.T) {
{
ID: "specify-port-index",
Ports: []int{80, 443},
Labels: map[string]string{
Labels: &map[string]string{
"traefik.portIndex": "0",
},
},
@ -270,7 +278,7 @@ func TestMarathonTaskFilter(t *testing.T) {
{
ID: "specify-out-of-range-port-index",
Ports: []int{80, 443},
Labels: map[string]string{
Labels: &map[string]string{
"traefik.portIndex": "2",
},
},
@ -289,7 +297,7 @@ func TestMarathonTaskFilter(t *testing.T) {
{
ID: "specify-both-port-index-and-number",
Ports: []int{80, 443},
Labels: map[string]string{
Labels: &map[string]string{
"traefik.port": "443",
"traefik.portIndex": "1",
},
@ -307,10 +315,11 @@ func TestMarathonTaskFilter(t *testing.T) {
applications: &marathon.Applications{
Apps: []marathon.Application{
{
ID: "foo",
Ports: []int{80},
HealthChecks: []*marathon.HealthCheck{
marathon.NewDefaultHealthCheck(),
ID: "foo",
Ports: []int{80},
Labels: &map[string]string{},
HealthChecks: &[]marathon.HealthCheck{
*marathon.NewDefaultHealthCheck(),
},
},
},
@ -331,10 +340,11 @@ func TestMarathonTaskFilter(t *testing.T) {
applications: &marathon.Applications{
Apps: []marathon.Application{
{
ID: "foo",
Ports: []int{80},
HealthChecks: []*marathon.HealthCheck{
marathon.NewDefaultHealthCheck(),
ID: "foo",
Ports: []int{80},
Labels: &map[string]string{},
HealthChecks: &[]marathon.HealthCheck{
*marathon.NewDefaultHealthCheck(),
},
},
},
@ -358,10 +368,11 @@ func TestMarathonTaskFilter(t *testing.T) {
applications: &marathon.Applications{
Apps: []marathon.Application{
{
ID: "foo",
Ports: []int{80},
HealthChecks: []*marathon.HealthCheck{
marathon.NewDefaultHealthCheck(),
ID: "foo",
Ports: []int{80},
Labels: &map[string]string{},
HealthChecks: &[]marathon.HealthCheck{
*marathon.NewDefaultHealthCheck(),
},
},
},
@ -377,8 +388,9 @@ func TestMarathonTaskFilter(t *testing.T) {
applications: &marathon.Applications{
Apps: []marathon.Application{
{
ID: "foo",
Ports: []int{80},
ID: "foo",
Ports: []int{80},
Labels: &map[string]string{},
},
},
},
@ -398,10 +410,11 @@ func TestMarathonTaskFilter(t *testing.T) {
applications: &marathon.Applications{
Apps: []marathon.Application{
{
ID: "foo",
Ports: []int{80},
HealthChecks: []*marathon.HealthCheck{
marathon.NewDefaultHealthCheck(),
ID: "foo",
Ports: []int{80},
Labels: &map[string]string{},
HealthChecks: &[]marathon.HealthCheck{
*marathon.NewDefaultHealthCheck(),
},
},
},
@ -417,8 +430,9 @@ func TestMarathonTaskFilter(t *testing.T) {
applications: &marathon.Applications{
Apps: []marathon.Application{
{
ID: "disable-default-expose",
Ports: []int{80},
ID: "disable-default-expose",
Ports: []int{80},
Labels: &map[string]string{},
},
},
},
@ -435,7 +449,7 @@ func TestMarathonTaskFilter(t *testing.T) {
{
ID: "disable-default-expose-disable-in-label",
Ports: []int{80},
Labels: map[string]string{
Labels: &map[string]string{
"traefik.enable": "false",
},
},
@ -454,7 +468,7 @@ func TestMarathonTaskFilter(t *testing.T) {
{
ID: "disable-default-expose-enable-in-label",
Ports: []int{80},
Labels: map[string]string{
Labels: &map[string]string{
"traefik.enable": "true",
},
},
@ -486,14 +500,16 @@ func TestMarathonApplicationFilter(t *testing.T) {
},
{
application: marathon.Application{
ID: "test",
ID: "test",
Labels: &map[string]string{},
},
filteredTasks: []marathon.Task{},
expected: false,
},
{
application: marathon.Application{
ID: "foo",
ID: "foo",
Labels: &map[string]string{},
},
filteredTasks: []marathon.Task{
{
@ -504,7 +520,8 @@ func TestMarathonApplicationFilter(t *testing.T) {
},
{
application: marathon.Application{
ID: "foo",
ID: "foo",
Labels: &map[string]string{},
},
filteredTasks: []marathon.Task{
{
@ -539,7 +556,8 @@ func TestMarathonGetPort(t *testing.T) {
{
applications: []marathon.Application{
{
ID: "test1",
ID: "test1",
Labels: &map[string]string{},
},
},
task: marathon.Task{
@ -550,7 +568,8 @@ func TestMarathonGetPort(t *testing.T) {
{
applications: []marathon.Application{
{
ID: "test1",
ID: "test1",
Labels: &map[string]string{},
},
},
task: marathon.Task{
@ -562,7 +581,8 @@ func TestMarathonGetPort(t *testing.T) {
{
applications: []marathon.Application{
{
ID: "test1",
ID: "test1",
Labels: &map[string]string{},
},
},
task: marathon.Task{
@ -575,7 +595,7 @@ func TestMarathonGetPort(t *testing.T) {
applications: []marathon.Application{
{
ID: "specify-port-number",
Labels: map[string]string{
Labels: &map[string]string{
"traefik.port": "443",
},
},
@ -590,7 +610,7 @@ func TestMarathonGetPort(t *testing.T) {
applications: []marathon.Application{
{
ID: "specify-port-index",
Labels: map[string]string{
Labels: &map[string]string{
"traefik.portIndex": "1",
},
},
@ -628,7 +648,7 @@ func TestMarathonGetWeigh(t *testing.T) {
applications: []marathon.Application{
{
ID: "test1",
Labels: map[string]string{
Labels: &map[string]string{
"traefik.weight": "10",
},
},
@ -642,7 +662,7 @@ func TestMarathonGetWeigh(t *testing.T) {
applications: []marathon.Application{
{
ID: "test",
Labels: map[string]string{
Labels: &map[string]string{
"traefik.test": "10",
},
},
@ -656,7 +676,7 @@ func TestMarathonGetWeigh(t *testing.T) {
applications: []marathon.Application{
{
ID: "test",
Labels: map[string]string{
Labels: &map[string]string{
"traefik.weight": "10",
},
},
@ -686,12 +706,13 @@ func TestMarathonGetDomain(t *testing.T) {
expected string
}{
{
application: marathon.Application{},
expected: "docker.localhost",
application: marathon.Application{
Labels: &map[string]string{}},
expected: "docker.localhost",
},
{
application: marathon.Application{
Labels: map[string]string{
Labels: &map[string]string{
"traefik.domain": "foo.bar",
},
},
@ -724,7 +745,7 @@ func TestMarathonGetProtocol(t *testing.T) {
applications: []marathon.Application{
{
ID: "test1",
Labels: map[string]string{
Labels: &map[string]string{
"traefik.protocol": "https",
},
},
@ -738,7 +759,7 @@ func TestMarathonGetProtocol(t *testing.T) {
applications: []marathon.Application{
{
ID: "test",
Labels: map[string]string{
Labels: &map[string]string{
"traefik.foo": "bar",
},
},
@ -752,7 +773,7 @@ func TestMarathonGetProtocol(t *testing.T) {
applications: []marathon.Application{
{
ID: "test",
Labels: map[string]string{
Labels: &map[string]string{
"traefik.protocol": "https",
},
},
@ -780,12 +801,13 @@ func TestMarathonGetPassHostHeader(t *testing.T) {
expected string
}{
{
application: marathon.Application{},
expected: "true",
application: marathon.Application{
Labels: &map[string]string{}},
expected: "true",
},
{
application: marathon.Application{
Labels: map[string]string{
Labels: &map[string]string{
"traefik.frontend.passHostHeader": "false",
},
},
@ -809,12 +831,13 @@ func TestMarathonGetEntryPoints(t *testing.T) {
expected []string
}{
{
application: marathon.Application{},
expected: []string{},
application: marathon.Application{
Labels: &map[string]string{}},
expected: []string{},
},
{
application: marathon.Application{
Labels: map[string]string{
Labels: &map[string]string{
"traefik.frontend.entryPoints": "http,https",
},
},
@ -841,18 +864,20 @@ func TestMarathonGetFrontendRule(t *testing.T) {
expected string
}{
{
application: marathon.Application{},
expected: "Host:.docker.localhost",
application: marathon.Application{
Labels: &map[string]string{}},
expected: "Host:.docker.localhost",
},
{
application: marathon.Application{
ID: "test",
ID: "test",
Labels: &map[string]string{},
},
expected: "Host:test.docker.localhost",
},
{
application: marathon.Application{
Labels: map[string]string{
Labels: &map[string]string{
"traefik.frontend.rule": "Host:foo.bar",
},
},
@ -878,7 +903,7 @@ func TestMarathonGetBackend(t *testing.T) {
{
application: marathon.Application{
ID: "foo",
Labels: map[string]string{
Labels: &map[string]string{
"traefik.backend": "bar",
},
},