describe('git version:', function () { var outputs = []; var ui = h.mockUI(beforeEach, outputs); var getProject; beforeEach(function () { getProject = new GetProject(ui); }); it('should be an old git version when < 1.7.10', function() { getProject._checkGitVersion('1.7.9'); h.expect(getProject.is_new_git).to.be.false; }); it('should be a new git version when >= 1.7.10', function() { getProject._checkGitVersion('1.7.10'); h.expect(getProject.is_new_git).to.be.true; }); it('should _gitHelper.version get real current git version', function() { var parsed_options = cliRouterCleanParams([ 'azk start git@github.com:azukiapp/azkdemo.git', '--git-ref master', '-vv', ].join(' ')); getProject = new GetProject(ui, parsed_options); return getProject._gitHelper.version(getProject.gitOutput) .then(function(git_version) { h.expect(git_version).to.match(/\d+\.\d+\.\d+/); }); }); });
describe('Azk generators Rails 4.1 rule', function() { var outputs = []; var UI = h.mockUI(beforeEach, outputs); var rule; before(function() { outputs = []; UI = h.mockUI(beforeEach, outputs); rule = new Rule(UI); }); it('should return an evidence object', () => { var gemfilePath = '/tmp/azk-test-30501680wvr4/front/Gemfile'; var gemfileContent = [ 'source \'https://rubygems.org\'', 'gem \'rails\', \'4.1.6\'', 'gem \'mysql2\', :git => "git://github.com/brianmario/mysql2"', 'gem \'pg\', \'~> 0.17.1\'', ].join('\n'); var evidence = rule.getEvidence(gemfilePath, gemfileContent); h.expect(evidence).to.have.deep.property('fullpath', gemfilePath); h.expect(evidence).to.have.deep.property('ruleType', 'framework'); h.expect(evidence).to.have.deep.property('name' , 'ruby_on_rails'); h.expect(evidence).to.have.deep.property('ruleName', 'ruby_on_rails'); h.expect(evidence.replaces).to.include('ruby'); h.expect(evidence.replaces).to.include('node'); h.expect(evidence).to.have.deep.property('version' , null); h.expect(evidence).to.have.deep.property('framework' , '4.1.6'); }); });
describe('Azk cli, version controller', function() { var outputs = []; var ui = h.mockUI(beforeEach, outputs); var cli_options = {}; var cli = new Cli(cli_options) .route('version', (p) => p.version || p['--version']); var doc_opts = { exit: false }; var run_options = { ui: ui }; var version_regex = /azk version \d+\.\d+\.\d+, build \w+, date \d+-\d+-\d+/; it('should run a version command', function() { doc_opts.argv = 'version'; var options = cli.docopt(doc_opts); return cli.run(doc_opts, run_options).then((code) => { h.expect(code).to.eql(0); h.expect(options).to.have.property('version', true); h.expect(outputs[0]).to.match(version_regex); }); }); it('should run a --version command', function() { doc_opts.argv = '--version'; return cli.run(doc_opts, run_options).then((code) => { h.expect(code).to.eql(0); h.expect(outputs[0]).to.match(version_regex); }); }); });
describe("Azk command info, run in an", function() { var outputs = []; var UI = h.mockUI(beforeEach, outputs); var cmd = init(UI); describe("invalid SoS dir", function() { it("should return error if not have manifest", function() { return h.tmp_dir().then((dir) => { cmd.cwd = dir; return h.expect(cmd.run()).to.rejectedWith(ManifestRequiredError); }); }); }); describe("valid SoS dir", function() { var SoS; before(() => { var data = { }; return h.mockManifest(data).then((dir) => { SoS = dir; }); }); it("should show systems information", function() { cmd.cwd = SoS; return cmd.run().then(() => { h.expect(outputs[0]).to.match(/example:/); h.expect(outputs[0]).to.match(RegExp(config('docker:image_default'))); h.expect(outputs[0]).to.match(/command:.*socat/); }); }); }); });
h.describeSkipVm("Azk command docker, run", function() { var outputs = []; var UI = h.mockUI(beforeEach, outputs); var cmd = init(UI); var argv = process.argv; afterEach(() => process.argv = argv); it("should call `azk vm ssh`", function() { cmd.cwd = __dirname; process.argv = [null, null, null, "images"]; return cmd.run().then(() => { h.expect(outputs[0]).to.match(/azk vm ssh -t/); h.expect(outputs[0]).to.match(RegExp("cd.*" + h.escapeRegExp(__dirname))); h.expect(outputs[0]).to.match(/; docker images/); }); }); it("should forwarding all arguments", function() { process.argv = [null, null, null, "run", "/bin/bash", "-c", "ls -l"]; return cmd.run().then(() => { var regex = /; docker run \/bin\/bash -c \\"ls -l\\"/; h.expect(outputs[0]).to.match(regex); }); }); });
describe('Azk cli, doctor controller', function() { var outputs = []; var ui = h.mockUI(beforeEach, outputs); var cli_options = {}; var cli = new Cli(cli_options) .route('doctor'); var doc_opts = { exit: false }; var run_options = { ui: ui, cwd: __dirname }; it("should run a `doctor` command", function() { doc_opts.argv = ['doctor']; var options = cli.router.cleanParams(cli.docopt(doc_opts)); return cli.run(doc_opts, run_options).then((code) => { h.expect(code).to.equal(0); h.expect(options).to.have.property('doctor', true); h.expect(outputs[0]).to.match(RegExp(`Version.*\:.*${h.escapeRegExp(Azk.version)}`)); h.expect(outputs[0]).to.match(RegExp(`Agent.*\:.*Running`)); }); }); it("should run a `doctor --logo` command", function() { doc_opts.argv = ['doctor', '--logo']; var options = cli.router.cleanParams(cli.docopt(doc_opts)); return cli.run(doc_opts, run_options).then((code) => { h.expect(code).to.equal(0); h.expect(options).to.have.property('doctor', true); h.expect(outputs[0]).to.match(RegExp(`Version.*\:.*${h.escapeRegExp(Azk.version)}`)); h.expect(outputs[0]).to.match(RegExp(`Agent.*\:.*Running`)); }); }); });
describe('Azk generators Django rule', function() { var outputs = []; var UI = h.mockUI(beforeEach, outputs); var rule; before(function() { outputs = []; UI = h.mockUI(beforeEach, outputs); rule = new Rule(UI); }); it('should return an evidence object', () => { var frameworkPath = '/tmp/djangoProject/requirements.txt'; var frameworkContent = [ 'BeautifulSoup==3.2.0', 'Django==1.4', 'Fabric==1.2.0', 'Jinja2==2.5.5', 'PyYAML==3.09', 'Pygments==1.4', 'SQLAlchemy==0.7.1', 'South==0.7.3', 'amqplib==0.6.1', 'anyjson==0.3', ].join('\n'); var evidence = rule.getEvidence(frameworkPath, frameworkContent); h.expect(evidence).to.have.deep.property('fullpath', frameworkPath); h.expect(evidence).to.have.deep.property('ruleType', 'framework'); h.expect(evidence).to.have.deep.property('name' , 'python_django'); h.expect(evidence).to.have.deep.property('ruleName', 'python_django-2.7'); h.expect(evidence).to.have.deep.property('framework' , '1.4.0'); }); it('should return python_django-2.7 when django framework version is too low', () => { var frameworkPath = '/tmp/djangoProject/requirements.txt'; var frameworkContent = [ 'Django==1.5.3', ].join('\n'); var evidence = rule.getEvidence(frameworkPath, frameworkContent); h.expect(evidence).to.have.deep.property('framework' , '1.5.3'); h.expect(evidence).to.have.deep.property('ruleName', 'python_django-2.7'); }); it('should return python_django-3.4 when django framework version is above 1.7', () => { var frameworkPath = '/tmp/djangoProject/requirements.txt'; var frameworkContent = [ 'Django==1.7.0', ].join('\n'); var evidence = rule.getEvidence(frameworkPath, frameworkContent); h.expect(evidence).to.have.deep.property('framework' , '1.7.0'); h.expect(evidence).to.have.deep.property('ruleName', 'python_django-3.4'); }); });
describe('Azk generators Pyhton rule', function() { var outputs = []; var UI = h.mockUI(beforeEach, outputs); var rule; before(function() { outputs = []; UI = h.mockUI(beforeEach, outputs); rule = new Rule(UI); }); it('should return an evidence object', () => { var runtimePath = '/tmp/pythonProject/runtime.txt'; var runtimeContent = [ 'python-3.4.2', '' ].join('\n'); var evidence = rule.getEvidence(runtimePath, runtimeContent); h.expect(evidence).to.have.deep.property('fullpath', runtimePath); h.expect(evidence).to.have.deep.property('ruleType', 'runtime'); h.expect(evidence).to.have.deep.property('name' , 'python'); h.expect(evidence).to.have.deep.property('ruleName', 'python34'); h.expect(evidence).to.have.deep.property('version' , '3.4.2'); }); it('should get latest python version when do not found engine', () => { var runtimePath = '/tmp/pythonProject/runtime.txt'; var runtimeContent = [ 'python-3.4.2' ].join('\n'); var evidence = rule.getEvidence(runtimePath, runtimeContent); h.expect(evidence).to.have.deep.property('ruleName', 'python34'); }); it('should get latest python version when version is too low', () => { var runtimePath = '/tmp/pythonProject/runtime.txt'; var runtimeContent = [ 'python-2.7.7' ].join('\n'); var evidence = rule.getEvidence(runtimePath, runtimeContent); h.expect(evidence).to.have.deep.property('ruleName', 'python34'); }); it('should get 2.7 python version when detected', () => { var runtimePath = '/tmp/pythonProject/runtime.txt'; var runtimeContent = [ 'python-2.7.8' ].join('\n'); var evidence = rule.getEvidence(runtimePath, runtimeContent); h.expect(evidence).to.have.deep.property('ruleName', 'python27'); }); });
describe("Azk generator ruby rule", function() { var project = null; var name = null; var outputs = []; var UI = h.mockUI(beforeEach, outputs); var generator = new Generator(UI); before(function() { return h.tmp_dir().then((dir) => { project = dir; name = path.basename(dir); }); }); var generateAndReturnManifest = (project) => { var manifest = path.join(project, config('manifest')); generator.render({ systems: generator.findSystems(project), }, manifest); return new Manifest(project); } it("should detect single node system", function() { h.touchSync(path.join(project, "Gemfile")); var manifest = generateAndReturnManifest(project); var system = manifest.systemDefault; var command = new RegExp(h.escapeRegExp("bundle exec rackup config.ru --port $HTTP_PORT")); h.expect(system).to.have.deep.property("name", name); h.expect(system).to.have.deep.property("image.name", "dockerfile/ruby:latest"); h.expect(system).to.have.deep.property("depends").and.to.eql([]); h.expect(system).to.have.deep.property("options.workdir", "/azk/" + name); h.expect(system).to.have.deep.property("command").and.match(command); h.expect(system).to.have.deep.property("raw_mount_folders") .and.to.eql({ ".": "/azk/" + name }); h.expect(system).to.have.deep.property("options.provision") .and.to.eql(["bundle install --path vendor/bundler"]); h.expect(system).to.have.property("scalable").and.ok; h.expect(system).to.have.property("hostname").and.match(new RegExp(name)); }); it("should detect sub-system", function() { var sub = path.join(project, "sub"); fs.mkdirSync(sub); h.touchSync(path.join(sub, "Gemfile")); var manifest = generateAndReturnManifest(project); var system = manifest.system("sub"); h.expect(system).to.have.deep.property("name", "sub"); h.expect(system).to.have.deep.property("options.workdir", "/azk/" + name + "/sub"); }); });
describe('_parseGitLsRemoteResult:', function () { var outputs = []; var ui = h.mockUI(beforeEach, outputs); var getProject = new GetProject(ui); it('should get commit and branch', function() { var input_string = [ '284b608a5b9301c3df8e4ddcf371ff74eec2d754 HEAD', '24af92c4701b6bb45c314e8b62be785b595ba74f refs/heads/feature/adding_services', '9fa9093f65e110ae036341861c0e8801e03591e1 refs/heads/final', '284b608a5b9301c3df8e4ddcf371ff74eec2d754 refs/heads/master', 'b6852f0c25461b2cc376b5339975a16747b412f8 refs/heads/two', 'f1ae4ba97ac97e615bb3e0d718e0565c3d303dcb refs/tags/v0.1.2', 'b6852f0c25461b2cc376b5339975a16747b412f8 refs/tags/v0.1.2^{}', ].join('\n'); var parsed_result = getProject._parseGitLsRemoteResult(input_string); h.expect(parsed_result).to.containSubset([ { commit: '284b608a5b9301c3df8e4ddcf371ff74eec2d754', git_ref: 'HEAD' }, { commit: '24af92c4701b6bb45c314e8b62be785b595ba74f', git_ref: 'feature/adding_services' }, { commit: '9fa9093f65e110ae036341861c0e8801e03591e1', git_ref: 'final' }, { commit: '284b608a5b9301c3df8e4ddcf371ff74eec2d754', git_ref: 'master' }, { commit: 'b6852f0c25461b2cc376b5339975a16747b412f8', git_ref: 'two' }, { commit: 'f1ae4ba97ac97e615bb3e0d718e0565c3d303dcb', git_ref: 'v0.1.2' }, { commit: 'b6852f0c25461b2cc376b5339975a16747b412f8', git_ref: 'v0.1.2^{}' }, ]); }); });
describe('Azk cli, terms controller', function() { var outputs = []; var ui = h.mockUI(beforeEach, outputs); var run_options = { ui: ui, cwd: __dirname }; var namespace = 'test_terms_of_use'; it("should support disable require accept of terms", function() { var cmd = new TermsController(run_options); cmd.require_terms = false; var result = cmd.askTermsOfUse({}, namespace); return h.expect(result).to.eventually.ok; }); });
h.describeRequireVm('Azk cli, vm controller', function() { var outputs = []; var ui = h.mockUI(beforeEach, outputs); var cli_options = {}; var cli = new Cli(cli_options) .route('vm'); var doc_opts = { exit: false }; var run_options = { ui: ui }; it("should run a vm status command", function() { doc_opts.argv = ['vm', 'status']; var options = cli.router.cleanParams(cli.docopt(doc_opts)); return cli.run(doc_opts, run_options).then((code) => { h.expect(code).to.equal(0); h.expect(options).to.have.property('vm', true); h.expect(options).to.have.property('status', true); h.expect(outputs[0]).to.match(RegExp(h.escapeRegExp('Virtual machine running.'))); }); }); it("should run a vm installed command", function() { doc_opts.argv = ['vm', 'installed']; var options = cli.router.cleanParams(cli.docopt(doc_opts)); return cli.run(doc_opts, run_options).then((code) => { h.expect(code).to.equal(0); h.expect(options).to.have.property('vm', true); h.expect(options).to.have.property('installed', true); h.expect(outputs[0]).to.match(RegExp(h.escapeRegExp('Virtual machine already installed.'))); }); }); it("should run a `vm ssh -- echo test` command", function() { doc_opts.argv = `vm ssh -- echo test`.split(' '); var options = cli.router.cleanParams(cli.docopt(doc_opts)); return cli.run(doc_opts, run_options).then((code) => { h.expect(code).to.equal(0); h.expect(options).to.have.property('vm', true); h.expect(options).to.have.property('ssh', true); h.expect(options).to.have.property('__doubledash', true); h.expect(options['ssh-args']).to.deep.eql(['echo', 'test']); h.expect(outputs[0]).to.match(RegExp(h.escapeRegExp('test'))); }); }); });
describe('_isBranchOrTag:', function () { var outputs = []; var ui = h.mockUI(beforeEach, outputs); var getProject = new GetProject(ui); it('should check if is a valid branch or tag name', function() { var input_array = [ { commit: '284b608a5b9301c3df8e4ddcf371ff74eec2d754', git_ref: 'HEAD' }, { commit: '24af92c4701b6bb45c314e8b62be785b595ba74f', git_ref: 'feature/adding_services' }, { commit: '9fa9093f65e110ae036341861c0e8801e03591e1', git_ref: 'final' }, { commit: '284b608a5b9301c3df8e4ddcf371ff74eec2d754', git_ref: 'master' }, { commit: 'b6852f0c25461b2cc376b5339975a16747b412f8', git_ref: 'two' }, { commit: 'f1ae4ba97ac97e615bb3e0d718e0565c3d303dcb', git_ref: 'v0.1.2' }, { commit: 'b6852f0c25461b2cc376b5339975a16747b412f8', git_ref: 'v0.1.2^{}' }, ]; h.expect(getProject._isBranchOrTag(input_array, 'two')).to.be.true; h.expect(getProject._isBranchOrTag(input_array, 'v0.1.2')).to.be.true; h.expect(getProject._isBranchOrTag(input_array, 'HEAD')).to.be.true; h.expect(getProject._isBranchOrTag(input_array, 'NONE')).to.be.false; }); });
describe("Azk command info, run in an", function() { var outputs = []; var UI = h.mockUI(beforeEach, outputs); var cmd = init(UI); describe("invalid SoS dir", function() { it("should return error if not have manifest", function() { return h.tmp_dir().then((dir) => { cmd.cwd = dir; return h.expect(cmd.run()).to.rejectedWith(ManifestRequiredError); }); }); }); describe("valid SoS dir", function() { var manifest; before(() => { var data = { }; return h.mockManifest(data).then((mf) => { manifest = mf; }); }); it("should show systems information", function() { cmd.cwd = manifest.manifestPath; return cmd.run().then(() => { var rx_manifest = RegExp("manifest:.*" + h.escapeRegExp(manifest.file)); h.expect(outputs[0]).to.match(rx_manifest); var rx_cache = RegExp("cache_dir:.*" + h.escapeRegExp(manifest.cache_dir)); h.expect(outputs[0]).to.match(rx_cache); var rx_default = RegExp("default_system:.*" + h.escapeRegExp(manifest.default_system)); h.expect(outputs[0]).to.match(rx_default); var rx_name = RegExp(`${h.escapeRegExp("example".yellow)}:`); h.expect(outputs[0]).to.match(rx_name); h.expect(outputs[0]).to.match(RegExp(config('docker:image_default'))); h.expect(outputs[0]).to.match(/command:.*socat/); }); }); }); });
describe('Azk generator generation two nodes systems', function() { var outputs = []; var UI = h.mockUI(beforeEach, outputs); var generator = new Generator(UI); var rootFolder; before(function() { return h.tmp_dir().then((dir) => { rootFolder = dir; // `node 1` system folder var projectFolder = path.join(dir, 'node1'); fs.mkdirSync(projectFolder); var packageJson = path.join(projectFolder, 'package.json'); h.touchSync(packageJson); // `node 2` system folder projectFolder = path.join(dir, 'node2'); fs.mkdirSync(projectFolder); packageJson = path.join(projectFolder, 'package.json'); h.touchSync(packageJson); return qfs.write(packageJson, ''); }); }); var generateAndReturnManifest = (project) => { var manifest = path.join(project, config('manifest')); generator.render({ systems: generator.findSystems(project), }, manifest); return new Manifest(project); }; it('should detect two node projects', function() { var manifest = generateAndReturnManifest(rootFolder); var allKeys = Object.keys(manifest.systems); h.expect(allKeys).to.have.contains('node1'); h.expect(allKeys).to.have.contains('node2'); }); });
return async(this, function* () { var outputs = []; var UI = h.mockUI(beforeEach, outputs); var dir = yield h.tmp_dir(); // Gemfile rootFullPath = dir; var frontFolder = path.join(rootFullPath, 'front'); yield fsAsync.mkdirs(frontFolder); var gemfilePath = path.join(frontFolder, 'Gemfile'); var gemfileContent = [ 'source \'https://rubygems.org\'', '', 'gem \'rails\', \'4.1.6\'', 'gem \'pg\', \'~> 0.17.1\'', ].join('\n'); yield fsAsync.writeFile(gemfilePath, gemfileContent); // package.json var apiFolder = path.join(rootFullPath, 'api'); yield fsAsync.mkdirs(apiFolder); var packageJsonPath = path.join(apiFolder, 'package.json'); var packageJsonContent = [ '{', ' "name": "best-practices",', ' "description": "A package using versioning best-practices",', ' "author": "Charlie Robbins <*****@*****.**>",', ' "dependencies": {', ' "colors": "0.x.x",', ' "express": "2.3.x",', ' "optimist": "0.2.x"', ' },', ' "devDependencies": {', ' "vows": "0.5.x"', ' },', ' "engine": "node >= 0.4.1"', '}', ].join('\n'); yield fsAsync.writeFile(packageJsonPath, packageJsonContent); var realRulesFolder = path.join(__dirname, '../../azk/generator/rules'); court = new Court(realRulesFolder, UI); });
h.describeRequireVm('Azk cli, docker controller', function() { var outputs = []; var ui = h.mockUI(beforeEach, outputs); var cli_options = {}; var cli = new Cli(cli_options).route('docker'); var doc_opts = { exit: false }; var run_options = { ui: ui, cwd: __dirname }; it("should run a `docker -- version` command", function() { doc_opts.argv = ['docker', '--', 'version']; var options = cli.router.cleanParams(cli.docopt(doc_opts)); return cli.run(doc_opts, run_options).then((code) => { h.expect(code).to.equal(0); h.expect(options).to.have.property('docker', true); h.expect(options).to.have.property('__doubledash', true); h.expect(options['docker-args']).to.deep.eql(['version']); h.expect(outputs[0]).to.match(RegExp(h.escapeRegExp("\"docker\" \"version\""))); }); }); });
describe("Spawn Helper", function() { let outputs = []; let ui = h.mockUI(beforeEach, outputs); let stdOut = ui.stdout().write.bind(ui); it("should printOutput do not print if verbose_level = 0", function() { lazy.printOutput(stdOut, 0, '[azk]', 'DATA'); h.expect(outputs.length).to.equal(0); }); it("should printOutput print if verbose_level = 1", function() { lazy.printOutput(stdOut, 1, '[azk]', 'DATA'); h.expect(outputs[0]).to.match(/\[azk\] DATA/); }); it("should spawnAsync should return result even without scanFunction", function() { const spawnAsync_promise = lazy.spawnAsync('git', ['--version'], undefined); return spawnAsync_promise.then((result) => { h.expect(result.error_code).to.equal(0); h.expect(result.message).to.match(/git version/); h.expect(outputs.length).to.equal(0); }); }); it("should spawnAsync should return result and call scanFunction", function() { const scanFunction = stdOut; const spawnAsync_promise = lazy.spawnAsync('git', ['--version'], scanFunction); return spawnAsync_promise.then((result) => { h.expect(result.error_code).to.equal(0); h.expect(result.message).to.match(/git version/); h.expect(outputs[0]).to.equal('$> git --version'); h.expect(outputs[1]).to.match(/git version/); }); }); });
describe('Azk generators Postgres rule', function() { var outputs = []; var UI = h.mockUI(beforeEach, outputs); var rule; before(function() { outputs = []; UI = h.mockUI(beforeEach, outputs); rule = new Rule(UI); }); it('should find a pg database', () => { var gemfilePath = '/tmp/azk-test-30501680wvr4/front/Gemfile'; var gemfileContent = [ 'source \'https://rubygems.org\'', 'gem \'rails\', \'4.1.6\'', 'gem \'pg\', \'~> 0.17.1\'', ].join('\n'); var evidence = rule.getEvidence(gemfilePath, gemfileContent); h.expect(evidence).to.have.property('name', 'postgres'); }); });
describe("Azk generator tool", function() { var outputs = []; var UI = h.mockUI(beforeEach, outputs); var generator = new Generator(UI); it("should load default rules", function() { var node = generator.rule("node"); h.expect(node).to.have.property("type", "runtime"); }); describe("run in a directory", function() { var dir; before(() => { return h.tmp_dir().then((tmp) => { dir = tmp; }); }); // Genereate manifest file var generate_manifest = (dir, data) => { var file = path.join(dir, config('manifest')); generator.render(data, file); return new Manifest(dir); }; var default_data = { systems: { front: { depends: ['db'], workdir: '/azk/#{manifest.dir}', image: { repository: 'base', tag: '0.1' }, scalable: true, http: true, mount_folders: { ".": "/azk/#{manifest.dir}", }, command: 'bundle exec rackup config.ru', envs: { RACK_ENV: 'dev' }, }, db: { image: "base", export_envs: { DB_URL: "#{envs.USER}:#{envs.PASSWORD}@#{net.host}:#{net.port.3666}" } } }, defaultSystem: 'front', bins: [ { name: "console", command: ["bundler", "exec"] } ] }; it("should generate with a valid format", function() { var extra = _.merge({}, default_data, { systems: { front: { envs: { "F-O_O": "BAR"}, scalable: { default: 3}} } }); var manifest = generate_manifest(dir, extra); var data = fs.readFileSync(manifest.file).toString(); h.expect(data).to.match(/^\s{2}db: {$/m); h.expect(data).to.match(/^\s{6}RACK_ENV: "dev",$/m); h.expect(data).to.match(/^\s{6}'F-O_O': "BAR",$/m); }); it("should expand image build steps", function() { var extra = _.merge({}, default_data, { systems: { front: { image: { build: [ "run step 1", ["run", "step 2"], ] } } } }); var manifest = generate_manifest(dir, extra); var data = fs.readFileSync(manifest.file).toString(); h.expect(data).to.match(/^\s{2}db: {$/m); h.expect(data).to.match(/^\s{6}build: \[$/m); h.expect(data).to.match(/^\s{8}"run step 1",$/m); h.expect(data).to.match(/^\s{8}\["run"\, "step 2"\],$/m); }); it("should generete a valid manifest file", function() { var manifest = generate_manifest(dir, default_data); var system = manifest.systemDefault; var name = path.basename(dir); h.expect(system).to.have.deep.property("name", "front"); h.expect(system).to.have.deep.property("image.name", "base:0.1"); h.expect(system).to.have.deep.property("depends").and.to.eql(["db"]); h.expect(system).to.have.deep.property("options.workdir", "/azk/" + name); h.expect(system).to.have.deep.property("options.scalable").and.ok; h.expect(system).to.have.deep.property("options.mount_folders") .and.to.eql({ ".": "/azk/" + name}); h.expect(system).to.have.deep.property("options.command") .and.to.eql("bundle exec rackup config.ru"); }); it("should generate export envs", function() { var manifest = generate_manifest(dir, default_data); var system = manifest.system('db'); h.expect(system).to.have.deep.property("options.export_envs") .and.to.eql({ DB_URL: "#{envs.USER}:#{envs.PASSWORD}@#{net.host}:#{net.port.3666}" }); }); it("should support instances in scalable", function() { var data = _.merge({}, default_data, { systems: { front: { scalable: { default: 5 } } }}); var manifest = generate_manifest(dir, data); var system = manifest.systemDefault; h.expect(system).to.have.deep.property("options.scalable").and.eql({ default: 5}); }); }); });
describe('Azk generators Ruby rule', function() { var outputs = []; var UI = h.mockUI(beforeEach, outputs); var rule; before(function() { outputs = []; UI = h.mockUI(beforeEach, outputs); rule = new Rule(UI); }); it('should return an evidence object', () => { var gemfilePath = '/tmp/azk-test-30501680wvr4/front/Gemfile'; var gemfileContent = [ 'source \'https://rubygems.org\'', 'ruby \'1.9.3\'', ].join('\n'); var evidence = rule.getEvidence(gemfilePath, gemfileContent); h.expect(evidence).to.have.deep.property('fullpath', gemfilePath); h.expect(evidence).to.have.deep.property('ruleType', 'runtime'); h.expect(evidence).to.have.deep.property('name' , 'ruby'); h.expect(evidence).to.have.deep.property('ruleName', 'ruby19'); h.expect(evidence).to.have.deep.property('version' , '1.9.3'); }); it('should get latest ruby version when do not found engine', () => { var gemfilePath = '/tmp/azk-test-30501680wvr4/front/Gemfile'; var gemfileContent = [ 'source \'https://rubygems.org\'', ].join('\n'); var evidence = rule.getEvidence(gemfilePath, gemfileContent); h.expect(evidence).to.have.deep.property('ruleName', 'ruby21'); }); it('should get latest ruby version when version is too low', () => { var gemfilePath = '/tmp/azk-test-30501680wvr4/front/Gemfile'; var gemfileContent = [ 'source \'https://rubygems.org\'', 'ruby \'1.8.1\'', ].join('\n'); var evidence = rule.getEvidence(gemfilePath, gemfileContent); h.expect(evidence).to.have.deep.property('ruleName', 'ruby21'); }); it('should get 1.9 ruby version when detected', () => { var gemfilePath = '/tmp/azk-test-30501680wvr4/front/Gemfile'; var gemfileContent = [ 'source \'https://rubygems.org\'', 'ruby \'1.9.3\'', ].join('\n'); var evidence = rule.getEvidence(gemfilePath, gemfileContent); h.expect(evidence).to.have.deep.property('ruleName', 'ruby19'); }); it('should get 2.0 ruby version when detected', () => { var gemfilePath = '/tmp/azk-test-30501680wvr4/front/Gemfile'; var gemfileContent = [ 'source \'https://rubygems.org\'', 'ruby \'2.0.0\'', ].join('\n'); var evidence = rule.getEvidence(gemfilePath, gemfileContent); h.expect(evidence).to.have.deep.property('ruleName', 'ruby20'); }); it('should get 2.1 ruby version when detected', () => { var gemfilePath = '/tmp/azk-test-30501680wvr4/front/Gemfile'; var gemfileContent = [ 'source \'https://rubygems.org\'', 'ruby \'2.1.0\'', ].join('\n'); var evidence = rule.getEvidence(gemfilePath, gemfileContent); h.expect(evidence).to.have.deep.property('ruleName', 'ruby21'); }); it('should get jruby if detected', () => { var gemfilePath = '/tmp/azk-test-30501680wvr4/front/Gemfile'; var gemfileContent = [ 'source \'https://rubygems.org\'', 'ruby \'1.9.3\', :engine => \'jruby\', :engine_version => \'1.7.16\'', ].join('\n'); var evidence = rule.getEvidence(gemfilePath, gemfileContent); h.expect(evidence).to.have.deep.property('ruleName', 'jruby17'); }); });
describe('Azk generator tool index:', function() { var outputs = []; var UI = h.mockUI(beforeEach, outputs); var generator = new Generator(UI); describe('run in a directory', function() { var dir; before(() => { return h.tmp_dir().then((tmp) => { dir = tmp; }); }); // Generates manifest file var generate_manifest = (dir, data) => { var file = path.join(dir, config('manifest')); generator.render(data, file); var manifest = new Manifest(dir); return manifest; }; var export_db = '#{envs.USER}:#{envs.PASSWORD}@#{net.host}:#{net.port.3666}'; var default_data = { systems: { front: { depends: ['db'], workdir: '/azk/#{manifest.dir}', image: { provider: 'docker', repository: 'base', tag: '0.1' }, scalable: true, http: true, mounts: { '/azk/root': '/', '/azk/#{manifest.dir}': { type: 'path', value: '.' }, '/azk/data': { type: 'persistent', value: 'data' }, }, command: 'bundle exec rackup config.ru', envs: { RACK_ENV: 'dev' }, }, db: { image: { docker: 'base' }, export_envs: { DB_URL: export_db } } }, defaultSystem: 'front', bins: [ { name: 'console', command: ['bundler', 'exec'] } ] }; it('should generate with a valid format', function() { var extra = _.merge({}, default_data, { systems: { front: { envs: { 'F-O_O': 'BAR'}, scalable: { default: 3 }} } }); var manifest = generate_manifest(dir, extra); var data = fs.readFileSync(manifest.file).toString(); h.expect(data).to.match(/^\s{2}db: {$/m); h.expect(data).to.match(/^\s{6}RACK_ENV: "dev",$/m); h.expect(data).to.match(/^\s{6}'F-O_O': "BAR",$/m); }); it('should generete a valid manifest file', function() { var manifest = generate_manifest(dir, default_data); var system = manifest.systemDefault; var name = path.basename(dir); h.expect(system).to.have.deep.property('name', 'front'); h.expect(system).to.have.deep.property('image.name', 'base:0.1'); h.expect(system).to.have.deep.property('depends').and.to.eql(['db']); h.expect(system).to.have.deep.property('options.workdir', '/azk/' + name); h.expect(system).to.have.deep.property('options.scalable').and.ok; h.expect(system).to.have.deep.property('options.command') .and.to.eql('bundle exec rackup config.ru'); }); it('should generate a mounts options', function() { var manifest = generate_manifest(dir, default_data); var system = manifest.systemDefault; var name = path.basename(dir); var persist_base = config('paths:persistent_folders'); persist_base = path.join(persist_base, manifest.namespace); var mounts = system.mounts; h.expect(system).to.have.property('mounts'); if (config('agent:requires_vm')) { h.expect(mounts).to.have.property('/azk/root', config('agent:vm:mount_point') + '/'); } else { h.expect(mounts).to.have.property('/azk/root', '/'); } h.expect(mounts).to.have.property('/azk/' + name, utils.docker.resolvePath(manifest.manifestPath)); h.expect(mounts).to.have.property('/azk/data', path.join(persist_base, 'data')); }); it('should generate export envs', function() { var manifest = generate_manifest(dir, default_data); var system = manifest.system('db'); h.expect(system).to.have.deep.property('options.export_envs') .and.to.eql({ DB_URL: '#{envs.USER}:#{envs.PASSWORD}@#{net.host}:#{net.port.3666}' }); }); it('should support instances in scalable', function() { var data = _.merge({}, default_data, { systems: { front: { scalable: { default: 5 } } }}); var manifest = generate_manifest(dir, data); var system = manifest.systemDefault; h.expect(system).to.have.deep.property('options.scalable') .and.eql({ default: 5}); }); describe('with httop options', function() { it('should generate a simple default host name', function() { var manifest = generate_manifest(dir, default_data); var system = manifest.systemDefault; var re_domain = RegExp(h.escapeRegExp(`${system.name}.${config('agent:balancer:host')}`)); h.expect(system).to.have.deep.property('hosts').and.length(1); h.expect(system).to.have.deep.property('hosts[0]').and.match(re_domain); }); it('should generate a multiple hosts', function() { var data = _.clone(default_data); data.systems.front.http = [ '#{system.name}.#{azk.default_domain}', 'custom.#{azk.default_domain}', ]; var manifest = generate_manifest(dir, data); var system = manifest.systemDefault; var re_default = RegExp(h.escapeRegExp(`${system.name}.${config('agent:balancer:host')}`)); var re_custom = RegExp(h.escapeRegExp(`custom.${config('agent:balancer:host')}`)); h.expect(system).to.have.deep.property('hosts').and.length(2); h.expect(system).to.have.deep.property('hosts[0]').and.match(re_default); h.expect(system).to.have.deep.property('hosts[1]').and.match(re_custom); }); }); }); });
describe('Azk generator generation mysql rule', function() { var outputs = []; var UI = h.mockUI(beforeEach, outputs); var generator = new Generator(UI); var projectFolder; var createTestFolders = h.tmp_dir().then((dir) => { // ------- // Gemfile // ------- projectFolder = path.join(dir, 'project'); fs.mkdirSync(projectFolder); var gemfilePath = path.join(projectFolder, 'Gemfile'); h.touchSync(gemfilePath); var gemfileContent = [ 'source \'https://rubygems.org\'', '', 'gem \'rails\', \'4.1.6\'', 'gem \'mysql2\'', ].join('\n'); return qfs.write(gemfilePath, gemfileContent); }); before(function() { return createTestFolders; }); var generateAndReturnManifest = (project) => { var manifest = path.join(project, config('manifest')); generator.render({ systems: generator.findSystems(project), }, manifest); return new Manifest(project); }; it('should detect single mysql system', function() { var manifest = generateAndReturnManifest(projectFolder); var mysqlSystem = manifest.systems.mysql; h.expect(mysqlSystem).to.have.deep.property('name', 'mysql'); h.expect(mysqlSystem).to.have.deep.property('image.name', 'azukiapp/mysql:5.6'); h.expect(mysqlSystem).to.have.deep.property('depends').and.to.eql([]); h.expect(mysqlSystem).to.have.deep.property('options.envs.MYSQL_ROOT_PASSWORD', 'mysecretpassword'); h.expect(mysqlSystem).to.have.deep.property('options.envs.MYSQL_USER', 'azk'); h.expect(mysqlSystem).to.have.deep.property('options.envs.MYSQL_PASS', 'azk'); h.expect(mysqlSystem).to.have.deep.property('options.envs.MYSQL_DATABASE', 'mysql_development'); h.expect(mysqlSystem).to.not.have.deep.property('options.provision'); h.expect(mysqlSystem).to.not.have.deep.property('options.command'); h.expect(mysqlSystem).to.not.have.deep.property('options.workdir'); }); it('should rails have a mysql dependency', function() { var manifest = generateAndReturnManifest(projectFolder); var railsSystem = manifest.systems.project; h.expect(railsSystem).to.have.deep.property('name', 'project'); h.expect(railsSystem).to.have.deep.property('depends').and.to.eql(['mysql']); }); });
describe('Azk cli, config controller', function() { let outputs = []; let ui = h.mockUI(beforeEach, outputs); let cli_options = {}; let cli = new Cli(cli_options) .route('config'); let doc_opts = { exit: false }; let run_options = { ui: ui }; process.env.AZK_DISABLE_TRACKER = true; let configuration = null; before(() => configuration = new lazy.Configuration()); beforeEach(() => configuration.resetAll()); it("should azk config list show all config", function() { doc_opts.argv = ['config', 'list']; let options = cli.router.cleanParams(cli.docopt(doc_opts)); return cli.run(doc_opts, run_options).then((code) => { h.expect(code).to.equal(0); h.expect(options).to.have.property('config', true); let ui_result = outputs.join("\n"); h.expect(ui_result).to.match(/user\.email/); h.expect(ui_result).to.match(/crash_reports\.always_send/); }); }); it("should azk config list show user.email configuration status", function() { doc_opts.argv = ['config', 'list', 'user.email']; let options = cli.router.cleanParams(cli.docopt(doc_opts)); return cli.run(doc_opts, run_options).then((code) => { h.expect(code).to.equal(0); h.expect(options).to.have.property('config', true); let ui_result = outputs.join("\n"); h.expect(ui_result).to.match(/user\.email.*\s.*/); h.expect(ui_result).not.to.match(/crash_reports\.always_send/); }); }); it("should support set string a configuration", function() { let key = 'user.email'; let value = '*****@*****.**'; doc_opts.argv = ['config', 'set', key, value]; return cli.run(doc_opts, run_options).then((code) => { h.expect(code).to.equal(0); let ui_result = outputs.join("\n"); let msg_regex = h.regexFromT('commands.config.set_ok', { key, value }); h.expect(ui_result).to.match(msg_regex); }); }); it("should support set boolean a configuration", function() { let key = 'user.email_always_ask'; let value = 'false'; doc_opts.argv = ['config', 'set', key, value]; // check: config set return cli.run(doc_opts, run_options).then((code) => { h.expect(code).to.equal(0); let ui_result = outputs.join("\n"); let msg_regex = h.regexFromT('commands.config.set_ok', { key, value }); h.expect(ui_result).to.match(msg_regex); // check: config list doc_opts.argv = ['config', 'list', 'user.email_always_ask']; let options = cli.router.cleanParams(cli.docopt(doc_opts)); return cli.run(doc_opts, run_options).then((code) => { h.expect(code).to.equal(0); h.expect(options).to.have.property('config', true); ui_result = outputs.join("\n"); h.expect(ui_result).to.match(/user\.email_always_ask.+\[Y\/N\].+N/gm); }); }); }); it("should support reset all configuration", function() { configuration.save('user.email', '*****@*****.**'); doc_opts.argv = ['config', 'reset']; return cli.run(doc_opts, run_options).then((code) => { let value = configuration.load('user.email'); h.expect(value).to.undefined; h.expect(code).to.equal(0); let ui_result = outputs.join("\n"); let msg_regex = h.regexFromT('commands.config.reset.confirmed'); h.expect(ui_result).to.match(msg_regex); }); }); });
describe('Azk cli, deploy controller run command', function () { var outputs = []; var ui = h.mockUI(beforeEach, outputs); var cli_options = {}; var doc_opts = { exit: false }; var run_options = { ui: ui, cwd: h.fixture_path('slim-app'), just_parse: true }; var cli = new Cli(cli_options) .route('deploy', null, function() { return (new (DeployTest)(this)).index(); }); it("`deploy`", function() { doc_opts.argv = ['deploy']; var options = cli.router.cleanParams(cli.docopt(doc_opts)); return cli.run(doc_opts, run_options).then((code) => { h.expect(code).to.equal(0); h.expect(options).to.have.property('deploy', true); h.expect(outputs[0]).to.match(RegExp(h.escapeRegExp('shell deploy'))); }); }); it("`deploy clear-cache`", function() { doc_opts.argv = ['deploy', 'clear-cache']; var options = cli.router.cleanParams(cli.docopt(doc_opts)); return cli.run(doc_opts, run_options).then((code) => { h.expect(code).to.equal(0); h.expect(options).to.have.property('deploy', true); h.expect(options).to.have.property('clear-cache', true); h.expect(outputs[0]).to.match(RegExp(h.escapeRegExp('shell deploy -- clear-cache'))); }); }); it("`deploy fast`", function() { doc_opts.argv = ['deploy', 'fast']; var options = cli.router.cleanParams(cli.docopt(doc_opts)); return cli.run(doc_opts, run_options).then((code) => { h.expect(code).to.equal(0); h.expect(options).to.have.property('deploy', true); h.expect(options).to.have.property('fast', true); h.expect(outputs[0]).to.match(RegExp(h.escapeRegExp('shell deploy -- fast'))); }); }); it("`deploy full`", function() { doc_opts.argv = ['deploy', 'full']; var options = cli.router.cleanParams(cli.docopt(doc_opts)); return cli.run(doc_opts, run_options).then((code) => { h.expect(code).to.equal(0); h.expect(options).to.have.property('deploy', true); h.expect(options).to.have.property('full', true); h.expect(outputs[0]).to.match(RegExp(h.escapeRegExp('shell deploy -- full'))); }); }); it("`deploy restart`", function() { doc_opts.argv = ['deploy', 'restart']; var options = cli.router.cleanParams(cli.docopt(doc_opts)); return cli.run(doc_opts, run_options).then((code) => { h.expect(code).to.equal(0); h.expect(options).to.have.property('deploy', true); h.expect(options).to.have.property('restart', true); h.expect(outputs[0]).to.match(RegExp(h.escapeRegExp('shell deploy -- restart'))); }); }); it("`deploy ssh`", function() { doc_opts.argv = ['deploy', 'ssh']; var options = cli.router.cleanParams(cli.docopt(doc_opts)); return cli.run(doc_opts, run_options).then((code) => { h.expect(code).to.equal(0); h.expect(options).to.have.property('deploy', true); h.expect(options).to.have.property('ssh', true); h.expect(outputs[0]).to.match(RegExp(h.escapeRegExp('shell deploy --tty -- ssh'))); }); }); it("`deploy ssh -- echo data`", function() { doc_opts.argv = ['deploy', 'ssh', '--', "-c 'echo data'"]; var options = cli.router.cleanParams(cli.docopt(doc_opts)); return cli.run(doc_opts, run_options).then((code) => { h.expect(code).to.equal(0); h.expect(options).to.have.property('deploy', true); h.expect(options).to.have.property('ssh', true); h.expect(options).to.have.property('__doubledash', true); h.expect(options.args).to.deep.eql(["-c 'echo data'"]); h.expect(outputs[0]).to.match(RegExp(h.escapeRegExp("shell deploy -- ssh -c 'echo data'"))); }); }); it("`deploy shell`", function() { doc_opts.argv = ['deploy', 'shell']; var options = cli.router.cleanParams(cli.docopt(doc_opts)); return cli.run(doc_opts, run_options).then((code) => { h.expect(code).to.equal(0); h.expect(options).to.have.property('deploy', true); h.expect(options).to.have.property('shell', true); h.expect(outputs[0]).to.match(RegExp(h.escapeRegExp('shell deploy --tty -- shell'))); }); }); it("`deploy shell -- echo data`", function() { doc_opts.argv = ['deploy', 'shell', '--', 'echo data']; var options = cli.router.cleanParams(cli.docopt(doc_opts)); return cli.run(doc_opts, run_options).then((code) => { h.expect(code).to.equal(0); h.expect(options).to.have.property('deploy', true); h.expect(options).to.have.property('shell', true); h.expect(options).to.have.property('__doubledash', true); h.expect(options.args).to.deep.eql(['echo data']); h.expect(outputs[0]).to.match(RegExp(h.escapeRegExp('shell deploy -- shell echo data'))); }); }); it("`deploy versions`", function() { doc_opts.argv = ['deploy', 'versions']; var options = cli.router.cleanParams(cli.docopt(doc_opts)); return cli.run(doc_opts, run_options).then((code) => { h.expect(code).to.equal(0); h.expect(options).to.have.property('deploy', true); h.expect(options).to.have.property('versions', true); h.expect(outputs[0]).to.match(RegExp(h.escapeRegExp('shell deploy -- versions'))); }); }); it("`deploy rollback`", function() { doc_opts.argv = ['deploy', 'rollback']; var options = cli.router.cleanParams(cli.docopt(doc_opts)); return cli.run(doc_opts, run_options).then((code) => { h.expect(code).to.equal(0); h.expect(options).to.have.property('deploy', true); h.expect(options).to.have.property('rollback', true); h.expect(outputs[0]).to.match(RegExp(h.escapeRegExp('shell deploy -- rollback'))); }); }); it("`deploy rollback <ref>`", function() { doc_opts.argv = ['deploy', 'rollback', 'v2']; var options = cli.router.cleanParams(cli.docopt(doc_opts)); return cli.run(doc_opts, run_options).then((code) => { h.expect(code).to.equal(0); h.expect(options).to.have.property('deploy', true); h.expect(options).to.have.property('rollback', true); h.expect(options).to.have.property('ref', "v2"); h.expect(outputs[0]).to.match(RegExp(h.escapeRegExp('shell deploy -- rollback v2'))); }); }); it("`invalid` and should error", function() { doc_opts.argv = ['deploy', 'invalid']; var func = () => cli.docopt(doc_opts); h.expect(func).to.throw(InvalidCommandError, /deploy invalid/); }); describe("without deploy system", function() { var manifest; var cli = new Cli(cli_options) .route('deploy'); before(() => { var data = { }; return h.mockManifest(data).then((mf) => { manifest = mf; }); }); it("should raise error if no get deploy system", function() { var func = () => manifest.getSystemsByName("deploy"); h.expect(func).to.throw(SystemNotFoundError, /deploy/); }); it("should no deploy system", function() { doc_opts.argv = ['deploy']; var run_options = { ui: ui, cwd: manifest.cwd, just_parse: true }; var result = cli.run(doc_opts, run_options); return h.expect(result).to.be.rejectedWith(SystemNotFoundError, /deploy/); }); }); });
describe('Azk generator db', function() { var outputs = []; var UI = h.mockUI(beforeEach, outputs); var generator = new Generator(UI); var rootFolder; var rootFolderBasename; before(function() { return async(this, function* () { var dir; var projectFolder; var gemfilePath; var gemfileContent; dir = yield h.tmp_dir(); // save root dir rootFolder = dir; rootFolderBasename = path.basename(dir); // rails + mysql projectFolder = path.join(rootFolder, 'railsMysql'); yield fsAsync.mkdirs(projectFolder); gemfilePath = path.join(projectFolder, 'Gemfile'); gemfileContent = [ 'source \'https://rubygems.org\'', '', 'gem \'rails\', \'4.1.6\'', 'gem \'mysql2\'', ].join('\n'); yield fsAsync.writeFile(gemfilePath, gemfileContent); // rails + postgres projectFolder = path.join(rootFolder, 'railsPostgres'); yield fsAsync.mkdirs(projectFolder); gemfilePath = path.join(projectFolder, 'Gemfile'); gemfileContent = [ 'source \'https://rubygems.org\'', '', 'gem \'rails\', \'4.1.6\'', 'gem \'pg\'', ].join('\n'); yield fsAsync.writeFile(gemfilePath, gemfileContent); }); }); var generateAndReturnManifest = (project) => { var manifest = path.join(project, config('manifest')); return generator.findSystems(project) .then(function (all_systems) { return generator.render({ systems: all_systems }, manifest) .then(function() { return new Manifest(project); }); }); }; describe('2 rails and 2 databases', function() { var manifest; before(function() { return generateAndReturnManifest(rootFolder).then(function (manifest_generated) { manifest = manifest_generated; }); }); it('should detect 4 systems', function() { var allKeys = Object.keys(manifest.systems); h.expect(allKeys).to.have.length(4); h.expect(allKeys).to.have.contains('mysql'); h.expect(allKeys).to.have.contains('postgres'); h.expect(allKeys).to.have.contains('railsMysql'); h.expect(allKeys).to.have.contains('railsPostgres'); }); describe('mysql system', function() { var systemName; var system; before(function() { systemName = 'mysql'; system = manifest.systems[systemName]; }); it('should has correct properties', function() { // main properties h.expect(system).to.have.property('name', 'mysql'); h.expect(system).to.have.deep.property('image.repository', 'azukiapp/mysql'); h.expect(system).to.have.deep.property('image.tag', '5.6'); // __options h.expect(system).to.have.deep.property('options.depends').and.to.eql([]); h.expect(system).to.have.deep.property('options.shell', '/bin/bash'); h.expect(system).to.have.deep.property('options.wait', 150); h.expect(system).to.not.have.deep.property('options.workdir'); h.expect(system).to.have.deep.property('options.mounts').and.to.eql( { '/var/lib/mysql': { type: 'persistent', value: `${manifest.manifestDirName}/mysql`, options: {} } } ); }); }); describe('postgres system', function() { var systemName; var system; before(function() { systemName = 'postgres'; system = manifest.systems[systemName]; }); it('should has correct properties', function() { // main properties h.expect(system).to.have.property('name', 'postgres'); h.expect(system).to.have.deep.property('image.repository', 'azukiapp/postgres'); h.expect(system).to.have.deep.property('image.tag', '9.4'); // __options h.expect(system).to.have.deep.property('options.depends').and.to.eql([]); h.expect(system).to.have.deep.property('options.shell', '/bin/bash'); h.expect(system).to.have.deep.property('options.wait', 150); h.expect(system).to.not.have.deep.property('options.workdir'); h.expect(system).to.have.deep.property('options.mounts').and.to.eql( { '/var/lib/postgresql/data': { type: 'persistent', value: 'postgresql', options: {} }, '/var/log/postgresql': { type: 'path', value: './log/postgresql', options: {} } } ); }); }); describe('railsMysql system', function() { var systemName; var system; before(function() { systemName = 'railsMysql'; system = manifest.systems[systemName]; }); it('should has correct properties', function() { // main properties h.expect(system).to.have.property('name', 'railsMysql'); h.expect(system).to.have.deep.property('image.repository', 'azukiapp/ruby'); h.expect(system).to.have.deep.property('image.tag', 'latest'); // __options h.expect(system).to.have.deep.property('options.depends').and.to.eql(['mysql']); h.expect(system).to.have.deep.property('options.shell', '/bin/bash'); h.expect(system).to.have.deep.property('options.wait', 20); var workdir = path.join('/azk', rootFolderBasename, 'railsMysql'); h.expect(system).to.have.deep.property('options.workdir', workdir); var expectedMounts = {}; var folderSystem = `${rootFolderBasename}/${systemName}`; // /azk/azk-test-60957fmnsb4/railsPostgres expectedMounts[path.join('/azk', folderSystem)] = { type: 'sync', value: `./${systemName}`, options: {} }; expectedMounts[path.join('/azk', folderSystem, '.bundle')] = { type: 'path', value: `./${systemName}/.bundle`, options: {} }; expectedMounts[path.join('/azk', folderSystem, 'log')] = { type: 'path', value: `./${systemName}/log`, options: {} }; expectedMounts[path.join('/azk', folderSystem, 'tmp')] = { type: 'persistent', value: `./${systemName}/tmp`, options: {} }; expectedMounts['/azk/bundler'] = { type: 'persistent', value: `./${systemName}/bundler`, options: {} }; h.expect(system).to.have.deep.property('options.mounts').and.to.eql(expectedMounts); }); }); describe('railsPostgres system', function() { var systemName; var system; before(function() { systemName = 'railsPostgres'; system = manifest.systems[systemName]; }); it('should has correct properties', function() { // main properties h.expect(system).to.have.property('name', 'railsPostgres'); h.expect(system).to.have.deep.property('image.repository', 'azukiapp/ruby'); h.expect(system).to.have.deep.property('image.tag', 'latest'); // __options h.expect(system).to.have.deep.property('options.depends').and.to.eql(['postgres']); h.expect(system).to.have.deep.property('options.shell', '/bin/bash'); h.expect(system).to.have.deep.property('options.wait', 20); var workdir = path.join('/azk', rootFolderBasename, 'railsPostgres'); h.expect(system).to.have.deep.property('options.workdir', workdir); var expectedMounts = {}; var folderSystem = `${rootFolderBasename}/${systemName}`; // /azk/azk-test-60957fmnsb4/railsPostgres expectedMounts[path.join('/azk', folderSystem)] = { type: 'sync', value: `./${systemName}`, options: {} }; expectedMounts[path.join('/azk', folderSystem, '.bundle')] = { type: 'path', value: `./${systemName}/.bundle`, options: {} }; expectedMounts[path.join('/azk', folderSystem, 'log')] = { type: 'path', value: `./${systemName}/log`, options: {} }; expectedMounts[path.join('/azk', folderSystem, 'tmp')] = { type: 'persistent', value: `./${systemName}/tmp`, options: {} }; expectedMounts['/azk/bundler'] = { type: 'persistent', value: `./${systemName}/bundler`, options: {} }; h.expect(system).to.have.deep.property('options.mounts').and.to.eql(expectedMounts); }); }); }); });
describe("Azk command init", function() { var manifest = config('manifest'); var outputs = []; var UI = h.mockUI(beforeEach, outputs); var cmd = init(UI); describe("run in a project already has a manifest", function() { var project; before(() => { return h.tmp_dir().then((dir) => { project = dir; cmd.cwd = project; h.touchSync(path.join(project, manifest)); }); }); it("should fail", function() { var message = t("commands.init.already", manifest); return cmd.run([]).then((code) => { h.expect(code).to.equal(1); h.expect(outputs[0]).to.match(RegExp(h.escapeRegExp(message))); }); }); it("should sucess if --force is passed", function() { var message = t("commands.init.already", manifest); return cmd.run(["--force"]).then((code) => { h.expect(code).to.equal(0); h.expect(outputs[0]).to.not.match(RegExp(h.escapeRegExp(message))); }); }); }); it("should generate a manifest with a example system in a blank dir", function() { return h.tmp_dir().then((project) => { cmd.cwd = project; return cmd.run([]).then(() => { // Check generated manifest var manifest = new Manifest(project); var system = manifest.systemDefault; var name = path.basename(project); h.expect(system).to.have.deep.property("name", "example"); h.expect(system).to.have.deep.property("image.name", "[repository]:[tag]"); h.expect(system).to.have.deep.property("depends").and.to.eql([]); h.expect(system).to.have.deep.property("mounts") .and.to.eql({ ["/azk/" + name]: utils.docker.resolvePath(manifest.manifestPath) }); h.expect(system).to.have.deep.property("options.workdir", "/azk/" + name); h.expect(system).to.have.deep.property("options.command") .and.to.eql("# command to run app"); h.expect(system).to.have.deep.property("options.envs") .and.to.eql({ EXAMPLE: "value" }); // Check messages var message = t("commands.init.not_found"); h.expect(outputs[0]).to.match(RegExp(h.escapeRegExp(message))); }); }); }); });
describe('Azk cli, init controller', function() { var outputs = []; var ui = h.mockUI(beforeEach, outputs); var manifest = config('manifest'); var cli_options = {}; var cli = new Cli(cli_options) .route('init'); var doc_opts = { exit: false }; var run_options = { ui: ui }; it("should return manifest filename", function() { doc_opts.argv = ['init', '--filename']; var options = cli.docopt(doc_opts); return cli.run(doc_opts, run_options).then((code) => { h.expect(options).to.have.property('--filename', true); h.expect(code).to.equal(0); h.expect(outputs[0]).to.equal(config('manifest')); }); }); describe("run in a project already has a manifest", function() { var message = t("commands.init.already_exists", manifest); before(() => { return h.tmp_dir().then((project) => { run_options.cwd = project; return fsAsync.createFile(path.join(project, manifest)); }); }); it("should fail", function() { doc_opts.argv = ['init']; var options = cli.router.cleanParams(cli.docopt(doc_opts)); return cli.run(doc_opts, run_options).then((code) => { h.expect(code).to.equal(1); h.expect(options).to.have.property('init', true); h.expect(options).to.have.property('path', null); h.expect(outputs[0]).to.match(RegExp(h.escapeRegExp(message))); }); }); it("should sucess if --force is passed", function() { doc_opts.argv = ['init', '--force']; var options = cli.docopt(doc_opts); return cli.run(doc_opts, run_options).then((code) => { h.expect(options).to.have.property('--force', true); h.expect(code).to.equal(0); h.expect(outputs[0]).to.not.match(RegExp(h.escapeRegExp(message))); }); }); }); it("should generate a manifest with a example system in a blank dir", function() { return h.tmp_dir().then((project) => { doc_opts.argv = ['init']; run_options.cwd = project; var options = cli.router.cleanParams(cli.docopt(doc_opts)); // Check generated manifest return cli.run(doc_opts, run_options).then((code) => { var manifest = new Manifest(project); var system = manifest.systemDefault; var name = path.basename(project); h.expect(code).to.equal(0); h.expect(options).to.have.property('path', null); h.expect(options).to.have.property('filename', false); h.expect(system).to.have.deep.property("name", "example"); h.expect(system).to.have.deep.property("image.name", "[repository]:[tag]"); h.expect(system).to.have.deep.property("depends").and.to.eql([]); var obj = {}; obj[`/azk/${name}`] = utils.docker.resolvePath(manifest.manifestPath); h.expect(system).to.have.deep.property("options.workdir", `/azk/${name}`); h.expect(system).to.have.deep.property("mounts" ).and.to.eql(obj); h.expect(system).to.have.deep.property("options.command").and.to.eql("# command to run app"); h.expect(system).to.have.deep.property("options.envs" ).and.to.eql({ EXAMPLE: "value" }); // Check messages var message = t("commands.init.not_found"); h.expect(outputs[0]).to.match(RegExp(h.escapeRegExp(message))); }); }); }); });
before(function() { outputs = []; UI = h.mockUI(beforeEach, outputs); rule = new Rule(UI); });
describe('Azk cli, main controller', function() { var outputs = []; var ui = h.mockUI(beforeEach, outputs); class TestCliController extends CliController { index(opts) { this.verbose_msg(1, 'nivel-1'); this.verbose_msg(2, 'nivel-2'); this.verbose_msg(3, () => { this.ui.dir('nivel-3'); }); this.ui.dir(opts); return promiseResolve(0); } verbose(data) { this.ui.dir(data); } run(...args) { while (outputs.length > 0) { outputs.pop(); } return super.run_action(...args); } } var run_options = { ui: ui, cwd: __dirname }; var cmd = new TestCliController(run_options); describe('whith quiet option', function() { it('should true', function () { return cmd.run({ quiet: true, verbose: 0 }).then(() => { h.expect(outputs).to.eql([{ quiet: true, verbose: 0}]); }); }); }); describe('whith verbose option', function() { it("should run with verbose outputs, level 0", function() { return cmd.run({ quiet: false, verbose: 0 }).then(() => { h.expect(outputs).to.eql([{ quiet: false, verbose: 0}]); }); }); it("should run with verbose outputs, level 1", function() { return cmd.run({ quiet: false, verbose: 1 }).then(() => { h.expect(outputs).to.eql(['nivel-1', { verbose: 1, quiet: false }]); }); }); it("should run with verbose outputs, level 2", function() { return cmd.run({ quiet: false, verbose: 2 }).then(() => { h.expect(outputs).to.eql(['nivel-1', 'nivel-2', { verbose: 2, quiet: false }]); }); }); it("should run with verbose outputs, level 3", function() { return cmd.run({ quiet: false, verbose: 3 }).then(() => { h.expect(outputs).to.eql(['nivel-1', 'nivel-2', 'nivel-3', { verbose: 3, quiet: false } ]); }); }); }); });