-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Marathon 1.5 #335
Open
katallaxie
wants to merge
17
commits into
gambol99:master
Choose a base branch
from
katallaxie:marathon1.5
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Marathon 1.5 #335
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
94d909a
move portmappings out of docker definition, network definition into n…
8bca4a2
remove ip per task
6b06f58
add network name
109dc08
fix docs
1867d92
addnetwork and emptynetworknames
494a09b
port mapping network names tests
093bf3d
networking tests
d973696
remove uris/ports
dd67f7c
restore compatibility with marathon < 1.5
13b9fbd
fix service port index function
c50aabe
fix retrieving service port in tasks
f9dea27
fix tests
9004fe0
fix tests, rename new methods to match old ones
5b880b0
mention port number in error message
63b9934
~ adding fixing tests and linting for marathon 1.5
c064ab4
Merge branch 'master' into marathon1.5
katallaxie e2b51e3
~ adding go report card
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -43,31 +43,70 @@ func TestApplicationMemory(t *testing.T) { | |
} | ||
|
||
func TestApplicationString(t *testing.T) { | ||
app := NewDockerApplication(). | ||
Name("my-app"). | ||
CPU(0.1). | ||
Memory(64). | ||
Storage(0.0). | ||
Count(2). | ||
AddArgs("/usr/sbin/apache2ctl", "-D", "FOREGROUND"). | ||
AddEnv("NAME", "frontend_http"). | ||
AddEnv("SERVICE_80_NAME", "test_http") | ||
app. | ||
Container.Docker.Container("quay.io/gambol99/apache-php:latest"). | ||
Bridged(). | ||
Expose(80). | ||
Expose(443) | ||
app, err := app.CheckHTTP("/health", 80, 5) | ||
assert.Nil(t, err) | ||
|
||
expectedAppJSONBytes, err := ioutil.ReadFile("tests/app-definitions/TestApplicationString-output.json") | ||
if err != nil { | ||
panic(err) | ||
type test struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can use an anonymous struct here as the type will never be reused. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, it was just for sake of clarity. |
||
name string | ||
app *Application | ||
expectedAppJSONPath string | ||
setup func(*Application) | ||
} | ||
expectedAppJSON := strings.TrimSpace(string(expectedAppJSONBytes)) | ||
assert.Equal(t, expectedAppJSON, app.String()) | ||
} | ||
|
||
tests := []test{ | ||
{ | ||
name: "marathon < 1.5", | ||
app: NewDockerApplication(). | ||
Name("my-app"). | ||
CPU(0.1). | ||
Memory(64). | ||
Storage(0.0). | ||
Count(2). | ||
AddArgs("/usr/sbin/apache2ctl", "-D", "FOREGROUND"). | ||
AddEnv("NAME", "frontend_http"). | ||
AddEnv("SERVICE_80_NAME", "test_http"), | ||
expectedAppJSONPath: "tests/app-definitions/TestApplicationString-output.json", | ||
setup: func(app *Application) { | ||
app. | ||
Container.Docker.Container("quay.io/gambol99/apache-php:latest"). | ||
Bridged(). | ||
Expose(80). | ||
Expose(443) | ||
}, | ||
}, | ||
{ | ||
name: "marathon > 1.5", | ||
app: NewDockerApplication(). | ||
Name("my-app"). | ||
CPU(0.1). | ||
Memory(64). | ||
Storage(0.0). | ||
Count(2). | ||
SetNetwork("", "container/bridge"). | ||
AddArgs("/usr/sbin/apache2ctl", "-D", "FOREGROUND"). | ||
AddEnv("NAME", "frontend_http"). | ||
AddEnv("SERVICE_80_NAME", "test_http"), | ||
expectedAppJSONPath: "tests/app-definitions/TestApplicationString-1.5-output.json", | ||
setup: func(app *Application) { | ||
app. | ||
Container.Expose(80).Expose(443). | ||
Docker.Container("quay.io/gambol99/apache-php:latest") | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
label := fmt.Sprintf("test: %s", test.name) | ||
|
||
test.setup(test.app) | ||
_, err := test.app.CheckHTTP("/health", 80, 5) | ||
assert.Nil(t, err) | ||
|
||
expectedAppJSONBytes, err := ioutil.ReadFile(test.expectedAppJSONPath) | ||
if err != nil { | ||
panic(err) | ||
} | ||
expectedAppJSON := strings.TrimSpace(string(expectedAppJSONBytes)) | ||
assert.Equal(t, expectedAppJSON, test.app.String(), label) | ||
} | ||
} | ||
func TestApplicationCount(t *testing.T) { | ||
app := NewDockerApplication() | ||
assert.Nil(t, app.Instances) | ||
|
@@ -290,45 +329,87 @@ func TestApplicationPortDefinitions(t *testing.T) { | |
} | ||
|
||
func TestHasHealthChecks(t *testing.T) { | ||
app := NewDockerApplication() | ||
assert.False(t, app.HasHealthChecks()) | ||
app.Container.Docker.Container("quay.io/gambol99/apache-php:latest").Expose(80) | ||
_, err := app.CheckTCP(80, 10) | ||
assert.NoError(t, err) | ||
assert.True(t, app.HasHealthChecks()) | ||
apps := []*Application{ | ||
NewDockerApplication(), | ||
NewDockerApplication(), | ||
} | ||
|
||
for i := range apps { | ||
assert.False(t, apps[i].HasHealthChecks()) | ||
} | ||
|
||
// Marathon < 1.5 | ||
apps[0].Container.Docker.Container("quay.io/gambol99/apache-php:latest").Expose(80) | ||
|
||
// Marathon >= 1.5 | ||
apps[1].Container.Expose(80).Docker.Container("quay.io/gambol99/apache-php:latest") | ||
|
||
for i := range apps { | ||
_, err := apps[i].CheckTCP(80, 10) | ||
assert.NoError(t, err) | ||
assert.True(t, apps[i].HasHealthChecks()) | ||
} | ||
} | ||
|
||
func TestApplicationCheckTCP(t *testing.T) { | ||
app := NewDockerApplication() | ||
assert.False(t, app.HasHealthChecks()) | ||
_, err := app.CheckTCP(80, 10) | ||
assert.Error(t, err) | ||
assert.False(t, app.HasHealthChecks()) | ||
app.Container.Docker.Container("quay.io/gambol99/apache-php:latest").Expose(80) | ||
_, err = app.CheckTCP(80, 10) | ||
assert.NoError(t, err) | ||
assert.True(t, app.HasHealthChecks()) | ||
check := (*app.HealthChecks)[0] | ||
assert.Equal(t, "TCP", check.Protocol) | ||
assert.Equal(t, 10, check.IntervalSeconds) | ||
assert.Equal(t, 0, *check.PortIndex) | ||
apps := []*Application{ | ||
NewDockerApplication(), | ||
NewDockerApplication(), | ||
} | ||
|
||
for i := range apps { | ||
assert.False(t, apps[i].HasHealthChecks()) | ||
_, err := apps[i].CheckTCP(80, 10) | ||
assert.Error(t, err) | ||
assert.False(t, apps[i].HasHealthChecks()) | ||
} | ||
|
||
// Marathon < 1.5 | ||
apps[0].Container.Docker.Container("quay.io/gambol99/apache-php:latest").Expose(80) | ||
|
||
// Marathon >= 1.5 | ||
apps[1].Container.Expose(80).Docker.Container("quay.io/gambol99/apache-php:latest") | ||
|
||
for i := range apps { | ||
_, err := apps[i].CheckTCP(80, 10) | ||
assert.NoError(t, err) | ||
assert.True(t, apps[i].HasHealthChecks()) | ||
check := (*apps[i].HealthChecks)[0] | ||
assert.Equal(t, "TCP", check.Protocol) | ||
assert.Equal(t, 10, check.IntervalSeconds) | ||
assert.Equal(t, 0, *check.PortIndex) | ||
} | ||
} | ||
|
||
func TestApplicationCheckHTTP(t *testing.T) { | ||
app := NewDockerApplication() | ||
assert.False(t, app.HasHealthChecks()) | ||
_, err := app.CheckHTTP("/", 80, 10) | ||
assert.Error(t, err) | ||
assert.False(t, app.HasHealthChecks()) | ||
app.Container.Docker.Container("quay.io/gambol99/apache-php:latest").Expose(80) | ||
_, err = app.CheckHTTP("/health", 80, 10) | ||
assert.NoError(t, err) | ||
assert.True(t, app.HasHealthChecks()) | ||
check := (*app.HealthChecks)[0] | ||
assert.Equal(t, "HTTP", check.Protocol) | ||
assert.Equal(t, 10, check.IntervalSeconds) | ||
assert.Equal(t, "/health", *check.Path) | ||
assert.Equal(t, 0, *check.PortIndex) | ||
apps := []*Application{ | ||
NewDockerApplication(), | ||
NewDockerApplication(), | ||
} | ||
|
||
for i := range apps { | ||
assert.False(t, apps[i].HasHealthChecks()) | ||
_, err := apps[i].CheckHTTP("/", 80, 10) | ||
assert.Error(t, err) | ||
assert.False(t, apps[i].HasHealthChecks()) | ||
} | ||
|
||
// Marathon < 1.5 | ||
apps[0].Container.Docker.Container("quay.io/gambol99/apache-php:latest").Expose(80) | ||
|
||
// Marathon >= 1.5 | ||
apps[1].Container.Expose(80).Docker.Container("quay.io/gambol99/apache-php:latest") | ||
|
||
for i := range apps { | ||
_, err := apps[i].CheckHTTP("/health", 80, 10) | ||
assert.NoError(t, err) | ||
assert.True(t, apps[i].HasHealthChecks()) | ||
check := (*apps[i].HealthChecks)[0] | ||
assert.Equal(t, "HTTP", check.Protocol) | ||
assert.Equal(t, 10, check.IntervalSeconds) | ||
assert.Equal(t, "/health", *check.Path) | ||
assert.Equal(t, 0, *check.PortIndex) | ||
} | ||
} | ||
|
||
func TestCreateApplication(t *testing.T) { | ||
|
@@ -483,9 +564,9 @@ func TestApplicationFetchURIs(t *testing.T) { | |
assert.Equal(t, Fetch{URI: "file://uri2.tar.gz"}, (*app.Fetch)[1]) | ||
assert.Equal(t, Fetch{URI: "file://uri3.tar.gz"}, (*app.Fetch)[2]) | ||
|
||
app.EmptyUris() | ||
assert.NotNil(t, app.Uris) | ||
assert.Equal(t, 0, len(*app.Uris)) | ||
app.EmptyFetchURIs() | ||
assert.NotNil(t, app.Fetch) | ||
assert.Equal(t, 0, len(*app.Fetch)) | ||
} | ||
|
||
func TestSetApplicationVersion(t *testing.T) { | ||
|
@@ -725,7 +806,7 @@ func TestIPAddressPerTask(t *testing.T) { | |
assert.Equal(t, 1, len(*ipPerTask.Groups)) | ||
assert.Equal(t, "label", (*ipPerTask.Groups)[0]) | ||
assert.Equal(t, "value", (*ipPerTask.Labels)["key"]) | ||
assert.NotEmpty(t, ipPerTask.Discovery) | ||
assert.NotEmpty(t, *ipPerTask.Discovery) | ||
|
||
ipPerTask.EmptyGroups() | ||
assert.Equal(t, 0, len(*ipPerTask.Groups)) | ||
|
@@ -764,3 +845,24 @@ func TestUpgradeStrategy(t *testing.T) { | |
assert.Nil(t, us.MinimumHealthCapacity) | ||
assert.Nil(t, us.MaximumOverCapacity) | ||
} | ||
|
||
func TestBridgedNetworking(t *testing.T) { | ||
app := NewDockerApplication().SetNetwork("test", "container/bridge") | ||
networks := *app.Networks | ||
|
||
assert.Equal(t, networks[0].Mode, "container/bridge") | ||
} | ||
|
||
func TestContainerNetworking(t *testing.T) { | ||
app := NewDockerApplication().SetNetwork("test", "container") | ||
networks := *app.Networks | ||
|
||
assert.Equal(t, networks[0].Mode, "container") | ||
} | ||
|
||
func TestHostNetworking(t *testing.T) { | ||
app := NewDockerApplication().SetNetwork("test", "host") | ||
networks := *app.Networks | ||
|
||
assert.Equal(t, networks[0].Mode, "host") | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This points at the wrong repo. But really, I'd rather have this added by a separate PR as well.
Remember that if we have to revert the final commit that will end up in master for whatever functional reason, all drive-by changes will be gone as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets keep it for now :)