New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

git2consul

Package Overview
Dependencies
Maintainers
1
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

git2consul - npm Package Compare versions

Comparing version 0.6.1 to 0.6.2

test/git2consul_graceful_shutdown_test.js

2

lib/branch_manager.js

@@ -23,2 +23,4 @@ var fs = require('fs');

logger.info("Creating branch manager %s %s", branch_parent, branch_directory);
var update_in_progress = false;

@@ -25,0 +27,0 @@ var pending_ref_change = undefined;

118

lib/git_manager.js

@@ -20,37 +20,19 @@ var _ = require('underscore');

var mock = false;
/*
* Turn on mocking mode so that we can inject some bogus config for the purposes of testing.
*/
exports.mock = function() {
mock = true;
};
var daemon = true;
/**
* By default, git2consul expects to run as a daemon. If this flag is disabled, git2consul will not
* start any hooks and will shut down after initializing each branch in each repo.
*/
exports.setDaemon = function(daemon_mode) {
daemon = daemon_mode;
};
// Track all active GitManager objects so we can traverse them as needed for a graceful shutdown.
var git_managers = {};
var git_cache = {};
// End the process once we are sure that no branches are busy updating.
var gracefulShutdown = function() {
for (var repo_name in git_managers) {
exports.gracefulShutdown = function(cb) {
for (var repo_name in git_cache) {
var git_manager = git_managers[repo_name];
var branch_names = git_manager.getBranchNames();
var my_git_manager = git_cache[repo_name];
var branch_names = my_git_manager.getBranchNames();
for (var i=0; i<branch_names.length; ++i) {
var branch_name = branch_names[i];
if (git_manager.getBranchManager(branch_name).isBusy()) {
logger.warn("Waiting for branch %s in repo %s", branch_name, git_manager.getRepoName());
var my_branch_manager = my_git_manager.getBranchManager(branch_name);
if (my_branch_manager && my_branch_manager.isBusy()) {
logger.warn("Waiting for branch %s in repo %s", branch_name, my_git_manager.getRepoName());
setTimeout(function() {
exports.gracefulShutdown();
exports.gracefulShutdown(cb);
}, 1000);

@@ -62,3 +44,10 @@ return;

process.exit(0);
/* istanbul ignore else */
// If we were provided a callback, fire it once we know all branches have quiesced. Otherwise,
// shutdown the process.
if (cb) {
cb();
} else {
process.exit(0);
}
};

@@ -77,3 +66,3 @@

gracefulShutdown();
exports.gracefulShutdown();
});

@@ -87,2 +76,4 @@ }

logger.info(util.inspect(repo_config));
var branch_managers = {};

@@ -92,13 +83,28 @@

GitManager.prototype.getRepoName = function() {
return repo_config.name;
};
GitManager.prototype.getBranchNames = function() {
return repo_config.branches;
};
GitManager.prototype.getBranchManager = function(branch_name) {
return branch_managers[branch_name];
};
var this_obj = new GitManager();
var branch_count = 0;
if (!repo_config.branches || repo_config.branches.length === 0) return cb('No branches specified');
if (!repo_config.branches || repo_config.branches.length === 0) return cb('No branches specified.');
// TODO: Validate repo name is present on the config and add test case.
// TODO: Validate repo name is unique and add test case.
git_managers[repo_config.name] = this_obj;
// Validate repo name is present on the config.
if (!repo_config.name) return cb("No name provided for repo.");
// Validate repo name is unique.
if (git_cache[repo_config.name]) return cb("A repo with that name is already tracked.");
git_cache[repo_config.name] = this_obj;
var unique_branches = _.uniq(repo_config.branches);
if (unique_branches.length !== repo_config.branches.length)
if (unique_branches.length !== repo_config.branches.length)
return cb("Duplicate name found in branches for repo " + repo_config.name + ": " + repo_config.branches);

@@ -160,14 +166,2 @@

GitManager.prototype.getRepoName = function() {
return repo_config.name;
};
GitManager.prototype.getBranchNames = function() {
return repo_config.branches;
};
GitManager.prototype.getBranchManager = function(branch_name) {
return branch_managers[branch_name];
};
};

@@ -210,1 +204,33 @@

};
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Unit-testing aids
//
////////////////////////////////////////////////////////////////////////////////////////////////////
var mock = false;
/*
* Turn on mocking mode so that we can inject some bogus config for the purposes of testing.
*/
exports.mock = function() {
mock = true;
};
var daemon = true;
/**
* By default, git2consul expects to run as a daemon. If this flag is disabled, git2consul will not
* start any hooks and will shut down after initializing each branch in each repo.
*/
exports.setDaemon = function(daemon_mode) {
daemon = daemon_mode;
};
/**
* Clear the git_manager hash. This is useful for unit tests that need to recreate git_managers.
*/
exports.clearGitManagers = function() {
git_cache = {};
};

@@ -85,2 +85,9 @@ var util = require('util');

var changes = implementation.getHeadChanges(req);
if (changes.length === 0) {
logger.trace('No changes in a relevant branch.');
return res.send('ok');
}
var res_sent = false;
for (var i=0; i<changes.length; ++i) {

@@ -95,2 +102,5 @@ var change = changes[i];

logger.trace('No branch_manager for branch %s, ignoring.', change.branch);
// Only return a response for the first change handled by this webhook.
if (res_sent) return;
res_sent = true;
return res.send('ok');

@@ -100,13 +110,14 @@ }

/* istanbul ignore next */
if (err) {
logger.error(err);
return res.send('ok');
}
if (err) logger.error(err);
logger.debug('Updates in branch %s complete', change.branch);
// Only return a response for the first change handled by this webhook.
if (res_sent) return;
res_sent = true;
return res.send('ok');
});
}
} else {
res.send('ok');
}
res.send('ok');
});

@@ -113,0 +124,0 @@ });

@@ -33,2 +33,3 @@ var consul = require('consul')();

/* istanbul ignore next */
/**

@@ -35,0 +36,0 @@ * Wait for the consul config KV to change

@@ -15,2 +15,5 @@ var exec = require('child_process').exec;

logger.trace("stdout: " + stdout);
logger.trace("stderr: " + stderr);
if (err) return cb(new Error(err + ' ' + stderr));

@@ -17,0 +20,0 @@

{
"name": "git2consul",
"description": "System for moving data from git to consul",
"version": "0.6.1",
"version": "0.6.2",
"contributors": [

@@ -6,0 +6,0 @@ {

@@ -26,20 +26,17 @@ var should = require('should');

exports.cleanup = function(cb) {
consul_utils.purgeKeys('test_repo', function(err) {
if (err) return cb(err);
consul_utils.purgeKeys('test_github_repo', function(err) {
consul_utils.purgeKeys('', function(err) {
if (err) return cb(err);
rimraf(git_utils.TEST_REMOTE_REPO, function(err) {
if (err) return cb(err);
rimraf(git_utils.TEST_REMOTE_REPO, function(err) {
mkdirp(git_utils.TEST_REMOTE_REPO, function(err) {
if (err) return cb(err);
mkdirp(git_utils.TEST_REMOTE_REPO, function(err) {
rimraf(git_utils.TEST_WORKING_DIR, function(err) {
if (err) return cb(err);
rimraf(git_utils.TEST_WORKING_DIR, function(err) {
mkdirp(git_utils.TEST_WORKING_DIR, function(err) {
if (err) return cb(err);
mkdirp(git_utils.TEST_WORKING_DIR, function(err) {
rimraf(git_utils.TEST_GITHUB_WORKING_DIR, function(err) {
if (err) return cb(err);
rimraf(git_utils.TEST_GITHUB_WORKING_DIR, function(err) {
mkdirp(git_utils.TEST_GITHUB_WORKING_DIR, function(err) {
if (err) return cb(err);
mkdirp(git_utils.TEST_GITHUB_WORKING_DIR, function(err) {
if (err) return cb(err);
cb();
});
cb();
});

@@ -54,5 +51,18 @@ });

var manual_mode = false;
/**
* Provide a mechanism to disable bootstrapping for test cases that want to configure all
* repo functionality themselves.
*/
exports.manual_mode = function(manual) {
manual_mode = manual;
};
// These cleanup operations need to run before each test to make sure the state of the
// suite is consistent. Placed here, they will be run before all suites and tests.
beforeEach(function(done) {
// If we are in manual mode, do nothing.
if (manual_mode) return done();
exports.cleanup(function(err) {

@@ -59,0 +69,0 @@ git_utils.initRepo(function(err) {

@@ -23,4 +23,2 @@ var should = require('should');

var default_repo_config = git_utils.createRepoConfig();
return function(done) {

@@ -55,6 +53,6 @@

// At this point, the git_manager should have populated consul with both sample_key
consul_utils.validateValue(default_repo_config.name + '/master/' + sample_key, sample_value, function(err, value) {
consul_utils.validateValue(git_utils.GM.getRepoName() + '/master/' + sample_key, sample_value, function(err, value) {
if (err) return done(err);
consul_utils.validateValue(default_repo_config.name + '/master/' + sample_key2, sample_value2, function(err, value) {
consul_utils.validateValue(git_utils.GM.getRepoName() + '/master/' + sample_key2, sample_value2, function(err, value) {
if (err) return done(err);

@@ -61,0 +59,0 @@ done();

@@ -11,3 +11,3 @@ var _ = require('underscore');

describe('Config Validation', function() {
it ('should reject a config with no repos', function(done) {

@@ -39,5 +39,23 @@ var count = 3;

it ('should reject a config with no repo name', function(done) {
var stock_config = git_utils.createConfig();
delete stock_config.repos[0].name;
git_manager.manageRepo(stock_config, stock_config.repos[0], function(err) {
err.should.equal('No name provided for repo.');
done();
});
});
it ('should reject a config using an existing repo name', function(done) {
var stock_config = git_utils.createConfig();
stock_config.repos[0].name = git_utils.GM.getRepoName();
git_manager.manageRepo(stock_config, stock_config.repos[0], function(err) {
err.should.equal('A repo with that name is already tracked.');
done();
});
});
it ('should reject a repo with no branches', function(done) {
git_manager.manageRepo(git_utils.createConfig(), {'name': 'busted_repo', 'branches': []}, function(err) {
err.should.equal('No branches specified');
git_manager.manageRepo(git_utils.createConfig(), {'name': 'busted_no_branch_repo', 'branches': []}, function(err) {
err.should.equal('No branches specified.');
done();

@@ -48,4 +66,4 @@ });

it ('should reject a repo with duplicate branches', function(done) {
git_manager.manageRepo(git_utils.createConfig(), {'name': 'busted_repo', 'branches': ['master', 'master', 'commander']}, function(err) {
err.should.startWith('Duplicate name found in branches for repo busted_repo');
git_manager.manageRepo(git_utils.createConfig(), {'name': 'busted_dupe_branch_repo', 'branches': ['master', 'master', 'commander']}, function(err) {
err.should.startWith('Duplicate name found in branches for repo busted_dupe_branch_repo');
done();

@@ -58,3 +76,3 @@ });

stock_config.local_store = "/var/permdenied";
git_manager.manageRepo(stock_config, {'branches': ['master']}, function(err) {
git_manager.manageRepo(stock_config, {'name': 'permfail', 'branches': ['master']}, function(err) {
err.should.startWith('Failed to create root_directory for git manager:');

@@ -61,0 +79,0 @@ done();

@@ -19,12 +19,9 @@ var should = require('should');

var default_repo_config = git_utils.createRepoConfig();
it ('should handle updates to a single file', function(done) {
var sample_key = 'sample_key';
var sample_value = 'new test data';
var default_repo_config = git_utils.createRepoConfig();
var repo_name = git_utils.GM.getRepoName();
git_utils.addFileToGitRepo(sample_key, sample_value, "Update a file.", function(err) {
if (err) return done(err);
// At this point, the git_manager should have populated consul with our sample_key
consul_utils.validateValue(default_repo_config.name + '/master/' + sample_key, sample_value, function(err, value) {
consul_utils.validateValue(repo_name + '/master/' + sample_key, sample_value, function(err, value) {
if (err) return done(err);

@@ -39,7 +36,7 @@ done();

var sample_value = 'new value';
var default_repo_config = git_utils.createRepoConfig();
var repo_name = git_utils.GM.getRepoName();
git_utils.addFileToGitRepo(sample_key, sample_value, "Add a file.", function(err) {
if (err) return done(err);
// At this point, the git_manager should have populated consul with our sample_key
consul_utils.validateValue(default_repo_config.name + '/master/' + sample_key, sample_value, function(err, value) {
consul_utils.validateValue(repo_name + '/master/' + sample_key, sample_value, function(err, value) {
if (err) return done(err);

@@ -54,7 +51,7 @@ done();

var sample_value = 'new value';
var default_repo_config = git_utils.createRepoConfig();
var repo_name = git_utils.GM.getRepoName();
git_utils.addFileToGitRepo(sample_key, sample_value, "Create file to delete.", function(err) {
if (err) return done(err);
// At this point, the git_manager should have populated consul with our sample_key
consul_utils.validateValue(default_repo_config.name + '/master/' + sample_key, sample_value, function(err, value) {
consul_utils.validateValue(repo_name + '/master/' + sample_key, sample_value, function(err, value) {
if (err) return done(err);

@@ -64,3 +61,3 @@ git_utils.deleteFileFromGitRepo(sample_key, "Delete file.", true, function(err) {

// At this point, the git_manager should have removed our sample_key
consul_utils.validateValue(default_repo_config.name + '/master/' + sample_key, undefined, function(err, value) {
consul_utils.validateValue(repo_name + '/master/' + sample_key, undefined, function(err, value) {
if (err) return done(err);

@@ -78,7 +75,7 @@ done();

var sample_value = 'movable value';
var default_repo_config = git_utils.createRepoConfig();
var repo_name = git_utils.GM.getRepoName();
git_utils.addFileToGitRepo(sample_key, sample_value, "Create file to move.", function(err) {
if (err) return done(err);
// At this point, the git_manager should have populated consul with our sample_key
consul_utils.validateValue(default_repo_config.name + '/master/' + sample_key, sample_value, function(err, value) {
consul_utils.validateValue(repo_name + '/master/' + sample_key, sample_value, function(err, value) {
if (err) return done(err);

@@ -88,6 +85,6 @@ git_utils.moveFileInGitRepo(sample_key, sample_moved_key, "Move file.", function(err) {

// At this point, the git_manager should have populated consul with our moved key, deleting the old name
consul_utils.validateValue(default_repo_config.name + '/master/' + sample_key, undefined, function(err) {
consul_utils.validateValue(repo_name + '/master/' + sample_key, undefined, function(err) {
if (err) return done(err);
// At this point, the git_manager should have populated consul with our moved key, adding the new name
consul_utils.validateValue(default_repo_config.name + '/master/' + sample_moved_key, sample_value, function(err) {
consul_utils.validateValue(repo_name + '/master/' + sample_moved_key, sample_value, function(err) {
if (err) return done(err);

@@ -106,7 +103,7 @@ done();

var sample_value = 'movable value';
var default_repo_config = git_utils.createRepoConfig();
var repo_name = git_utils.GM.getRepoName();
git_utils.addFileToGitRepo(sample_key, sample_value, "Create file to move to subfolder.", function(err) {
if (err) return done(err);
// At this point, the git_manager should have populated consul with our sample_key
consul_utils.validateValue(default_repo_config.name + '/master/' + sample_key, sample_value, function(err, value) {
consul_utils.validateValue(repo_name + '/master/' + sample_key, sample_value, function(err, value) {
if (err) return done(err);

@@ -118,6 +115,6 @@ mkdirp(git_utils.TEST_REMOTE_REPO + 'subfolder', function(err) {

// At this point, the git_manager should have populated consul with our moved key, deleting the old name
consul_utils.validateValue(default_repo_config.name + '/master/' + sample_key, undefined, function(err) {
consul_utils.validateValue(repo_name + '/master/' + sample_key, undefined, function(err) {
if (err) return done(err);
// At this point, the git_manager should have populated consul with our moved key, adding the new name
consul_utils.validateValue(default_repo_config.name + '/master/' + sample_moved_key, sample_value, function(err) {
consul_utils.validateValue(repo_name + '/master/' + sample_moved_key, sample_value, function(err) {
if (err) return done(err);

@@ -137,7 +134,7 @@ done();

var sample_value = 'linked value';
var default_repo_config = git_utils.createRepoConfig();
var repo_name = git_utils.GM.getRepoName();
git_utils.addFileToGitRepo(sample_key, sample_value, "Create file for symlinking.", function(err) {
if (err) return done(err);
// At this point, the git_manager should have populated consul with our sample_key
consul_utils.validateValue(default_repo_config.name + '/master/' + sample_key, sample_value, function(err, value) {
consul_utils.validateValue(repo_name + '/master/' + sample_key, sample_value, function(err, value) {
if (err) return done(err);

@@ -147,6 +144,6 @@ git_utils.symlinkFileInGitRepo(sample_key, sample_referrent_file, "Change type of file.", function(err) {

// After symlinking, the consul KV should contain the symlink's name as a key and the symlinked file's contents as a value
consul_utils.validateValue(default_repo_config.name + '/master/' + sample_key, sample_value, function(err) {
consul_utils.validateValue(repo_name + '/master/' + sample_key, sample_value, function(err) {
if (err) return done(err);
// The symlink's referrent should also appear in the KV store.
consul_utils.validateValue(default_repo_config.name + '/master/' + sample_referrent_file, sample_value, function(err) {
consul_utils.validateValue(repo_name + '/master/' + sample_referrent_file, sample_value, function(err) {
if (err) return done(err);

@@ -153,0 +150,0 @@ done();

@@ -15,4 +15,2 @@ var should = require('should');

var default_repo_config = git_utils.createRepoConfig();
var buffer_test = function(size, cb) {

@@ -29,2 +27,4 @@ var buf = new Buffer(size);

var repo_name = git_utils.GM.getRepoName();
buffer_test(512*1024, function(err) {

@@ -34,3 +34,3 @@ if (err) return done(err);

// At this point, the git_manager should have populated consul with our sample_key
consul_utils.getValue(default_repo_config.name + '/master/big_file', function(err, value) {
consul_utils.getValue(repo_name + '/master/big_file', function(err, value) {
if (err) return done(err);

@@ -45,6 +45,8 @@ value.length.should.equal(512*1024);

var repo_name = git_utils.GM.getRepoName();
buffer_test(513*1024, function(err) {
err.should.not.equal(null);
// Because the write was rejected, no KV will exist.
consul_utils.validateValue(default_repo_config.name + '/master/big_file', undefined, function(err) {
consul_utils.validateValue(repo_name + '/master/big_file', undefined, function(err) {
if (err) return done(err);

@@ -58,2 +60,4 @@ done();

it ('should handle files with empty values', function(done) {
var repo_name = git_utils.GM.getRepoName();
var sample_key = 'sample_new_key';

@@ -65,3 +69,3 @@ var sample_value = '';

// At this point, the git_manager should have populated consul with our sample_key
consul_utils.validateValue(default_repo_config.name + '/master/' + sample_key, sample_value, function(err, value) {
consul_utils.validateValue(repo_name + '/master/' + sample_key, sample_value, function(err, value) {
if (err) return done(err);

@@ -68,0 +72,0 @@ done();

@@ -17,2 +17,3 @@ var should = require('should');

it ('should handle a multiple file repo', function(done) {
var repo_name = git_utils.GM.getRepoName();
var sample_key = 'sample_key';

@@ -31,5 +32,5 @@ var sample_value = 'test data';

// At this point, the git_manager should have populated consul with our sample_key
consul_utils.validateValue(default_repo_config.name + '/master/' + sample_key, sample_value, function(err, value) {
consul_utils.validateValue(repo_name + '/master/' + sample_key, sample_value, function(err, value) {
if (err) return done(err);
consul_utils.validateValue(default_repo_config.name + '/master/' + sample_key2, sample_value2, function(err, value) {
consul_utils.validateValue(repo_name + '/master/' + sample_key2, sample_value2, function(err, value) {
if (err) return done(err);

@@ -112,5 +113,8 @@ done();

it ('should handle creating a git_manager around a repo that is been emptied', function(done) {
it ('should handle creating a git_manager around a repo that has been emptied', function(done) {
var repo_name = git_utils.GM.getRepoName();
var default_config = git_utils.createConfig();
var default_repo_config = default_config.repos[0];
default_repo_config.name = repo_name;
git_manager.clearGitManagers();

@@ -132,4 +136,7 @@ // This addFileToGitRepo will automatically create a git_manager in git_utils, so once the callback

it ('should handle populating consul when you create a git_manager around a repo that is already on disk', function(done) {
var repo_name = git_utils.GM.getRepoName();
var default_config = git_utils.createConfig();
var default_repo_config = default_config.repos[0];
default_repo_config.name = repo_name;
git_manager.clearGitManagers();

@@ -148,3 +155,3 @@ var sample_key = 'sample_key';

// At this point, the git_manager should have populated consul with our sample_key
consul_utils.validateValue(default_repo_config.name + '/master/' + sample_key, sample_value, function(err, value) {
consul_utils.validateValue(repo_name + '/master/' + sample_key, sample_value, function(err, value) {
if (err) return done(err);

@@ -151,0 +158,0 @@ done();

@@ -19,2 +19,3 @@ var should = require('should');

return function(done) {
var repo_name = git_utils.GM.getRepoName();
git_utils.addFileToGitRepo(key_name, key_value, key_name + " key name test.", function(err) {

@@ -24,3 +25,3 @@ if (err) return done(err);

// At this point, the git_manager should have populated consul with our sample_key
consul_utils.validateValue(default_repo_config.name + '/master/' + key_name, key_value, function(err, value) {
consul_utils.validateValue(repo_name + '/master/' + key_name, key_value, function(err, value) {
if (err) return done(err);

@@ -27,0 +28,0 @@ done();

@@ -6,3 +6,3 @@ var should = require('should');

// We want this above any git2consul module to make sure logging gets configured
require('./git2consul_bootstrap_test.js');
var bootstrap = require('./git2consul_bootstrap_test.js');

@@ -14,2 +14,4 @@ var consul_utils = require('./utils/consul_utils.js');

var logger = require('../lib/utils/logging.js');
/**

@@ -20,3 +22,2 @@ * Test webhooks and polling. NOTE: This test needs to run last because the polling test case will

*/
// Test failing webhook configs

@@ -67,2 +68,4 @@ [[

var repo_counter = 0;
[

@@ -140,16 +143,27 @@ // Test webhooks sharing a port

var my_hooked_gm;
before(function(done) {
var config = git_utils.createConfig();
config.repos[0].hooks = hook_config;
git_manager.manageRepo(config, config.repos[0], function(err, gm) {
// Enable manual mode. We don't want the standard git2consul bootstrap tests to create a git_manager
// that is enabled without hooks as this just causes endless confusion.
bootstrap.manual_mode(true);
bootstrap.cleanup(function(err) {
if (err) return done(err);
my_hooked_gm = gm;
done();
var config = git_utils.createConfig();
config.repos[0].hooks = hook_config;
config.repos[0].name = "webhook_test" + repo_counter;
++repo_counter;
git_utils.initRepo(config, config.repos[0], function(err, gm) {
if (err) return done(err);
done();
});
});
});
var sample_data_randomizer = 0;
// This creates a function suitable as the predicate of a mocha test. The function will enclose

@@ -159,4 +173,6 @@ // the config object and use it to send a request to the webhook and validate the response.

return function(done) {
var repo_name = git_utils.GM.getRepoName();
var sample_key = 'sample_key';
var sample_value = 'stash test data';
var sample_value = 'stash test data ' + sample_data_randomizer;
++sample_data_randomizer;
git_utils.addFileToGitRepo(sample_key, sample_value, "Webhook.", false, function(err) {

@@ -167,3 +183,2 @@ if (err) return done(err);

if (config.type === 'bitbucket') {
//req_conf.headers = {'content-type':'application/x-www-form-urlencoded'};
req_conf.form = { payload: decodeURIComponent(config.body).replace(/\+/g, ' ') };

@@ -174,2 +189,3 @@ } else req_conf.json = config.body

request(req_conf, function(err) {
if (err) return done(err);

@@ -181,3 +197,3 @@

consul_utils.waitForValue('test_repo/master/sample_key', function(err) {
consul_utils.waitForValue(repo_name + '/master/sample_key', function(err) {
if (err) return done(err);

@@ -232,23 +248,31 @@

describe('polling hook', function() {
var my_hooked_gm;
before(function(done) {
var config = git_utils.createConfig();
config.repos[0].hooks = [{
'type': 'polling',
'interval': '1'
}];
// Signal that we are in mocking mode to allow for < 1 minute polling
// Enable manual mode. We don't want the standard git2consul bootstrap tests to create a git_manager
// that is enabled without hooks as this just causes endless confusion.
bootstrap.manual_mode(true);
git_manager.mock();
git_manager.manageRepo(config, config.repos[0], function(err, gm) {
bootstrap.cleanup(function(err) {
if (err) return done(err);
my_hooked_gm = gm;
done();
var config = git_utils.createConfig();
config.repos[0].hooks = [{
'type': 'polling',
'interval': '1'
}];
config.repos[0].name = "polling_test";
git_utils.initRepo(config, config.repos[0], function(err, gm) {
if (err) return done(err);
done();
});
});
});
it ('should handle inbound requests', function(done) {
it ('should handle polling updates', function(done) {
var repo_name = git_utils.GM.getRepoName();
var sample_key = 'sample_key';

@@ -259,3 +283,3 @@ var sample_value = 'stash test data';

consul_utils.waitForValue('test_repo/master/sample_key', function(err) {
consul_utils.waitForValue(repo_name + '/master/sample_key', function(err) {
if (err) return done(err);

@@ -262,0 +286,0 @@ done();

@@ -16,2 +16,3 @@ var should = require('should');

exports.validateValue = function(key, expected_value, cb) {
logger.trace('Looking for key %s with value %s', key, expected_value);
exports.getValue(key, function(err, value) {

@@ -30,2 +31,3 @@ if (err) return cb(err);

return function(key, cb) {
logger.trace('Waiting for key %s', key);
var check_value = function() {

@@ -32,0 +34,0 @@ exports.getValue(key, function(err, value) {

@@ -11,2 +11,4 @@ var fs = require('fs');

var repo_counter = 0;
exports.createConfig = function() {

@@ -22,4 +24,5 @@ return {

exports.createRepoConfig = function() {
++repo_counter;
return {
name: 'test_repo',
name: 'test_repo' + repo_counter,
url: 'file://' + exports.TEST_REMOTE_REPO,

@@ -30,4 +33,10 @@ branches: [ 'master' ]

exports.initRepo = function(cb) {
exports.initRepo = function(config, repo_config, cb) {
if (!cb) {
cb = config;
config = exports.createConfig();
repo_config = config.repos[0];
}
git_commands.init(exports.TEST_REMOTE_REPO, function(err) {

@@ -38,3 +47,3 @@ if (err) return cb(err);

git_manager.manageRepo(exports.createConfig(), exports.createRepoConfig(), function(err, gm) {
git_manager.manageRepo(config, repo_config, function(err, gm) {
if (err) return cb(err);

@@ -41,0 +50,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc