@@ -10,18 +10,55 @@ const Plugin = require("../index.js");
10
10
11
11
const serverlessMock = require ( "./serverlessMock" ) ;
12
12
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
+
13
36
describe ( "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
+
14
44
it ( "Port should return number" , function ( ) {
15
- let service = new Plugin ( serverlessMock , { } ) ;
16
45
assert ( typeof service . port , "number" ) ;
17
46
} ) ;
18
47
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 ( ) ;
25
62
} ) ;
26
63
} ) ;
27
64
@@ -41,7 +78,7 @@ describe("Check the dynamodb function",function(){
41
78
let raw = new aws . DynamoDB ( dynamoOptions ) ;
42
79
raw . should . be . type ( "object" ) ;
43
80
} ) ;
44
-
81
+
45
82
it ( "Should be an object" , function ( ) {
46
83
let dynamoOptions = Plugin . prototype . dynamodbOptions ;
47
84
let doc = new aws . DynamoDB ( dynamoOptions ) ;
@@ -62,7 +99,7 @@ describe ("createTable functon",function(){
62
99
const tbl = Plugin . prototype . createTable ;
63
100
assert . equal ( typeof tbl , "function" ) ;
64
101
} ) ;
65
- } ) ;
102
+ } ) ;
66
103
67
104
describe ( "Check the Seeder file" , function ( ) {
68
105
it ( "Table name shoud be a string" , function ( ) {
0 commit comments