Permalink
Browse files

Use mocha for tests

Move sample code to examples directory
Add sample config for tests
Add sample config showing apiKeyCredentials and passwordCrenentials authentication types
Remove stray console.log debugging output
  • Loading branch information...
1 parent a4b7ecd commit c6be5ef6474dedc3cce1e6ab434e21b64e2f6278 @mmurphy mmurphy committed May 30, 2012
View
@@ -0,0 +1,11 @@
+{
+ "auth": {
+ "apiAccessKeyCredentials": {
+ "accessKey": "YOUR API ACCESS KEY",
+ "secretKey": "YOUR SECRET KEY"
+ },
+ "tenantId": "YOUR TENANT ID"
+ },
+ "host": "YOUR IDENTITY SERVER URL",
+ "storageName": "THE NAME OF YOUR STORAGE SERVICE IN THE SERVICE CATALOG"
+}
File renamed without changes.
@@ -0,0 +1,11 @@
+{
+ "auth": {
+ "passwordCredentials": {
+ "username": "user1234",
+ "password":"secretpassword"
+ },
+ "tenantId": "your tennant id"
+ },
+ "host": "http://192.168.28.52:5000",
+ "storageName": "swift-service"
+}
File renamed without changes.
File renamed without changes.
View
@@ -45,7 +45,6 @@ var getTokens = exports.getTokens = function (options, callback) {
var tokens = {};
if (!err && res && res.statusCode && res.statusCode === 200) {
var respBody = body;
- console.log('responseBody ', respBody);
tokens.id = respBody.access.token.id;
tokens.expires = respBody.access.token.expires;
async.detect(
View
@@ -13,6 +13,13 @@
"async": "0.1.18",
"request": "2.9.202"
},
+ "scripts": {
+ "test": "mocha --ui tdd --globals writeln --reporter spec"
+ },
+ "devDependencies": {
+ "buffertools":"*",
+ "mocha":"*"
+ },
"devDependencies": {},
"optionalDependencies": {},
"engines": {
View
@@ -0,0 +1,73 @@
+var path = require('path');
+var assert = require('assert');
+var async = require('async');
+
+var authenticate = require('../lib/authenticate');
+var storage = require('../lib/storage');
+
+suite('StorageTests', function(){
+ var configFile;
+ var config;
+ var authFn;
+
+ setup(function(){
+ configFile = path.join(__dirname,'../config/testconfig.json');
+ config = require(configFile);
+ authFn = async.apply(authenticate.getTokens, config);
+ });
+
+ suite('Create Container, then file, the delete both', function(){
+ test('happy test', function(done){
+ var storageSwift = new storage.OpenStackStorage (authFn, function(err, res, tokens) {
+ assert(!err);
+ assert(tokens);
+ async.waterfall(
+ [
+ function(cb) {
+ var containerName = "EngTest";
+ cb(null, containerName);
+ },
+ function(containerName, cb) {
+ storageSwift.createContainer(containerName, function (err, statusCode) {
+ assert(!err, "error creating container");
+ assert(statusCode, "no statusCode");
+ assert((statusCode>=200) && (statusCode<300), "non successful statusCode: " + statusCode);
+ cb(err, containerName);
+ });
+ },
+ function(containerName, cb) {
+ storageSwift.addFile(containerName, {remoteName:'file1.png', localFile:'./test.png'}, function(err, statusCode) {
+ assert(!err, "error sending file");
+ assert(statusCode, "no statusCode");
+ assert((statusCode>=200) && (statusCode<300), "non successful statusCode: " + statusCode);
+ cb(err, containerName);
+ });
+ },
+ function(containerName, cb) {
+ storageSwift.deleteFile(containerName, 'file1.png', function (err, statusCode) {
+ assert(!err, "error deleting file");
+ assert(statusCode, "no statusCode");
+ assert((statusCode>=200) && (statusCode<300), "non successful statusCode: " + statusCode);
+ cb(err, containerName);
+ });
+ },
+ function(containerName, cb) {
+ storageSwift.deleteContainer(containerName, function (err, statusCode) {
+ assert(!err, "error deleting container");
+ assert(statusCode, "no statusCode");
+ assert((statusCode>=200) && (statusCode<300), "non successful statusCode: " + statusCode);
+ cb(err, containerName);
+ });
+ }
+ ],
+ function(err, containerName) {
+ assert(!err, "Previous asserts have succeeded, unexpected error: " + (err?err.toString():""));
+ assert.strictEqual(containerName, "EngTest", "waterfall parameter sequence broken");
+ done();
+ }
+ );
+ });
+ });
+ });
+});
+
View
@@ -1,36 +1,28 @@
-// Arguments parser
-var args = require('optimist').argv;
-
-// Logger Library
-var winston = require('winston');
-
-var dateFormat = require('dateformat');
-
-// Usage
-function usage() {
- console.error("Usage: " + args.$0 + " <config file>");
- process.exit(0);
-}
-
-if(args.h) {
- usage();
-}
-
-if(args._.length != 1) {
- usage();
-}
-
-var configFile = args._[0];
-var config = require(configFile);
-
-var authenticate = require('authenticate');
-
-var res = authenticate.getTokens(config, function (err, res, tokens) {
- console.log("err: ", err);
-// console.log("res: ", res);
- console.log("tokens: ", tokens);
+var path = require('path');
+var assert = require('assert');
+var authenticate = require('../lib/authenticate');
+
+suite('authenticate', function(){
+ var configFile;
+ var config;
+
+ setup(function(){
+ configFile = path.join(__dirname,'../config/testconfig.json');
+ config = require(configFile);
+ });
+
+ suite('getTokens', function(){
+ test('happy test', function(done){
+ var res = authenticate.getTokens(config, function (err, res, tokens) {
+ assert(!err, "Error from getToken: " + (err?err.toString():""));
+ assert(tokens, "Invalid response from authentication");
+ assert(tokens.id && (tokens.id.length > 0), "id should be a string");
+ assert(tokens.expires && (tokens.expires.length > 0), "invalid expiry time returned");
+ assert(tokens.storageUrl && (tokens.storageUrl.length > 0), "storageURL not returned");
+ done();
+ });
+ });
+ });
});
-
-

0 comments on commit c6be5ef

Please sign in to comment.