Last active
June 29, 2018 15:00
-
-
Save SimonHooker/485454cf42805aab14c1 to your computer and use it in GitHub Desktop.
Code samples for Automating testing in Coldfusion and Railo with Testbox, Gulp, and Jenkins. Pt 2
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
component { | |
public Base function init() { | |
variables.uuid = makeUUID(); | |
return this; | |
} | |
private string function makeUUID() { | |
return CreateUUID(); | |
} | |
public string function getUUID() { | |
return variables.uuid; | |
} | |
} | |
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
component extends='mxunit.framework.TestCase' { | |
public void function retrieveUUID() { | |
var thisObject = new Base(); | |
assertTrue(Len(thisObject.getUUID())>0,'Length of uuid is 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
[CommandBox] | |
name=CommandBox $releasever - $basearch | |
failovermethod=priority | |
baseurl=http://integration.staging.ortussolutions.com/artifacts/RPMS/noarch | |
enabled=1 | |
metadata_expire=7d | |
gpgcheck=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
// node includes | |
var http = require('http'); | |
var args = require('yargs').argv; | |
var fs = require('fs'); | |
// gulp includes | |
var gulp = require('gulp'); | |
var gulputil = require('gulp-util'); | |
var clean = require('gulp-clean'); | |
var targetFolder = 'testresults/'; | |
var targetFile = 'results.xml'; | |
var testSuite = '/demo/runAllTests.cfm'; | |
gulp.task('checkargs',function(){ | |
if (typeof args.url === 'undefined') { | |
throw Error('URL argument must be defined (i.e. gulp --url www.domain.here )'); | |
} else { | |
console.log('Test suite: '+args.url+testSuite); | |
console.log('Results file: '+targetFolder+targetFile); | |
} | |
}); | |
gulp.task('clean',function(){ | |
ensureExists(targetFolder, 0744, function(err) { | |
if (err) { | |
throw Error('Unable to create target folder'); | |
} | |
}); | |
return gulp.src(targetFolder+'*', {read: false}) | |
.pipe(clean()); | |
}); | |
gulp.task('runtests',['clean'],function(){ | |
var opts = { | |
host: args.url, | |
port: 80, | |
path: testSuite, | |
method: 'GET' | |
}; | |
var file = fs.createWriteStream(targetFolder+targetFile); | |
var rq = http.get(opts, function(res) { | |
console.log('runtests options:'); | |
console.log(opts); | |
console.log('Response: '+res.statusCode); | |
res.pipe(file); | |
console.log('Test suite results file written'); | |
}).on('error',function(e){ | |
console.log('Error returned while running testsuite: '+e.message); | |
}); | |
rq.setTimeout( 10 * 60 * 1000 ); // timeout in ms | |
return rq; | |
}); | |
gulp.task('default',['checkargs','runtests'],function(){ | |
console.log('All done!'); | |
}); | |
function ensureExists(path, mask, cb) { | |
if (typeof mask == 'function') { // allow the `mask` parameter to be optional | |
cb = mask; | |
mask = 0777; | |
} | |
fs.mkdir(path, mask, function(err) { | |
if (err) { | |
if (err.code == 'EEXIST') cb(null); // ignore the error if the folder already exists | |
else cb(err); // something else went wrong | |
} else cb(null); // successfully created folder | |
}); | |
} |
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
{ | |
"devDependencies": { | |
"gulp": "^3.8.0", | |
"gulp-util": "^2.2.17", | |
"gulp-clean": "^0.3.0", | |
"gulp-open": "^0.2.8", | |
"yargs": "^1.2.3" | |
} | |
} |
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
<cfsilent> | |
<cfscript> | |
setting requesttimeout=3600 {}; | |
// Iterate over tests | |
r = new testbox.system.TestBox( | |
reporter='ANTJunit', | |
directory={ | |
mapping='', | |
recurse=true, | |
filter=function(pathTest){ | |
return (Right(pathTest,8) == 'Test.cfc'); | |
} | |
} | |
); | |
testOutput = r.run(); | |
</cfscript> | |
</cfsilent> | |
<cfoutput>#testOutput#</cfoutput> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment