UNPKG

elasticsearch-watchdog

Version:

A watchdog of elasticsearch - cluster nodes' statuses monitor, auto restart, keep PRIMARY node unique.

95 lines (84 loc) 2.81 kB
var chai = require('chai'), should = chai.should(), expect = chai.expect, path = require('path'), fs = require('fs'), Watchdog = require('../'), helper = require('../lib/util/helper'), spawn = require('child_process').spawn; function runCmd(cmd, args, callback){ var proc = spawn(process.execPath, [ path.resolve(__dirname, '..', 'bin/watchdog'), cmd ].concat(args)); proc.stdout.on('data', function(data){ expect(data).exist; callback(data); proc.kill(); }); } describe('CLI utility', function(){ // you can find all logs and data here. describe('--root', function(){ it('should responds with root location', function(done){ runCmd('-r', [], function(data){ expect(data.toString()).to.match(/root location:(.+)/) done(); }) }); }); describe('pwd', function(){ it('should responds with encrypted password', function(done){ var pwd = 'testw@rd'; runCmd('pwd', [pwd], function(data){ var encryptedPwd = data.toString().match(/encrypted password:\s*(\S+)/); expect(encryptedPwd).exist; expect(encryptedPwd).have.length(2); encryptedPwd = encryptedPwd[1]; expect(encryptedPwd).exist; expect(helper.decrypt(encryptedPwd)).equal(pwd); done(); }) }); }); describe('encrypt', function(){ it('should render a template of configuration that passwords are encrypted', function(done){ runCmd('tmpl', ['my_es'], function(data){ var tmplLocation = data.toString().match(/Location of template is:\s*(\S+)/); expect(tmplLocation).exist; expect(tmplLocation).have.length(2); tmplLocation = tmplLocation[1]; expect(tmplLocation).exist; expect(fs.existsSync(tmplLocation)).is.ok; runCmd('encrypt', [tmplLocation], function(data){ var conf = helper.loadConfig(tmplLocation); var pwd = conf.nodes.host1.ssh.password; expect(pwd).exist; expect(helper.decrypt(pwd)).equal('passw@rd'); try { fs.unlinkSync(tmplLocation); } catch (err) { } done(); }); }) }); }); describe('tmpl', function(){ it('should render a template of configuration', function(done){ runCmd('tmpl', ['my_es'], function(data){ var tmplLocation = data.toString().match(/Location of template is:\s*(\S+)/); expect(tmplLocation).exist; expect(tmplLocation).have.length(2); tmplLocation = tmplLocation[1]; expect(tmplLocation).exist; expect(fs.existsSync(tmplLocation)).is.ok; try { fs.unlinkSync(tmplLocation); } catch (err) { } done(); }) }); }); });