@@ -10,18 +10,55 @@ const Plugin = require("../index.js");
1010
1111const serverlessMock = require ( "./serverlessMock" ) ;
1212
13+ function get ( url ) {
14+ return new Promise ( function ( resolve , reject ) {
15+ http . get ( url , function ( incoming ) {
16+ resolve ( incoming ) ;
17+ } ) . on ( 'error' , reject ) ;
18+ } ) ;
19+ }
20+
21+ function getWithRetry ( url , retryCount , previousError ) {
22+ retryCount = retryCount || 0 ;
23+ if ( retryCount >= 3 ) {
24+ return Promise . reject ( 'Exceeded retry count for get of ' + url , previousError ) ;
25+ }
26+ return get ( url )
27+ . catch ( function ( error ) {
28+ console . error ( 'error getting ' + url + ', retrying' ) ;
29+ return new Promise ( function ( resolve ) { setTimeout ( resolve , 1000 ) ; } )
30+ . then ( function ( ) {
31+ return getWithRetry ( url , retryCount + 1 , error ) ;
32+ } ) ;
33+ } ) ;
34+ }
35+
1336describe ( "Port function" , function ( ) {
37+ let service ;
38+ before ( function ( ) {
39+ this . timeout ( 60000 ) ;
40+ service = new Plugin ( serverlessMock , { stage : 'test' } ) ;
41+ return service . installHandler ( ) ;
42+ } )
43+
1444 it ( "Port should return number" , function ( ) {
15- let service = new Plugin ( serverlessMock , { } ) ;
1645 assert ( typeof service . port , "number" ) ;
1746 } ) ;
1847
19- it ( "Port value should be >= 0 and < 65536" , function ( done ) {
20- let service = new Plugin ( serverlessMock , { } ) ;
21- http . get ( `http://localhost:${ service . port } /shell/` , function ( response ) {
22- assert . equal ( response . statusCode , 200 ) ;
23- done ( ) ;
24- } ) ;
48+ it ( "Port value should be >= 0 and < 65536" , function ( ) {
49+ this . timeout ( 10000 ) ;
50+ return service . startHandler ( )
51+ . then ( function ( ) {
52+ console . log ( 'started handler' ) ;
53+ return getWithRetry ( `http://localhost:${ service . port } /shell/` ) ;
54+ } )
55+ . then ( function ( response ) {
56+ assert . equal ( response . statusCode , 200 ) ;
57+ } ) ;
58+ } ) ;
59+
60+ after ( function ( ) {
61+ return service . endHandler ( ) ;
2562 } ) ;
2663} ) ;
2764
@@ -41,7 +78,7 @@ describe("Check the dynamodb function",function(){
4178 let raw = new aws . DynamoDB ( dynamoOptions ) ;
4279 raw . should . be . type ( "object" ) ;
4380 } ) ;
44-
81+
4582 it ( "Should be an object" , function ( ) {
4683 let dynamoOptions = Plugin . prototype . dynamodbOptions ;
4784 let doc = new aws . DynamoDB ( dynamoOptions ) ;
@@ -62,7 +99,7 @@ describe ("createTable functon",function(){
6299 const tbl = Plugin . prototype . createTable ;
63100 assert . equal ( typeof tbl , "function" ) ;
64101 } ) ;
65- } ) ;
102+ } ) ;
66103
67104describe ( "Check the Seeder file" , function ( ) {
68105 it ( "Table name shoud be a string" , function ( ) {
0 commit comments