Last active
December 27, 2015 07:09
-
-
Save smith/7286713 to your computer and use it in GitHub Desktop.
An example of using chef-zero for integration testing chef-node
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
var spawn = require('child_process').spawn, | |
chef = require('../../chef'), | |
key = require('fs').readFileSync(__dirname + '/../fixtures/example.pem'), | |
expect = require('chai').expect; | |
describe('Nodes', function () { | |
before(function () { | |
var chefZero = this.chefZero = spawn('chef-zero', ['--port=8889']); | |
chefZero.on('exit', function (code, signal) { | |
if (code !== 0) { throw new Error('Chef Zero exited unexpectedly.'); } | |
}); | |
chefZero.stdout.on('data', function (data) { | |
if (data.toString().indexOf('is listening at') !== -1) { | |
chefZero.emit('ready'); | |
} | |
}); | |
chefZero.stdout.pipe(process.stdout); | |
chefZero.stderr.pipe(process.stderr); | |
}); | |
after(function () { | |
this.chefZero.kill(); | |
}); | |
it('should create and get nodes', function (done) { | |
var client = chef.createClient('admin', key, 'http://localhost:8889'); | |
this.chefZero.on('ready', function () { | |
client.post('/nodes', { name: 'test' }, function (err, res) { | |
client.get('/nodes/test', function (err, res) { | |
expect(res.body.name).to.eq('test'); | |
done(); | |
}); | |
}); | |
}); | |
}); | |
}); |
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
nathansmith@opstop:~/Projects/chef-node:·master:1$ mocha tests/integration/nodes.js --reporter=spec | |
Nodes | |
◦ should create and get nodes: >> Starting Chef Zero (v1.7)... | |
>> Puma (v1.6.3) is listening at http://127.0.0.1:8889 | |
>> Press CTRL+C to stop | |
✓ should create and get nodes (567ms) | |
>> Stopping Chef Zero ... | |
1 passing (577ms) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment