-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle Fn::GetAtt and Fn::Join in kinesis stream spec [reworked from #94
- Loading branch information
1 parent
d02f5b2
commit 3d9a107
Showing
3 changed files
with
144 additions
and
6 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
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 @@ | ||
const ServerlessOfflineKinesis = require('./index'); | ||
const { extractStreamNameFromGetAtt } = ServerlessOfflineKinesis; | ||
|
||
test('extractStreamNameFromGetAtt handles array Fn::GetAtt', () => { | ||
expect(extractStreamNameFromGetAtt(['MyResource', 'Arn'])).toEqual('MyResource'); | ||
}); | ||
test('extractStreamNameFromGetAtt handles string Fn::GetAtt', () => { | ||
expect(extractStreamNameFromGetAtt('MyResource.Arn')).toEqual('MyResource'); | ||
}); | ||
test('extractStreamNameFromGetAtt throws on other cases', () => { | ||
expect(() => extractStreamNameFromGetAtt({ MyResource: 'Arn' })).toThrow(); | ||
}); | ||
|
||
const baseServerless = { | ||
service: { | ||
resources: { | ||
Resources: { | ||
TestStream: { | ||
Type: 'AWS::Kinesis::Stream', | ||
Properties: { | ||
Name: 'test-stream-dev' | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
test('getStreamName handles a directly specified ARN', () => { | ||
const plugin = new ServerlessOfflineKinesis(baseServerless); | ||
expect(plugin.getStreamName('arn:aws:kinesis:us-east-1:123456789012:stream/TestStream')).toEqual('TestStream'); | ||
}) | ||
|
||
test('getStreamName handles an object with a arn string property', () => { | ||
const plugin = new ServerlessOfflineKinesis(baseServerless); | ||
expect(plugin.getStreamName({ | ||
arn: 'arn:aws:kinesis:us-east-1:123456789012:stream/TestStream' | ||
})).toEqual('TestStream'); | ||
}); | ||
|
||
test('getStreamName handles an object with a streamName property', () => { | ||
const plugin = new ServerlessOfflineKinesis(baseServerless); | ||
expect(plugin.getStreamName({ | ||
streamName: 'TestStream', | ||
})).toEqual('TestStream'); | ||
}); | ||
|
||
test('getStreamName handles an object with an arn Fn::GetAtt lookup (array form)', () => { | ||
const plugin = new ServerlessOfflineKinesis(baseServerless); | ||
expect(plugin.getStreamName({ | ||
arn: { | ||
'Fn::GetAtt': ['TestStream', 'Arn'], | ||
} | ||
})).toEqual('test-stream-dev'); | ||
}); | ||
|
||
test('getStreamName handles an object with an arn Fn::GetAtt lookup (string form)', () => { | ||
const plugin = new ServerlessOfflineKinesis(baseServerless); | ||
expect(plugin.getStreamName({ | ||
arn: { | ||
'Fn::GetAtt': 'TestStream.Arn', | ||
} | ||
})).toEqual('test-stream-dev'); | ||
}); | ||
test('getStreamName makes a naïve attempt to parse an arn Fn::Join lookup', () => { | ||
const plugin = new ServerlessOfflineKinesis(baseServerless); | ||
expect(plugin.getStreamName({ | ||
arn: { | ||
'Fn::Join': [ | ||
':', | ||
['arn', 'aws', 'kinesis', { Ref: 'AWS::Region'}, { Ref: 'AWS::AccountId' }, 'stream/my-stream-dev'] | ||
] | ||
} | ||
})).toEqual('my-stream-dev'); | ||
}); | ||
|