ntf is a network testing framework written in Node.js.
See the ntf homepage for more details about the ntf framework.
Install ntf
npm install ntf
npm install ntf -g
Create a file named ntfjs.org.js
var ntf = require('ntf')
, test = ntf.http('http://ntfjs.org')
exports.homepage = test.get('/', function(test) {
test.statusCode(200)
test.body('ntf')
test.done()
})
Run the tests
ntf ntfjs.org.js
- Test: request, del, get, head, options, patch, post, put
- Assert: body, cookie, header, json, jsonPath, statusCode
Test DNS records.
var ntf = require('ntf')
, dns = ntf.dns()
Resolve an IPv4 address record.
Arguments
- name {String} - name to resolve
- callback(test) {Function} - test callback
Example
exports.a = dns.a('a.dns.ntfjs.org', function(test) {
test.address('127.0.0.1')
test.done()
})
Resolve an IPv6 address record.
Arguments
- name {String} - name to resolve
- callback(test) {Function} - test callback
Example
exports.aaaa = dns.aaaa('aaaa.dns.ntfjs.org', function(test) {
test.address('::1')
test.done()
})
Resolve a canonical name record.
Arguments
- name {String} - canonical name to resolve
- callback(test) {Function} - test callback
Example
exports.cname = dns.cname('cname.dns.ntfjs.org', function(test) {
test.name('a.dns.ntfjs.org')
test.done()
})
Resolve a mail exchange record.
Arguments
- name {String} - mail exchange to resolve
- callback(test) {Function} - test callback
Example
exports.mx = dns.mx('mx.dns.ntfjs.org', function(test) {
test.name('mx1.dns.ntfjs.org')
test.done()
})
Resolve a name server record.
Arguments
- name {String} - name server to resolve
- callback(test) {Function} - test callback
Example
exports.ns = dns.ns('ns.dns.ntfjs.org', function(test) {
test.name('ns1.dns.ntfjs.org')
test.done()
})
Resolve a pointer record.
Arguments
- name {String} - IP address to resolve
- callback(test) {Function} - test callback
Example
exports.ptr = dns.ptr('50.116.49.237', function(test) {
test.name('hub.sewell.org')
test.done()
})
Resolve a service location record.
Arguments
- name {String} - service to resolve
- callback(test) {Function} - test callback
Example
exports.srv = dns.srv('_ntfjs', function(test) {
test.name('srv1.dns.ntfjs.org')
test.done()
})
Resolve a text record.
Arguments
- name {String} - text to resolve
- callback(test) {Function} - test callback
Example
exports.txt = dns.txt('_ntfjs', function(test) {
test.done()
})
Assert answer contains IP address.
Arguments
- ip {String} - IP address to check
Example
exports.a = dns.a('a.dns.ntfjs.org', function(test) {
test.address('127.0.0.1')
test.done()
})
Assert answer contains name.
Arguments
- name {String} - name to check
Example
exports.cname = dns.cname('cname.dns.ntfjs.org', function(test) {
test.name('a.dns.ntfjs.org')
test.done()
})
Test HTTP requests.
var ntf = require('ntf')
, http = ntf.http('http://http.ntfjs.org')
Execute an HTTP request.
__Arguments__- options {Object,String} - options or path/URL
- auth {String} - username and password (ex: "user:pass")
- body {Object,String} - request body
- cookie {Object} - cookie names and values (ex: { "sid": "2bf74f" })
- header {Object} - header names and values (ex: { "content-type": "application/json" })
- jar {Boolean} - persist cookies in sub-requests
- method {String} - HTTP method (delete, get, post, put)
- timeout {Integer} - maximum number of milliseconds request can take before its killed
- type {String} - encodes body and sets content-type header (form, json)
- url {String} - path or URL
- callback(test) {Function} - test callback
Example
exports.request = http.request('/', function(test) {
test.statusCode(200)
test.done()
})
Execute an HTTP delete request.
Arguments
- options {Object,String} - see request arguments
- method {String} - always set to delete
- callback(test) {Function} - test callback
Example
exports.del = http.del('/delete', function(test) {
test.statusCode(200)
test.done()
})
Execute an HTTP get request.
Arguments
- options {Object,String} - see request arguments
- method {String} - always set to get
- callback(test) {Function} - test callback
Example
exports.get = http.get('/get', function(test) {
test.statusCode(200)
test.done()
})
Execute an HTTP head request.
Arguments
- options {Object,String} - see request arguments
- method {String} - always set to head
- callback(test) {Function} - test callback
Example
exports.head = http.head('/head', function(test) {
test.statusCode(200)
test.done()
})
Execute an HTTP options request.
Arguments
- options {Object,String} - see request arguments
- method {String} - always set to options
- callback(test) {Function} - test callback
Example
exports.options = http.options('/options', function(test) {
test.statusCode(200)
test.done()
})
Execute an HTTP patch request.
Arguments
- options {Object,String} - see request arguments
- method {String} - always set to patch
- callback(test) {Function} - test callback
Example
exports.patch = http.patch('/patch', function(test) {
test.statusCode(200)
test.done()
})
Execute an HTTP post request.
Arguments
- options {Object} - see request arguments
- body {Object,String} - should be object by default (see type below)
- method {String} - always set to post
- type {String} - defaults to form
- callback(test) {Function} - test callback
Example
exports.post = http.post({ url: '/post', body: { 'q': 'test' } }), function(test) {
test.statusCode(201)
test.done()
})
Execute an HTTP put request.
Arguments
- options {Object} - see request arguments
- method {String} - always set to put
- callback(test) {Function} - test callback
Example
exports.put = http.put({ url: '/put', body: 'put' }), function(test) {
test.statusCode(201)
test.done()
})
Tests match
against body and returns result.
Arguments
- match
- RegExp - asserts body matches RegExp
- compare {String} - compare against match results
- return {Array,null} - RegExp match result
- String - asserts body contains match
- return {Integer} - first position of matched result
- undefined
- return {String,undefined} - body String
- RegExp - asserts body matches RegExp
Example
exports.get = http.get('/', function(test) {
test.body(/<title>(.*)<\/title>/, 'ntf')
test.done()
})
Tests cookie existence/value and returns match.
Arguments
- name {String} - cookie name
- match
- RegExp - asserts value matches RegExp
- return {Array,null} - RegExp match result
- String - asserts value matches String
- undefined
- return {Object,undefined} - cookie object
- RegExp - asserts value matches RegExp
Example
exports.get = http.get('/', function(test) {
test.cookie('sid', /^[a-f0-9]+$/)
test.done()
})
Tests header existence/value and returns match.
Arguments
- name {String} - header name
- match
- RegExp - asserts value matches RegExp
- return {Array,null} - RegExp match result
- String - asserts value matches String
- undefined
- return {Object,undefined} - header object
- RegExp - asserts value matches RegExp
Example
exports.get = http.get('/', function(test) {
test.header('Content-Type', 'text/html')
test.done()
})
Tests body against match and returns parsed JSON.
Arguments
- match - deep equal assert against match
- return - parsed JSON object
Example
exports.get = http.get('/', function(test) {
test.json({ one: 'two' })
test.done()
})
Tests json path against compares and returns result.
Arguments
- path {String} - json path (examples)
- compare - compare against json path results
- return {Array} - parsed JSON object
Example
exports.get = http.get('/', function(test) {
test.jsonPath('$.book.title', 'Second Foundation', "The Wise Man's Fear")
test.done()
})
Tests response status code.
Arguments
- code {Integer} - status code
Example
exports.get = http.get('/', function(test) {
test.statusCode(200)
test.done()
})
Test socket connections.
var ntf = require('ntf')
, socket = ntf.socket('ntfjs.org')
Open TCP connection to host and port.
Arguments
- options {Integer,Object} - port or options
- port {Integer} - port
- timeout {Integer} - maximum number of milliseconds before connection is killed
- callback(test) {Function} - test callback
Example
exports.tcp = socket.tcp(25, function(test) {
test.connect()
test.done()
})
Tests connection was opened.
Example
exports.tcp = socket.tcp(25, function(test) {
test.connect()
test.done()
})
MIT © 2011-2017 Shutterstock Images, LLC