Created
December 10, 2014 19:38
-
-
Save YanivHaramati/76fd01f58c1a3731acea to your computer and use it in GitHub Desktop.
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 Promise = require('bluebird'), | |
request = require('request'), | |
url = require('url'), | |
tests = require('./tests').tests; | |
var environments = { "prod": "", | |
"qa": "qam.", | |
"dev": "localci." | |
}; | |
function promiseableRequest(args) { | |
return new Promise(function(resolve, reject) { | |
var env = getEnv(args.environment); | |
var opts = { | |
uri: url.parse("http://" + env + args.url), | |
followRedirect: !!args.redirect, | |
encoding: "UTF-8" | |
} | |
request(opts, function (error, response, body) { | |
if (error) reject(error); | |
var match = isMatch(args, response); | |
resolve({test: {description: args, status: match, result: { url: response.request.uri.href, status: response.statusCode}}}); | |
}); | |
}); | |
} | |
function isMatch(args, response) { | |
var env = getEnv(args.environment, args.redirect_environment); | |
var status = response.statusCode; | |
var match = (status === args.status); | |
if (args.redirect_to) { | |
match = match && (response.request.uri.href == "http://" + env + args.redirect_to); | |
} | |
return match; | |
} | |
function getEnv(environment, redirect_environment) { | |
var env = (environment) ? environment : ""; | |
var redir = (redirect_environment) ? redirect_environment : ""; | |
var e = redir ? redir : env; | |
return environments[e]; | |
} | |
function displayResults(results) { | |
console.log(JSON.stringify(results, null, '\t')); | |
console.log("test results for " + tests.length + " tests."); | |
console.log(results.fail.length + " tests failed."); | |
} | |
Promise | |
.reduce(tests.map(promiseableRequest), | |
function(finalResult, currentResult) { | |
var test = currentResult.test; | |
var bucket = (test.status) ? finalResult.pass : finalResult.fail; | |
bucket.push({test: test.description, result: test.result}); | |
return (finalResult); | |
}, { pass: [], fail: []}) | |
.catch(function(err) { | |
console.log("error: " + err); | |
process.exit(1); | |
}) | |
.then(function(results) { | |
displayResults(results); | |
process.exit((results.fail.length) ? 1 : 0); | |
}); | |
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
module.exports = { | |
tests: [ | |
{environment: "prod", url: "www.realtor.com/local/", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/California", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/California/rent-prices", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/California/home-prices", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/California/lifestyle", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Texas", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Texas/rent-prices", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Texas/home-prices", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Texas/lifestyle", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/94131", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/94131/rent-prices", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/94131/home-prices", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/94131/lifestyle", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Irene_Olive-Branch_TN", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Irene_Olive-Branch_TN/rent-prices", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Irene_Olive-Branch_TN/home-prices", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Irene_Olive-Branch_TN/lifestyle", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/01061", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/01061/rent-prices", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/01061/home-prices", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/01061/lifestyle", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Plano_TX", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Plano_TX/rent-prices", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Plano_TX/home-prices", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Plano_TX/lifestyle", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/San-Francisco-County_CA", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/San-Francisco-County_CA/rent-prices", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/San-Francisco-County_CA/home-prices", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/San-Francisco-County_CA/lifestyle", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Armstrong-Park_Plano_TX", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Armstrong-Park_Plano_TX/rent-prices", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Armstrong-Park_Plano_TX/home-prices", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Armstrong-Park_Plano_TX/lifestyle", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Jefferson-On-The-Bend-Sub_Plano_TX", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Jefferson-On-The-Bend-Sub_Plano_TX/rent-prices", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Jefferson-On-The-Bend-Sub_Plano_TX/home-prices", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Jefferson-On-The-Bend-Sub_Plano_TX/lifestyle", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Hanford-Metro_CA", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Hanford-Metro_CA/rent-prices", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Hanford-Metro_CA/home-prices", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Hanford-Metro_CA/lifestyle", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/foobar1123", status: 404}, | |
{environment: "prod", url: "www.realtor.com/local/Saint-Thomas_VI", status: 301}, | |
{environment: "prod", url: "www.realtor.com/local/%C1nimo-Pat-Brown-School_Los-Angeles_Los-Angeles-County_CA/education", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Saline%c3%b1o_TX", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Saline%c3%b1o_TX/rent-prices", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Saline%c3%b1o_TX/home-prices", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Saline%c3%b1o_TX/lifestyle", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/\"seattle\"", status: 301}, | |
{environment: "prod", url: "www.realtor.com/local/\"seattle\"", status: 200, redirect: true, redirect_to: "www.realtor.com/local/Seattle_WA", redirect_environment: "prod"}, | |
{environment: "prod", url: "www.realtor.com/local/seattle", status: 301}, | |
{environment: "prod", url: "www.realtor.com/local/seattle", status: 200, redirect: true, redirect_to: "www.realtor.com/local/Seattle_WA", redirect_environment: "prod"}, | |
{environment: "prod", url: "www.realtor.com/local/*seattle", status: 301}, | |
{environment: "prod", url: "www.realtor.com/local/*seattle", status: 200, redirect: true, redirect_to: "www.realtor.com/local/Seattle_WA", redirect_environment: "prod"}, | |
{environment: "prod", url: "www.realtor.com/local/+seattle", status: 301}, | |
{environment: "prod", url: "www.realtor.com/local/+seattle", status: 200, redirect: true, redirect_to: "www.realtor.com/local/Seattle_WA", redirect_environment: "prod"}, | |
{environment: "prod", url: "www.realtor.com/local/seattle wa", status: 301}, | |
{environment: "prod", url: "www.realtor.com/local/seattle wa", status: 200, redirect: true, redirect_to: "www.realtor.com/local/Seattle_WA", redirect_environment: "prod"}, | |
{environment: "prod", url: "www.realtor.com/local/sea", status: 200, redirect: true, redirect_to: "www.realtor.com/local/Seattle_WA"}, | |
{environment: "prod", url: "www.realtor.com/local/Asawa-San-Francisco-School-Of-The-Arts_San-Francisco_San-Francisco-County_CA", status: 301}, | |
{environment: "prod", url: "www.realtor.com/local/Asawa-San-Francisco-School-Of-The-Arts_San-Francisco_San-Francisco-County_CA/", status: 301}, | |
{environment: "prod", url: "www.realtor.com/local/Asawa-San-Francisco-School-Of-The-Arts_San-Francisco_San-Francisco-County_CA/education", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Asawa-San-Francisco-School-Of-The-Arts_San-Francisco_San-Francisco-County_CA/test-scores", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/San-Francisco-Unified-School-District_San-Francisco_San-Francisco-County_CA", status: 301}, | |
{environment: "prod", url: "www.realtor.com/local/San-Francisco-Unified-School-District_San-Francisco_San-Francisco-County_CA/", status: 301}, | |
{environment: "prod", url: "www.realtor.com/local/San-Francisco-Unified-School-District_San-Francisco_San-Francisco-County_CA/education", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Archbishop-Riordan-High-Private-School_San-Francisco_San-Francisco-County_CA", status: 301}, | |
{environment: "prod", url: "www.realtor.com/local/Archbishop-Riordan-High-Private-School_San-Francisco_San-Francisco-County_CA/", status: 301}, | |
{environment: "prod", url: "www.realtor.com/local/Archbishop-Riordan-High-Private-School_San-Francisco_San-Francisco-County_CA/education", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Archbishop-Riordan-High-Private-School_San-Francisco_San-Francisco-County_CA/test-scores", status: 200}, | |
{environment: "prod", url: "www.realtor.com/local/Aloma-Vista_Phoenix_AZ", status: 200, redirect: true, redirect_to: "www.realtor.com/local/Aloma-Vista-Sub_Phoenix_AZ", redirect_environment: "prod"}, | |
{environment: "prod", url: "www.realtor.com/local/blah_Phoenix_AZ", status: 200, redirect: true, redirect_to: "www.realtor.com/local/Phoenix_AZ", redirect_environment: "prod"}, | |
] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment