Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignored dependencies #66

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 5 additions & 0 deletions src/config/_upsert.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = function upsertProps (config, newConfig) {
let props = JSON.parse(JSON.stringify(config))
let layers = []
let policies = []
let ignoredDependencies = []

for (let setting of newConfig) {
let name
Expand Down Expand Up @@ -59,6 +60,9 @@ module.exports = function upsertProps (config, newConfig) {
else if (name === 'policies' && !!(value)) {
policies = policies.concat(value)
}
else if (name === 'ignoredDependencies' && !!(value)) {
ignoredDependencies = ignoredDependencies.concat(value)
}
else {
props[name] = value[0]
}
Expand All @@ -67,6 +71,7 @@ module.exports = function upsertProps (config, newConfig) {
// Drop in new (de-duped) layers, but don't unnecessarily overwrite
if (layers.length) props.layers = [ ...new Set(layers) ]
if (policies.length) props.policies = [ ...new Set(policies) ]
if (ignoredDependencies.length) props.ignoredDependencies = [ ...new Set(ignoredDependencies) ]

return props
}
1 change: 1 addition & 0 deletions src/defaults/function-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ module.exports = function createDefaultFunctionConfig () {
policies: [],
shared: true,
env: true,
ignoredDependencies: [],
}
}
2 changes: 2 additions & 0 deletions test/integration/function-config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ test('[No global runtime] Inventory and compare functions with / without functio
shared: false,
env: false,
views: false,
ignoredDependencies: [ 'module-1', 'module-2' ],
}
let params = Object.keys(custom).length
test('Configured route uses correct custom settings', t => {
Expand Down Expand Up @@ -82,6 +83,7 @@ test('[Global runtime alias] Inventory and compare functions with / without func
shared: false,
env: false,
views: false,
ignoredDependencies: [ 'module-1', 'module-2' ],
}
let params = Object.keys(custom).length
test('Configured route uses correct custom settings', t => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ architecture arm64
shared false
env false
views false
ignoredDependencies
module-1
module-2
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ architecture arm64
shared false
env false
views false
ignoredDependencies
module-1
module-2
136 changes: 135 additions & 1 deletion test/unit/src/config/_upsert-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ policies
policy-1
policy-2
architecture arm64
ignoredDependencies
module-1
module-2
`
let mock = parse(rawConfigMock)

Expand All @@ -44,7 +47,7 @@ test('Upsert returns same number of params', t => {
t.plan(3)
let result = upsert(defaults, [])
t.ok(result, 'Got result from upsert')
t.equal(Object.keys(result).length, 12, 'Got back same number of params as base config')
t.equal(Object.keys(result).length, 13, 'Got back same number of params as base config')
t.equal(str(defaults), str(result), 'Passed back config as-is')
})

Expand Down Expand Up @@ -452,6 +455,137 @@ runtime python
t.equal(str(policiesDefaults.policies), str(result.policies), 'Did not overwrite project-level config with empty policies array')
})

// AJB HACK //
test('Individual setting upsert: ignoredDependencies', t => {
t.plan(22)
let value
let ignoredDependencies
let result
let expected
let ignoredDependenciesDefaults

/**
* ignored dependencies
*/
// Single inline
value = [ 'module-1' ]
ignoredDependencies = parse(`@aws
ignoredDependencies ${value}
`).aws
result = upsert(defaults, ignoredDependencies)
t.notEqual(str(defaults.ignoredDependencies), str(value), 'Testing value is not already the default')
t.equal(str(result.ignoredDependencies), str(value), 'Properly upserted single ignored dependency')

// Multiple inline
value = [ 'module-1', 'module-2' ]
ignoredDependencies = parse(`@aws
ignoredDependencies ${value.join(' ')}
`).aws
result = upsert(defaults, ignoredDependencies)
t.notEqual(str(defaults.ignoredDependencies), str(value), 'Testing value is not already the default')
t.equal(str(result.ignoredDependencies), str(value), 'Properly upserted ignored dependencies')

// Single in array
value = [ 'module-1' ]
ignoredDependencies = parse(`@aws
ignoredDependencies
${value}
`).aws
result = upsert(defaults, ignoredDependencies)
t.notEqual(str(defaults.ignoredDependencies), str(value), 'Testing value is not already the default')
t.equal(str(result.ignoredDependencies), str(value), 'Properly upserted single ignored dependency')

// Multiple in array
value = [ 'module-1', 'module-2' ]
ignoredDependencies = parse(`@aws
ignoredDependencies
${value.join('\n ')}
`).aws
result = upsert(defaults, ignoredDependencies)
t.notEqual(str(defaults.ignoredDependencies), str(value), 'Testing value is not already the default')
t.equal(str(result.ignoredDependencies), str(value), 'Properly upserted ignored dependencies')

// Multiple in array de-duped
ignoredDependenciesDefaults = defaultFunctionConfig()
ignoredDependenciesDefaults.ignoredDependencies = [ 'module-1', 'module-2' ]
value = [ 'module-2', 'module-3', 'module-3' ]
expected = [ 'module-2', 'module-3' ]
ignoredDependencies = parse(`@aws
ignoredDependencies
${value.join('\n ')}
`).aws
result = upsert(ignoredDependenciesDefaults, ignoredDependencies)
t.notEqual(str(ignoredDependenciesDefaults.ignoredDependencies), str(value), 'Testing value is not already the default')
t.equal(str(result.ignoredDependencies), str(expected), 'Properly upserted ignored dependencies & de-duped')

/**
* ignoredDependencies
*/
// Single inline
value = [ 'module-1' ]
ignoredDependencies = parse(`@aws
ignoredDependencies ${value}
`).aws
result = upsert(defaults, ignoredDependencies)
t.notEqual(str(defaults.ignoredDependencies), str(value), 'Testing value is not already the default')
t.equal(str(result.ignoredDependencies), str(value), 'Properly upserted single ignored dependency')

// Multiple inline
value = [ 'module-1', 'module-2' ]
ignoredDependencies = parse(`@aws
ignoredDependencies ${value.join(' ')}
`).aws
result = upsert(defaults, ignoredDependencies)
t.notEqual(str(defaults.ignoredDependencies), str(value), 'Testing value is not already the default')
t.equal(str(result.ignoredDependencies), str(value), 'Properly upserted single ignored dependency')

// Single in array
value = [ 'module-1' ]
ignoredDependencies = parse(`@aws
ignoredDependencies
${value}
`).aws
result = upsert(defaults, ignoredDependencies)
t.notEqual(str(defaults.ignoredDependencies), str(value), 'Testing value is not already the default')
t.equal(str(result.ignoredDependencies), str(value), 'Properly upserted single ignored dependency')

// Multiple in array
value = [ 'module-1', 'module-2' ]
ignoredDependencies = parse(`@aws
ignoredDependencies
${value.join('\n ')}
`).aws
result = upsert(defaults, ignoredDependencies)
t.notEqual(str(defaults.ignoredDependencies), str(value), 'Testing value is not already the default')
t.equal(str(result.ignoredDependencies), str(value), 'Properly upserted single ignored dependency')

// Multiple in array de-duped
ignoredDependenciesDefaults = defaultFunctionConfig()
ignoredDependenciesDefaults.ignoredDependencies = [ 'module-1', 'module-2' ]
value = [ 'module-2', 'module-3', 'module-3' ]
expected = [ 'module-2', 'module-3' ]
ignoredDependencies = parse(`@aws
ignoredDependencies
${value.join('\n ')}
`).aws
result = upsert(ignoredDependenciesDefaults, ignoredDependencies)
t.notEqual(str(ignoredDependenciesDefaults.ignoredDependencies), str(value), 'Testing value is not already the default')
t.equal(str(result.ignoredDependencies), str(expected), 'Properly upserted ignored dependencies & de-duped')

/**
* Don't unnecessarily overwrite existing ignoredDependencies config
*/
ignoredDependenciesDefaults = defaultFunctionConfig()
ignoredDependenciesDefaults.ignoredDependencies = [ 'module-1', 'module-2' ]
ignoredDependencies = parse(`@aws
runtime python
`).aws
result = upsert(ignoredDependenciesDefaults, ignoredDependencies)
t.notEqual(str(ignoredDependenciesDefaults.ignoredDependencies), str(ignoredDependencies.ignoredDependencies), 'Testing value is not already the default')
t.equal(str(ignoredDependenciesDefaults.ignoredDependencies), str(result.ignoredDependencies), 'Did not overwrite project-level config with empty ignoredDependencies array')
})
// AJB HACK END //

test('Individual setting upsert: something unknown', t => {
t.plan(2)
let value = 'mysterious'
Expand Down
2 changes: 1 addition & 1 deletion test/unit/src/defaults/function-config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test('Set up env', t => {
test('Function config returns correct defaults', t => {
t.plan(13)
let result = functionConfig()
t.equal(Object.keys(result).length, 12, 'Got correct number of properties')
t.equal(Object.keys(result).length, 13, 'Got correct number of properties')
t.ok(result.timeout, 'Got timeout')
t.ok(result.memory, 'Got memory')
t.ok(result.runtime, 'Got runtime')
Expand Down