-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from allegro/add_tests
Add tests for marathon.go and refactor
- Loading branch information
Showing
12 changed files
with
795 additions
and
392 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
{ | ||
"app": { | ||
"id": "/myapp", | ||
"cmd": "env && python -m SimpleHTTPServer $PORT0", | ||
"args": null, | ||
"user": null, | ||
"env": {}, | ||
"instances": 2, | ||
"cpus": 0.1, | ||
"mem": 32.0, | ||
"disk": 0.0, | ||
"executor": "", | ||
"constraints": [], | ||
"uris": [], | ||
"storeUrls": [], | ||
"ports": [ | ||
10002, | ||
1, | ||
2, | ||
3 | ||
], | ||
"requirePorts": false, | ||
"backoffSeconds": 1, | ||
"backoffFactor": 1.15, | ||
"maxLaunchDelaySeconds": 3600, | ||
"container": null, | ||
"healthChecks": [ | ||
{ | ||
"path": "/", | ||
"protocol": "HTTP", | ||
"portIndex": 0, | ||
"gracePeriodSeconds": 10, | ||
"intervalSeconds": 5, | ||
"timeoutSeconds": 10, | ||
"maxConsecutiveFailures": 3, | ||
"ignoreHttp1xx": false | ||
} | ||
], | ||
"dependencies": [], | ||
"upgradeStrategy": { | ||
"minimumHealthCapacity": 1.0, | ||
"maximumOverCapacity": 1.0 | ||
}, | ||
"labels": { | ||
"consul": "true", | ||
"public": "tag" | ||
}, | ||
"version": "2015-12-01T10:03:32.003Z", | ||
"tasksStaged": 0, | ||
"tasksRunning": 2, | ||
"tasksHealthy": 2, | ||
"tasksUnhealthy": 0, | ||
"deployments": [], | ||
"tasks": [ | ||
{ | ||
"id": "myapp.cc49ccc1-9812-11e5-a06e-56847afe9799", | ||
"host": "10.141.141.10", | ||
"ports": [ | ||
31678, | ||
31679, | ||
31680, | ||
31681 | ||
], | ||
"startedAt": "2015-12-01T10:03:40.966Z", | ||
"stagedAt": "2015-12-01T10:03:40.890Z", | ||
"version": "2015-12-01T10:03:32.003Z", | ||
"appId": "/myapp", | ||
"healthCheckResults": [ | ||
{ | ||
"alive": true, | ||
"consecutiveFailures": 0, | ||
"firstSuccess": "2015-12-01T10:03:42.324Z", | ||
"lastFailure": null, | ||
"lastSuccess": "2015-12-01T10:03:42.324Z", | ||
"taskId": "myapp.cc49ccc1-9812-11e5-a06e-56847afe9799" | ||
} | ||
] | ||
}, | ||
{ | ||
"id": "myapp.c8b449f0-9812-11e5-a06e-56847afe9799", | ||
"host": "10.141.141.10", | ||
"ports": [ | ||
31307, | ||
31308, | ||
31309, | ||
31310 | ||
], | ||
"startedAt": "2015-12-01T10:03:34.945Z", | ||
"stagedAt": "2015-12-01T10:03:34.877Z", | ||
"version": "2015-12-01T10:03:32.003Z", | ||
"appId": "/myapp", | ||
"healthCheckResults": [ | ||
{ | ||
"alive": true, | ||
"consecutiveFailures": 0, | ||
"firstSuccess": "2015-12-01T10:03:37.313Z", | ||
"lastFailure": null, | ||
"lastSuccess": "2015-12-01T10:03:42.337Z", | ||
"taskId": "myapp.c8b449f0-9812-11e5-a06e-56847afe9799" | ||
} | ||
] | ||
} | ||
], | ||
"lastTaskFailure": null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package apps | ||
|
||
import ( | ||
"github.com/allegro/marathon-consul/tasks" | ||
"github.com/stretchr/testify/assert" | ||
"io/ioutil" | ||
"testing" | ||
) | ||
|
||
func TestParseApps(t *testing.T) { | ||
t.Parallel() | ||
|
||
appBlob, _ := ioutil.ReadFile("apps.json") | ||
|
||
expected := []*App{ | ||
&App{ | ||
HealthChecks: []HealthCheck{ | ||
HealthCheck{ | ||
Path: "/", | ||
PortIndex: 0, | ||
Protocol: "HTTP", | ||
GracePeriodSeconds: 5, | ||
IntervalSeconds: 20, | ||
TimeoutSeconds: 20, | ||
MaxConsecutiveFailures: 3, | ||
}, | ||
}, | ||
ID: "/bridged-webapp", | ||
Tasks: []tasks.Task{ | ||
tasks.Task{ | ||
ID: "test.47de43bd-1a81-11e5-bdb6-e6cb6734eaf8", | ||
AppID: "/test", | ||
Host: "192.168.2.114", | ||
Ports: []int{31315}, | ||
HealthCheckResults: []tasks.HealthCheckResult{tasks.HealthCheckResult{Alive: true}}, | ||
}, | ||
tasks.Task{ | ||
ID: "test.4453212c-1a81-11e5-bdb6-e6cb6734eaf8", | ||
AppID: "/test", | ||
Host: "192.168.2.114", | ||
Ports: []int{31797}, | ||
}, | ||
}, | ||
}, | ||
} | ||
apps, err := ParseApps(appBlob) | ||
assert.NoError(t, err) | ||
assert.Len(t, apps, 1) | ||
assert.Equal(t, expected, apps) | ||
} | ||
|
||
func TestParseApp(t *testing.T) { | ||
t.Parallel() | ||
|
||
appBlob, _ := ioutil.ReadFile("app.json") | ||
|
||
expected := &App{Labels: map[string]string{"consul": "true", "public": "tag"}, | ||
HealthChecks: []HealthCheck{HealthCheck{Path: "/", | ||
PortIndex: 0, | ||
Protocol: "HTTP", | ||
GracePeriodSeconds: 10, | ||
IntervalSeconds: 5, | ||
TimeoutSeconds: 10, | ||
MaxConsecutiveFailures: 3}}, | ||
ID: "/myapp", | ||
Tasks: []tasks.Task{tasks.Task{ | ||
ID: "myapp.cc49ccc1-9812-11e5-a06e-56847afe9799", | ||
AppID: "/myapp", | ||
Host: "10.141.141.10", | ||
Ports: []int{31678, | ||
31679, | ||
31680, | ||
31681}, | ||
HealthCheckResults: []tasks.HealthCheckResult{tasks.HealthCheckResult{Alive: true}}}, | ||
tasks.Task{ | ||
ID: "myapp.c8b449f0-9812-11e5-a06e-56847afe9799", | ||
AppID: "/myapp", | ||
Host: "10.141.141.10", | ||
Ports: []int{31307, | ||
31308, | ||
31309, | ||
31310}, | ||
HealthCheckResults: []tasks.HealthCheckResult{tasks.HealthCheckResult{Alive: true}}}}} | ||
|
||
app, err := ParseApp(appBlob) | ||
assert.NoError(t, err) | ||
assert.Equal(t, expected, app) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
{ | ||
"apps": [ | ||
{ | ||
"args": null, | ||
"backoffFactor": 1.15, | ||
"backoffSeconds": 1, | ||
"maxLaunchDelaySeconds": 3600, | ||
"cmd": "python3 -m http.server 8080", | ||
"constraints": [], | ||
"container": { | ||
"docker": { | ||
"image": "python:3", | ||
"network": "BRIDGE", | ||
"portMappings": [ | ||
{ | ||
"containerPort": 8080, | ||
"hostPort": 0, | ||
"servicePort": 9000, | ||
"protocol": "tcp" | ||
}, | ||
{ | ||
"containerPort": 161, | ||
"hostPort": 0, | ||
"protocol": "udp" | ||
} | ||
] | ||
}, | ||
"type": "DOCKER", | ||
"volumes": [] | ||
}, | ||
"cpus": 0.5, | ||
"dependencies": [], | ||
"deployments": [], | ||
"disk": 0.0, | ||
"env": {}, | ||
"executor": "", | ||
"healthChecks": [ | ||
{ | ||
"command": null, | ||
"gracePeriodSeconds": 5, | ||
"intervalSeconds": 20, | ||
"maxConsecutiveFailures": 3, | ||
"path": "/", | ||
"portIndex": 0, | ||
"protocol": "HTTP", | ||
"timeoutSeconds": 20 | ||
} | ||
], | ||
"id": "/bridged-webapp", | ||
"instances": 2, | ||
"mem": 64.0, | ||
"ports": [ | ||
10000, | ||
10001 | ||
], | ||
"requirePorts": false, | ||
"storeUrls": [], | ||
"tasksRunning": 2, | ||
"tasksHealthy": 2, | ||
"tasksUnhealthy": 0, | ||
"tasksStaged": 0, | ||
"upgradeStrategy": { | ||
"minimumHealthCapacity": 1.0 | ||
}, | ||
"uris": [], | ||
"user": null, | ||
"version": "2014-09-25T02:26:59.256Z", | ||
"tasks": [ | ||
{ | ||
"appId": "/test", | ||
"host": "192.168.2.114", | ||
"id": "test.47de43bd-1a81-11e5-bdb6-e6cb6734eaf8", | ||
"ports": [ | ||
31315 | ||
], | ||
"stagedAt": "2015-06-24T14:57:06.353Z", | ||
"startedAt": "2015-06-24T14:57:06.466Z", | ||
"version": "2015-06-24T14:56:57.466Z", | ||
"healthCheckResults": [ | ||
{ | ||
"alive": true, | ||
"consecutiveFailures": 0, | ||
"firstSuccess": "2015-11-28T18:21:11.957Z", | ||
"lastFailure": null, | ||
"lastSuccess": "2015-11-30T10:08:19.477Z", | ||
"taskId": "bridged-webapp.a9b051fb-95fc-11e5-9571-02818b42970e" | ||
} | ||
] | ||
}, | ||
{ | ||
"appId": "/test", | ||
"host": "192.168.2.114", | ||
"id": "test.4453212c-1a81-11e5-bdb6-e6cb6734eaf8", | ||
"ports": [ | ||
31797 | ||
], | ||
"stagedAt": "2015-06-24T14:57:00.474Z", | ||
"startedAt": "2015-06-24T14:57:00.611Z", | ||
"version": "2015-06-24T14:56:57.466Z" | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
package marathon | ||
|
||
type Config struct { | ||
Location string | ||
Protocol string | ||
Username string | ||
Password string | ||
Location string | ||
Protocol string | ||
Username string | ||
Password string | ||
VerifySsl bool | ||
} |
Oops, something went wrong.