@@ -65,6 +65,42 @@ describe('Lambda Data Source configuration', () => {
65
65
} ) ;
66
66
} ) ;
67
67
68
+ test ( 'appsync sanitized datasource name from unsupported characters' , ( ) => {
69
+ const badCharacters = [ ...'!@#$%^&*()+-=[]{}\\|;:\'",<>?/' ] ;
70
+
71
+ badCharacters . forEach ( ( badCharacter ) => {
72
+ // WHEN
73
+ const newStack = new cdk . Stack ( ) ;
74
+ const graphqlapi = new appsync . GraphqlApi ( newStack , 'baseApi' , {
75
+ name : 'api' ,
76
+ schema : appsync . Schema . fromAsset ( path . join ( __dirname , 'appsync.test.graphql' ) ) ,
77
+ } ) ;
78
+ const dummyFunction = new lambda . Function ( newStack , 'func' , {
79
+ code : lambda . Code . fromAsset ( path . join ( __dirname , 'verify/iam-query' ) ) ,
80
+ handler : 'iam-query.handler' ,
81
+ runtime : lambda . Runtime . NODEJS_12_X ,
82
+ } ) ;
83
+ graphqlapi . addLambdaDataSource ( `data-${ badCharacter } -source` , dummyFunction ) ;
84
+
85
+ // THEN
86
+ Template . fromStack ( newStack ) . hasResourceProperties ( 'AWS::AppSync::DataSource' , {
87
+ Type : 'AWS_LAMBDA' ,
88
+ Name : 'datasource' ,
89
+ } ) ;
90
+ } ) ;
91
+ } ) ;
92
+
93
+ test ( 'appsync leaves underscore untouched in datasource name' , ( ) => {
94
+ // WHEN
95
+ api . addLambdaDataSource ( 'data_source' , func ) ;
96
+
97
+ // THEN
98
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::AppSync::DataSource' , {
99
+ Type : 'AWS_LAMBDA' ,
100
+ Name : 'data_source' ,
101
+ } ) ;
102
+ } ) ;
103
+
68
104
test ( 'appsync errors when creating multiple lambda data sources with no configuration' , ( ) => {
69
105
// THEN
70
106
expect ( ( ) => {
0 commit comments