-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
191 additions
and
7 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
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const BASE_SCHEME_LABEL = "MARATHON_SCHEME_PORT"; | ||
|
||
var ServiceSchemeUtil = { | ||
/* | ||
* Returns service scheme of the n-th port. | ||
* | ||
* Given N a port index, if `MARATHON_SCHEME_PORT<N>` is | ||
* in the set of labels, then the function returns the value | ||
* of this label. | ||
* | ||
* Given N a port index, if `MARATHON_SCHEME_PORT0<N>` is | ||
* not in the set of labels, then the value associated with | ||
* `MARATHON_SCHEME_PORT` is returned. | ||
* | ||
* Given N a port index, if `MARATHON_SCHEME_PORT0<N>` and | ||
* `MARATHON_SCHEME_PORT` are not in the set of labels, the | ||
* function returns the `http` as the default scheme. | ||
*/ | ||
getServiceSchemeFromLabels(labels, n) { | ||
function getScheme(labelValue) { | ||
return (labelValue === "http" || labelValue === "https") | ||
? labelValue | ||
: ''; | ||
} | ||
|
||
const labelKey = ("" + BASE_SCHEME_LABEL + n); | ||
if (labels && labelKey in labels) | ||
return getScheme(labels[labelKey]); | ||
else if (labels && BASE_SCHEME_LABEL in labels) | ||
return getScheme(labels[BASE_SCHEME_LABEL]); | ||
|
||
return ''; | ||
} | ||
}; | ||
|
||
export default ServiceSchemeUtil; |
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,56 @@ | ||
import {expect} from "chai"; | ||
import ServiceSchemeUtil from "../../js/helpers/ServiceSchemeUtil"; | ||
|
||
function verifyPortSchemeWithDefault(serviceScheme, serviceScheme0, | ||
expectedSchemePort0, expectedSchemePort1) { | ||
describe("MARATHON_SCHEME_PORT is set to " + serviceScheme, function() { | ||
describe("MARATHON_SCHEME_PORT0 is set to " + serviceScheme0, function() { | ||
it("detect scheme of port 0", function() { | ||
expect(ServiceSchemeUtil.getServiceSchemeFromLabels({ | ||
"MARATHON_SCHEME_PORT": serviceScheme, | ||
"MARATHON_SCHEME_PORT0": serviceScheme0, | ||
}, 0)).to.eq(expectedSchemePort0); | ||
}); | ||
|
||
it("detect scheme of port 1", function() { | ||
expect(ServiceSchemeUtil.getServiceSchemeFromLabels({ | ||
"MARATHON_SCHEME_PORT": serviceScheme, | ||
"MARATHON_SCHEME_PORT0": serviceScheme0, | ||
}, 1)).to.eq(expectedSchemePort1); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
function verifyPortSchemeWithoutDefault(serviceScheme0, | ||
expectedSchemePort0, expectedSchemePort1) { | ||
describe("MARATHON_SCHEME_PORT is not set", function() { | ||
describe("MARATHON_SCHEME_PORT0 is set to " + serviceScheme0, function() { | ||
it("detect scheme of port 0", function() { | ||
expect(ServiceSchemeUtil.getServiceSchemeFromLabels({ | ||
"MARATHON_SCHEME_PORT0": serviceScheme0, | ||
}, 0)).to.eq(expectedSchemePort0); | ||
}); | ||
|
||
it("detect scheme of port 1", function() { | ||
expect(ServiceSchemeUtil.getServiceSchemeFromLabels({ | ||
"MARATHON_SCHEME_PORT0": serviceScheme0, | ||
}, 1)).to.eq(expectedSchemePort1); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
describe("ServiceSchemeUtil", function () { | ||
// default scheme scheme port 0 expected port 0 expected port 1 | ||
verifyPortSchemeWithDefault("http", "http", "http", "http"); | ||
verifyPortSchemeWithDefault("http", "https", "https", "http"); | ||
verifyPortSchemeWithDefault("https", "http", "http", "https"); | ||
verifyPortSchemeWithDefault("https", "https", "https", "https"); | ||
|
||
// scheme port 0 expected port 0 expected port 1 | ||
verifyPortSchemeWithoutDefault("http", "http", ""); | ||
verifyPortSchemeWithoutDefault("https", "https", ""); | ||
verifyPortSchemeWithoutDefault("http", "http", ""); | ||
verifyPortSchemeWithoutDefault("https", "https", ""); | ||
}); |
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