-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(lambda): compare Runtimes by value instead of identity (#2543)
Different Runtime objects that represent the same runtime now compare as equal. This is important when using Layers, which declare compatible runtimes.
- Loading branch information
Showing
6 changed files
with
162 additions
and
2 deletions.
There are no files selected for viewing
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import s3 = require('@aws-cdk/aws-s3'); | ||
import cdk = require('@aws-cdk/cdk'); | ||
import _ = require('lodash'); | ||
import {Test, testCase} from 'nodeunit'; | ||
import lambda = require('../lib'); | ||
|
||
export = testCase({ | ||
'add incompatible layer'(test: Test) { | ||
// GIVEN | ||
const stack = new cdk.Stack(undefined, 'TestStack'); | ||
const bucket = new s3.Bucket(stack, 'Bucket'); | ||
const code = new lambda.S3Code(bucket, 'ObjectKey'); | ||
|
||
const func = new lambda.Function(stack, 'myFunc', { | ||
runtime: lambda.Runtime.Python37, | ||
handler: 'index.handler', | ||
code, | ||
}); | ||
const layer = new lambda.LayerVersion(stack, 'myLayer', { | ||
code, | ||
compatibleRuntimes: [lambda.Runtime.NodeJS] | ||
}); | ||
|
||
// THEN | ||
test.throws(() => func.addLayer(layer), | ||
/This lambda function uses a runtime that is incompatible with this layer/); | ||
|
||
test.done(); | ||
}, | ||
'add compatible layer'(test: Test) { | ||
// GIVEN | ||
const stack = new cdk.Stack(undefined, 'TestStack'); | ||
const bucket = new s3.Bucket(stack, 'Bucket'); | ||
const code = new lambda.S3Code(bucket, 'ObjectKey'); | ||
|
||
const func = new lambda.Function(stack, 'myFunc', { | ||
runtime: lambda.Runtime.Python37, | ||
handler: 'index.handler', | ||
code, | ||
}); | ||
const layer = new lambda.LayerVersion(stack, 'myLayer', { | ||
code, | ||
compatibleRuntimes: [lambda.Runtime.Python37] | ||
}); | ||
|
||
// THEN | ||
// should not throw | ||
func.addLayer(layer); | ||
|
||
test.done(); | ||
}, | ||
'add compatible layer for deep clone'(test: Test) { | ||
// GIVEN | ||
const stack = new cdk.Stack(undefined, 'TestStack'); | ||
const bucket = new s3.Bucket(stack, 'Bucket'); | ||
const code = new lambda.S3Code(bucket, 'ObjectKey'); | ||
|
||
const runtime = lambda.Runtime.Python37; | ||
const func = new lambda.Function(stack, 'myFunc', { | ||
runtime, | ||
handler: 'index.handler', | ||
code, | ||
}); | ||
const clone = _.cloneDeep(runtime); | ||
const layer = new lambda.LayerVersion(stack, 'myLayer', { | ||
code, | ||
compatibleRuntimes: [clone] | ||
}); | ||
|
||
// THEN | ||
// should not throw | ||
func.addLayer(layer); | ||
|
||
test.done(); | ||
}, | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import {Test, testCase} from 'nodeunit'; | ||
import {RuntimeFamily} from "../lib"; | ||
import lambda = require('../lib'); | ||
|
||
export = testCase({ | ||
'runtimes are equal for different instances'(test: Test) { | ||
// GIVEN | ||
const runtime1 = new lambda.Runtime('python3.7', RuntimeFamily.Python, {supportsInlineCode: true}); | ||
const runtime2 = new lambda.Runtime('python3.7', RuntimeFamily.Python, {supportsInlineCode: true}); | ||
|
||
// WHEN | ||
const result = runtime1.equals(runtime2); | ||
|
||
// THEN | ||
test.strictEqual(result, true, 'Runtimes should be equal'); | ||
|
||
test.done(); | ||
}, | ||
'runtimes are equal for same instance'(test: Test) { | ||
// GIVEN | ||
const runtime = new lambda.Runtime('python3.7', RuntimeFamily.Python, {supportsInlineCode: true}); | ||
|
||
// WHEN | ||
const result = runtime.equals(runtime); | ||
|
||
// THEN | ||
test.strictEqual(result, true, 'Runtimes should be equal'); | ||
|
||
test.done(); | ||
}, | ||
'unequal when name changes'(test: Test) { | ||
// GIVEN | ||
const runtime1 = new lambda.Runtime('python3.7', RuntimeFamily.Python, {supportsInlineCode: true}); | ||
const runtime2 = new lambda.Runtime('python3.6', RuntimeFamily.Python, {supportsInlineCode: true}); | ||
|
||
// WHEN | ||
const result = runtime1.equals(runtime2); | ||
|
||
// THEN | ||
test.strictEqual(result, false, 'Runtimes should be unequal when name changes'); | ||
|
||
test.done(); | ||
}, | ||
'unequal when family changes'(test: Test) { | ||
// GIVEN | ||
const runtime1 = new lambda.Runtime('python3.7', RuntimeFamily.Python, {supportsInlineCode: true}); | ||
const runtime2 = new lambda.Runtime('python3.7', RuntimeFamily.Java, {supportsInlineCode: true}); | ||
|
||
// WHEN | ||
const result = runtime1.equals(runtime2); | ||
|
||
// THEN | ||
test.strictEqual(result, false, 'Runtimes should be unequal when family changes'); | ||
|
||
test.done(); | ||
}, | ||
'unequal when supportsInlineCode changes'(test: Test) { | ||
// GIVEN | ||
const runtime1 = new lambda.Runtime('python3.7', RuntimeFamily.Python, {supportsInlineCode: true}); | ||
const runtime2 = new lambda.Runtime('python3.7', RuntimeFamily.Python, {supportsInlineCode: false}); | ||
|
||
// WHEN | ||
const result = runtime1.equals(runtime2); | ||
|
||
// THEN | ||
test.strictEqual(result, false, 'Runtimes should be unequal when supportsInlineCode changes'); | ||
|
||
test.done(); | ||
}, | ||
}); |