-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix(tests): Refactor for tests * fix(tests): Adding tests * fix(test): fix dependencies * fix(test): Add badges * fix(test): Add badges
- Loading branch information
Ben Ross
authored
Apr 20, 2018
1 parent
a290acd
commit 8bf73a8
Showing
9 changed files
with
980 additions
and
79 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
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,41 @@ | ||
import * as AWS from 'aws-sdk'; | ||
import { CloudFormation, Config } from 'aws-sdk'; | ||
import { DescribeStacksOutput } from 'aws-sdk/clients/cloudformation'; | ||
|
||
import { ResolverMap } from './types'; | ||
|
||
|
||
export const resolvers: ResolverMap = { | ||
cft: async (argument: string) => { | ||
if (!AWS.config.region) { | ||
AWS.config.update({ region: 'us-east-1' }); | ||
} | ||
const cft = new CloudFormation(); | ||
const parsedArgument = argument.split('.', 2); | ||
let stack: DescribeStacksOutput; | ||
try { | ||
stack = await cft.describeStacks({ StackName: parsedArgument[0] }).promise(); | ||
} catch (e) { | ||
throw new Error( | ||
`Could not get info for stack with name ${parsedArgument[0]} when parsing cft reference ${argument}: ${e}` | ||
); | ||
} | ||
if (stack.Stacks.length == 0) { | ||
throw new Error( | ||
`Could not locate stack with name ${parsedArgument[0]} when parsing cft reference ${argument}`); | ||
} | ||
|
||
for (const output of stack.Stacks[0].Outputs) { | ||
if (output.OutputKey === parsedArgument[1]) { | ||
return output.OutputValue; | ||
} | ||
} | ||
throw new Error(`Could not locate output ${parsedArgument[1]} of stack ${parsedArgument[0]}`); | ||
}, | ||
env: async (argument: string) => { | ||
return process.env[argument]; | ||
}, | ||
constant: async (argument: string) => { | ||
return argument; | ||
} | ||
}; |
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,30 @@ | ||
const { Rewriter } = require('./rewriter'); | ||
const { resolvers } = require('./resolvers'); | ||
|
||
|
||
describe('Rewriter', () => { | ||
it('Rewrites constants', () => { | ||
const document = { | ||
'explicit': '${constant:hello}', | ||
'implicit': 'hello' | ||
}; | ||
|
||
const rewriter = new Rewriter(resolvers); | ||
return rewriter.rewrite(document).then((output) => { | ||
expect(output['explicit']).toBe(output['implicit']); | ||
}); | ||
}); | ||
|
||
it('Rewrites environment variables', () => { | ||
process.env['TEST'] = 'hello'; | ||
const document = { | ||
'test': '${env:TEST}' | ||
}; | ||
|
||
const rewriter = new Rewriter(resolvers); | ||
return rewriter.rewrite(document).then((output) => { | ||
expect(output['test']).toBe('hello'); | ||
}); | ||
}); | ||
|
||
}); |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export type ResolverMap = { [name: string]: (arg: string) => Promise<string> }; | ||
export type Document = { [name: string]: string } |
Oops, something went wrong.