Skip to content

Commit

Permalink
use ssh-tunnel port if present
Browse files Browse the repository at this point in the history
  • Loading branch information
ssendev committed Oct 12, 2015
1 parent 166164c commit 07e893e
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 2 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ The Redis host. If [url](#url) is defined, then this option is not needed.

The Redis port. If [url](#url) is defined, then this option is not needed.

*Default:* `6379`
*Default:* `6379` or `context.tunnel.srcPort` if present (set by [ember-cli-deploy-ssh-tunnel][7])

### database

Expand Down Expand Up @@ -265,6 +265,10 @@ The following properties are expected to be present on the deployment `context`
- `commandLineArgs.revisionKey` (provided by [ember-cli-deploy][5])
- `deployEnvironment` (provided by [ember-cli-deploy][5])

The following properties are used if present on the deployment `context` object:

- `tunnel.srcPort` (provided by [ember-cli-deploy-ssh-tunnel][7])

## Running Tests

- `npm test`
Expand All @@ -275,3 +279,4 @@ The following properties are expected to be present on the deployment `context`
[4]: https://github.com/ember-cli-deploy/ember-cli-deploy-build "ember-cli-deploy-build"
[5]: https://github.com/ember-cli/ember-cli-deploy "ember-cli-deploy"
[6]: https://github.com/ember-cli-deploy/ember-cli-deploy-revision-data "ember-cli-deploy-revision-data"
[7]: https://github.com/ember-cli-deploy/ember-cli-deploy-ssh-tunnel "ember-cli-deploy-ssh-tunnel"
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ module.exports = {
name: options.name,
defaultConfig: {
host: 'localhost',
port: 6379,
port: function(context) {
if (context.tunnel && context.tunnel.srcPort) {
return context.tunnel.srcPort;
} else {
return 6379;
}
},
filePattern: 'index.html',
distDir: function(context) {
return context.distDir;
Expand All @@ -42,6 +48,7 @@ module.exports = {
},
redisDeployClient: function(context) {
var redisOptions = this.pluginConfig;
redisOptions.port = this.readConfig('port');
var redisLib = context._redisLib;

return new Redis(redisOptions, redisLib);
Expand Down
72 changes: 72 additions & 0 deletions tests/unit/index-nodetest.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,78 @@ describe('redis plugin', function() {
assert.equal(redisLib.createdClient.options.database, 4);
});

describe('resolving port from the pipeline', function() {
it('uses the config data if it already exists', function() {
var plugin = subject.createDeployPlugin({
name: 'redis'
});

var config = {
host: 'somehost',
port: 1234,
};
var context = {
ui: mockUi,
project: stubProject,
config: {
redis: config
},
tunnel: {
srcPort: '2345'
}
};

plugin.beforeHook(context);
plugin.configure(context);
assert.equal(plugin.readConfig('port'), '1234');
});

it('uses the context value if it exists and config doesn\'t', function() {
var plugin = subject.createDeployPlugin({
name: 'redis'
});

var config = {
host: 'somehost',
};
var context = {
ui: mockUi,
project: stubProject,
config: {
redis: config
},
tunnel: {
srcPort: '2345'
}
};

plugin.beforeHook(context);
plugin.configure(context);
assert.equal(plugin.readConfig('port'), '2345');
});

it('uses the default port if config and context don\'t exist', function() {
var plugin = subject.createDeployPlugin({
name: 'redis'
});

var config = {
host: 'somehost',
};
var context = {
ui: mockUi,
project: stubProject,
config: {
redis: config
}
};

plugin.beforeHook(context);
plugin.configure(context);
assert.equal(plugin.readConfig('port'), '6379');
});
});

describe('resolving revisionKey from the pipeline', function() {
it('uses the config data if it already exists', function() {
var plugin = subject.createDeployPlugin({
Expand Down

0 comments on commit 07e893e

Please sign in to comment.