Skip to content
This repository has been archived by the owner on Jun 4, 2019. It is now read-only.

Commit

Permalink
Check for supported serverless version (#15)
Browse files Browse the repository at this point in the history
* Add `semver-compare` as dependecy

* Check for supported serverless version on start

* Add test for checking supported serverless version

* Update serverless version check

* Updated comment

* Test for `aws-sdk` version instead of `serverless` version
  • Loading branch information
sbstjn committed Jun 16, 2017
1 parent 5da3ae9 commit 3c72ec2
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -26,7 +26,9 @@
"url": "https://github.com/Jimdo/serverless-dynamodb-ttl/issues"
},
"homepage": "https://github.com/Jimdo/serverless-dynamodb-ttl#readme",
"dependencies": {},
"dependencies": {
"semver-compare": "^1.0.0"
},
"standard": {
"envs": [
"node",
Expand Down
10 changes: 9 additions & 1 deletion src/plugin.js
Expand Up @@ -2,12 +2,15 @@

const assert = require('assert')
const util = require('util')
const cmp = require('semver-compare')

const MINIMUM_COMPATIBLE_AWSSDK_VERSION = '2.21.0'

class Plugin {
constructor (serverless, options) {
this.serverless = serverless
this.options = options || {}
this.provider = serverless.getProvider('aws')
this.options = options || {}

this.hooks = {
'after:deploy:deploy': this.afterDeploy.bind(this)
Expand All @@ -21,6 +24,11 @@ class Plugin {
assert(this.serverless.service.provider.name, 'Invalid serverless configuration')
assert(this.serverless.service.provider.name === 'aws', 'Only supported for AWS provider')

assert(
cmp(this.provider.sdk.VERSION, MINIMUM_COMPATIBLE_AWSSDK_VERSION) > -1,
util.format('Use `aws-sdk` version %s or newer', MINIMUM_COMPATIBLE_AWSSDK_VERSION)
)

assert(this.options && !this.options.noDeploy, 'Used --noDeploy flag')
assert(this.list().constructor === Array, 'Invalid configuration found')
assert(this.list().length > 0, 'No configuration found')
Expand Down
42 changes: 41 additions & 1 deletion test/plugin.spec.js
Expand Up @@ -6,7 +6,10 @@ const Plugin = require('../')
describe('Plugin', () => {
let getProvider = null
let provider = {
request: () => true
request: () => true,
sdk: {
VERSION: '2.21.0'
}
}
let providerMock = null

Expand Down Expand Up @@ -114,6 +117,43 @@ describe('Plugin', () => {
)
})

it('Skips for unsupported aws-sdk versions', () => {
let log = jest.fn()

let unsupportedProvider = {
request: () => true,
sdk: {
VERSION: '2.20.0'
}
}

let unsupportedProviderMock = sinon.mock(unsupportedProvider)
let unsupportedGetProvider = sinon.stub().returns(unsupportedProvider)

unsupportedProviderMock.expects('request').never()
const config = {
cli: { log },
region: 'us-east-1',
version: '1.13.1',
service: {
provider: {
name: 'aws'
},
custom: {
dynamodb: { ttl: [ { table: 'my-table-1', field: 'my-field-1' } ] }
}
},
getProvider: unsupportedGetProvider
}

return new Plugin(config, { region: 'eu-west-1' }).afterDeploy().then(
() => {
expect(log).toBeCalledWith('Skipping TTL setting(s) for DynamoDB: Use `aws-sdk` version 2.21.0 or newer!')
unsupportedProviderMock.restore()
}
)
})

it('Skips when no custom.dynamodb.ttl is found', () => {
let log = jest.fn()

Expand Down

0 comments on commit 3c72ec2

Please sign in to comment.