1.0.6 • Published 7 years ago

dpd-test v1.0.6

Weekly downloads
1
License
ISC
Repository
github
Last release
7 years ago

Easy way to write deployd tests without mongodb

Build Status

Usage

$ npm install dpd-test --save
$ NODE_PATH=node_modules node test/mytest.js

test/mytest.js:

var dpdTest = require('dpd-test')

dpdTest.run({
  port:3030, 
  before: function(dpd){}, 
  ready: function(dpd, done){
    console.log("ready to test")       // use your favorite testing framework here
    done()
  }, 
  done: function(err, database){
    console.log("done")                // inspect database content here  (or in file 'mongodb.test.js')
    process.exit( err ? 1 : 0 )
  }  
})

Voila, there you go

Options

keytypeinfo
readyfn(dpd, done)called when deployd server started.
donefn (err, database)called when done() is called in ready(). You can inspect the contents of the database afterwards
portinteger (3030)port for the fake deployd server to listen on
isRootboolean (false)this sets req.isRoot = true on each request when dpd-ssh-key-header is sent (see auth example)
patchFilefn(file)allows patching files during bootup
noresetboolean (false)don't wipe database during startup (reuse db of previous test)

Endpoint testing

var dpdTest = require('dpd-test')
var request = require('superagent')
var port = 3030

dpdTest.run({
  port: port, 
  ready: function(dpd, done){

    request
      .post('localhost:'+port+'/user/login')
      .set('Content-Type',  'application/json')
      .set('Accept',  'application/json')
      .send({ username: "foo", password:"foo" })
      .end(function(err,  res){
        done(res.body.status != 200) // return true when error
      })

  }, 
  done: function(err, database){
    process.exit( err ? 1 : 0 )
  }  
})

Authenticated test

Just specify a user, and the user is automatically created and authenticated:

	dpdTest.run({
		port: port, 
		patchFile: patchFiles, 
		user: {username:"foo", "password":"foo"}, 
		ready: function(dpd, done, sessionid ){

			request
				.get('localhost:'+port+'/user/me')
				.set('Cookie', 'sid='+sessionid)
				.set('Content-Type',  'application/json')
				.set('Accept',  'application/json')
				.end(function(err,  res){
					console.dir(res.body) // logged in
					done()
				})

		}, 
		done: function(err, database){
			console.log("done") 
			process.exit( err ? 1 : 0 )
		} 
	})

for testing roles check dpd-acl-roles-permissions

Patch files

Occasionally it can be handy to patch required files to mimic certain situations:

	var patchFiles = function(file){
		if( file.match(/resources\/foo\/config.json/) != null ){
			var mod = JSON.parse(require('fs').readFileSync(file))
			delete mod.user.properties
			return mod
		}
	}

	dpdTest.run({
		...
		patchFile: patchFiles
		...
	})
1.0.6

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago