Last active
January 4, 2017 19:28
-
-
Save cmawhorter/67c88aadc13bbd1d3c74a503a22a694c 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
'use strict'; | |
var assert = require('assert'); | |
var AWS = require('aws-sdk'); | |
var dynogels = require('dynogels'); | |
var Enjoi = require('enjoi'); | |
var config = { | |
endpoint: 'http://localhost:8000', | |
}; | |
var table = process.argv[2]; | |
var lookupId = process.argv[3]; | |
assert.ok(table, 'table name missing at argv[2]'); | |
assert.ok(lookupId, 'lookup id missing at argv[3]'); | |
var REGION = 'us-east-1'; | |
switch (process.env.TEST_STRATEGY) { | |
case 'constructor': | |
config.region = REGION; | |
config.accessKeyId = 'blah'; | |
config.secretAccessKey = 'blah'; | |
break; | |
case 'none': | |
config.region = REGION; | |
break; | |
case 'mixed': | |
config.region = REGION; | |
process.env.AWS_ACCESS_KEY_ID = 'blah'; | |
process.env.AWS_SECRET_ACCESS_KEY = 'blah'; | |
break; | |
case 'env': | |
process.env.AWS_REGION = REGION; | |
process.env.AWS_ACCESS_KEY_ID = 'blah'; | |
process.env.AWS_SECRET_ACCESS_KEY = 'blah'; | |
break; | |
case 'some': | |
config.region = REGION; | |
config.accessKeyId = 'blah'; | |
config.secretAccessKey = 'blah'; | |
process.env.AWS_ACCESS_KEY_ID = 'blah'; | |
process.env.AWS_SECRET_ACCESS_KEY = 'blah'; | |
break; | |
case 'all': | |
config.region = REGION; | |
config.accessKeyId = 'blah'; | |
config.secretAccessKey = 'blah'; | |
process.env.AWS_REGION = REGION; | |
process.env.AWS_ACCESS_KEY_ID = 'blah'; | |
process.env.AWS_SECRET_ACCESS_KEY = 'blah'; | |
break; | |
case 'mismatch': | |
config.region = REGION; | |
config.accessKeyId = 'blah'; | |
config.secretAccessKey = 'blah'; | |
process.env.AWS_REGION = 'us-west-2'; | |
assert.notStrictEqual(REGION, process.env.AWS_REGION, 'REGION cannot be same as alternative'); | |
process.env.AWS_ACCESS_KEY_ID = config.accessKeyId + '_not_the_same'; | |
process.env.AWS_SECRET_ACCESS_KEY = config.secretAccessKey + '_not_the_same'; | |
break; | |
case 'missing': | |
config.region = REGION; | |
config.accessKeyId = ''; | |
config.secretAccessKey = ''; | |
break; | |
default: | |
throw new Error('credential test strategy missing at process.env.TEST_STRATEGY'); | |
} | |
console.log('options', JSON.stringify({ config, table, env: { | |
AWS_REGION: REGION, | |
AWS_ACCESS_KEY_ID: 'blah', | |
AWS_SECRET_ACCESS_KEY: 'blah', | |
} }, null, 2)); | |
var dynamodb = new AWS.DynamoDB(config); | |
dynogels.dynamoDriver(dynamodb); | |
assert.strictEqual(REGION, dynamodb.config.region, `region mismatch ${REGION} !== ${dynamodb.config.region}`); | |
var SomeModel = dynogels.define('SomeModel', { | |
tableName: table, | |
hashKey: 'id', | |
timestamps: true, | |
createdAt: 'created', | |
updatedAt: 'updated', | |
schema: Enjoi({ | |
"$schema": "http://json-schema.org/draft-04/schema#", | |
"type": "object", | |
"properties": { | |
"id": { | |
"type": "string" | |
}, | |
}, | |
"required": [ "id" ] | |
}), | |
}); | |
SomeModel.get(lookupId, null, (err, result) => { | |
assert.ifError(err); | |
assert.equal(lookupId, result.get('id'), `lookup data id mismatch ${lookupId} !== ${result.get('id')}`); | |
console.log('\n\n\nok %s\n', result.get('id')); | |
process.exit(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment