7
7
const test = require ( 'tape' )
8
8
const axios = require ( 'axios' )
9
9
10
- const { log, fixture , util , enableDataSending } = require ( '../../test-helper' )
10
+ const { log } = require ( '../../test-helper' )
11
11
12
12
const agent = require ( '../../support/agent-singleton-mock' )
13
13
14
14
const express = require ( 'express' )
15
- const ioRedis = require ( 'ioredis-mock' )
16
- const Redis = require ( 'redis-mock' )
17
15
const Koa = require ( 'koa' )
18
16
const Router = require ( 'koa-router' )
19
17
const koaBodyParser = require ( 'koa-bodyparser' )
20
- const rq = require ( 'request' )
18
+
19
+ const { GenericContainer } = require ( "testcontainers" )
20
+
21
+ const ioRedis = require ( 'ioredis-mock' )
22
+ const Redis = require ( 'redis-mock' )
21
23
22
24
const TEST_ENV = {
23
25
host : 'localhost' ,
@@ -44,37 +46,37 @@ test(`${testName1} should Record the connections between express and redis.`, fu
44
46
const PATH = `/${ testName } `
45
47
46
48
app . use ( express . json ( ) )
47
- app . use ( function ( req , res , next ) {
49
+ app . use ( function ( req , res , next ) {
48
50
req . cache = client
49
51
next ( )
50
52
} )
51
- app . post ( PATH , function ( req , res , next ) {
53
+ app . post ( PATH , function ( req , res , next ) {
52
54
req . accepts ( 'application/json' )
53
55
var key = req . body . name
54
56
var value = JSON . stringify ( req . body )
55
- req . cache . set ( key , value , function ( err , data ) {
56
- if ( err ) {
57
+ req . cache . set ( key , value , function ( err , data ) {
58
+ if ( err ) {
57
59
console . log ( err )
58
- res . send ( "error " + err )
60
+ res . send ( "error " + err )
59
61
return
60
62
}
61
- req . cache . expire ( key , 10 )
63
+ req . cache . expire ( key , 10 )
62
64
res . json ( value )
63
65
} )
64
66
} )
65
- app . get ( `${ PATH } /:name` , function ( req , res , next ) {
67
+ app . get ( `${ PATH } /:name` , function ( req , res , next ) {
66
68
var key = req . params . name
67
- req . cache . get ( key , function ( err , data ) {
68
- if ( err ) {
69
+ req . cache . get ( key , function ( err , data ) {
70
+ if ( err ) {
69
71
console . log ( err )
70
- res . send ( "error " + err )
72
+ res . send ( "error " + err )
71
73
return
72
74
}
73
75
var value = JSON . parse ( data )
74
76
res . json ( value )
75
77
} )
76
78
} )
77
- app . use ( function ( req , res , next ) {
79
+ app . use ( function ( req , res , next ) {
78
80
var err = new Error ( 'Not Found' )
79
81
err . status = 404
80
82
next ( err )
@@ -107,37 +109,37 @@ test(`${testName2} should Record the connections between express and ioredis.`,
107
109
const PATH = `/${ testName } `
108
110
109
111
app . use ( express . json ( ) )
110
- app . use ( function ( req , res , next ) {
112
+ app . use ( function ( req , res , next ) {
111
113
req . cache = redis
112
114
next ( )
113
115
} )
114
- app . post ( PATH , function ( req , res , next ) {
116
+ app . post ( PATH , function ( req , res , next ) {
115
117
req . accepts ( 'application/json' )
116
118
var key = req . body . name
117
119
var value = JSON . stringify ( req . body )
118
- req . cache . set ( key , value , function ( err , data ) {
119
- if ( err ) {
120
+ req . cache . set ( key , value , function ( err , data ) {
121
+ if ( err ) {
120
122
console . log ( err )
121
- res . send ( "error " + err )
123
+ res . send ( "error " + err )
122
124
return
123
125
}
124
- req . cache . expire ( key , 10 )
126
+ req . cache . expire ( key , 10 )
125
127
res . json ( value )
126
128
} )
127
129
} )
128
- app . get ( `${ PATH } /:name` , function ( req , res , next ) {
130
+ app . get ( `${ PATH } /:name` , function ( req , res , next ) {
129
131
var key = req . params . name
130
- req . cache . get ( key , function ( err , data ) {
131
- if ( err ) {
132
+ req . cache . get ( key , function ( err , data ) {
133
+ if ( err ) {
132
134
console . log ( err )
133
- res . send ( "error " + err )
135
+ res . send ( "error " + err )
134
136
return
135
137
}
136
138
var value = JSON . parse ( data )
137
139
res . json ( value )
138
140
} )
139
141
} )
140
- app . use ( function ( req , res , next ) {
142
+ app . use ( function ( req , res , next ) {
141
143
var err = new Error ( 'Not Found' )
142
144
err . status = 404
143
145
next ( err )
@@ -171,13 +173,13 @@ test(`${testName3} should Record the connections between koa and redis.`, functi
171
173
172
174
const PATH = `/${ testName } `
173
175
app . use ( koaBodyParser ( ) )
174
- router . post ( PATH , async function ( ctx , next ) {
176
+ router . post ( PATH , async function ( ctx , next ) {
175
177
console . log ( ctx . request . body )
176
178
const key = ctx . request . body . name
177
179
const value = JSON . stringify ( ctx . request . body )
178
180
179
- client . set ( key , value , function ( err , data ) {
180
- if ( err ) {
181
+ client . set ( key , value , function ( err , data ) {
182
+ if ( err ) {
181
183
console . log ( err )
182
184
ctx . body = `error :: ${ err } `
183
185
return
@@ -216,7 +218,7 @@ test(`${testName3} should Record the connections between koa and redis.`, functi
216
218
const testName4 = 'koa-ioredis'
217
219
test ( `${ testName4 } should Record the connections between koa and ioredis.` , function ( t ) {
218
220
agent . bindHttp ( )
219
-
221
+
220
222
const testName = testName4
221
223
222
224
t . plan ( 2 )
@@ -227,7 +229,7 @@ test(`${testName4} should Record the connections between koa and ioredis.`, func
227
229
228
230
const PATH = `/${ testName } `
229
231
app . use ( koaBodyParser ( ) )
230
- router . post ( PATH , async function ( ctx , next ) {
232
+ router . post ( PATH , async function ( ctx , next ) {
231
233
const key = ctx . request . body . name
232
234
const value = JSON . stringify ( ctx . request . body )
233
235
await redis . set ( key , value )
0 commit comments