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

Check for supported serverless version #15

Merged
merged 6 commits into from
Jun 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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