@omnitron-dev/testing 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -0
- package/dist/docker/database-manager.js +4 -6
- package/dist/docker/database-manager.js.map +1 -1
- package/dist/docker/docker-test-manager.d.ts +4 -3
- package/dist/docker/docker-test-manager.js +126 -268
- package/dist/docker/docker-test-manager.js.map +1 -1
- package/dist/docker/redis-manager.js +38 -36
- package/dist/docker/redis-manager.js.map +1 -1
- package/dist/docker/types.d.ts +2 -2
- package/dist/env.js +6 -3
- package/dist/env.js.map +1 -1
- package/dist/runtime/deno-adapter.js +1 -1
- package/dist/runtime/deno-adapter.js.map +1 -1
- package/dist/titan/redis-test-utils.js +80 -54
- package/dist/titan/redis-test-utils.js.map +1 -1
- package/package.json +33 -31
- package/src/docker/database-manager.ts +4 -6
- package/src/docker/docker-test-manager.ts +113 -353
- package/src/docker/docker-volume-cleanup.spec.ts +62 -15
- package/src/docker/redis-cluster-creation.spec.ts +52 -0
- package/src/docker/redis-manager.ts +33 -49
- package/src/docker/types.ts +4 -4
- package/src/env.spec.ts +20 -0
- package/src/env.ts +5 -3
- package/src/index.ts +1 -1
- package/src/runtime/deno-adapter.ts +1 -1
- package/src/titan/redis-test-utils.test.ts +102 -0
- package/src/titan/redis-test-utils.ts +86 -71
|
@@ -49,7 +49,7 @@ export interface TestRedisEndpoint {
|
|
|
49
49
|
*/
|
|
50
50
|
export function resolveTestRedisEndpoint(): TestRedisEndpoint {
|
|
51
51
|
try {
|
|
52
|
-
const infoPath = join(process.cwd(), REDIS_INFO_FILE);
|
|
52
|
+
const infoPath = process.env['TITAN_TEST_REDIS_INFO'] ?? join(process.cwd(), REDIS_INFO_FILE);
|
|
53
53
|
if (existsSync(infoPath)) {
|
|
54
54
|
const info = JSON.parse(readFileSync(infoPath, 'utf-8')) as {
|
|
55
55
|
port?: number;
|
|
@@ -131,12 +131,16 @@ export interface RedisTestFixture {
|
|
|
131
131
|
* Create a Redis test fixture with proper cleanup
|
|
132
132
|
*/
|
|
133
133
|
export async function createRedisTestFixture(options: RedisTestFixtureOptions = {}): Promise<RedisTestFixture> {
|
|
134
|
+
const endpoint = resolveTestRedisEndpoint();
|
|
135
|
+
if (endpoint.isMock && options.port === undefined) {
|
|
136
|
+
throw new Error('A real Redis fixture requires a test endpoint; Redis setup selected mock mode.');
|
|
137
|
+
}
|
|
134
138
|
const {
|
|
135
139
|
withManager = false,
|
|
136
140
|
withService = false,
|
|
137
141
|
db = 15, // Use test database
|
|
138
|
-
host =
|
|
139
|
-
port =
|
|
142
|
+
host = endpoint.host,
|
|
143
|
+
port = endpoint.port,
|
|
140
144
|
namespace = 'test',
|
|
141
145
|
lazyConnect = false,
|
|
142
146
|
enableReadyCheck = true,
|
|
@@ -157,66 +161,83 @@ export async function createRedisTestFixture(options: RedisTestFixtureOptions =
|
|
|
157
161
|
|
|
158
162
|
// Create primary client
|
|
159
163
|
const client = new Redis(redisOptions);
|
|
160
|
-
|
|
161
|
-
// Wait for connection if not lazy
|
|
162
|
-
if (!lazyConnect) {
|
|
163
|
-
await new Promise<void>((resolve, reject) => {
|
|
164
|
-
const timeout = setTimeout(() => {
|
|
165
|
-
client.removeAllListeners();
|
|
166
|
-
reject(Errors.timeout('Redis connection in test fixture', 10000));
|
|
167
|
-
}, 10000); // 10 second timeout
|
|
168
|
-
|
|
169
|
-
client.once('ready', () => {
|
|
170
|
-
clearTimeout(timeout);
|
|
171
|
-
resolve();
|
|
172
|
-
});
|
|
173
|
-
client.once('error', (error) => {
|
|
174
|
-
clearTimeout(timeout);
|
|
175
|
-
reject(error);
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
// Ensure connection starts
|
|
179
|
-
if (client.status === 'wait') {
|
|
180
|
-
client.connect().catch(reject);
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
|
|
185
164
|
let manager: RedisManager | undefined;
|
|
186
165
|
let service: RedisService | undefined;
|
|
187
166
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
167
|
+
try {
|
|
168
|
+
// Wait for connection if not lazy
|
|
169
|
+
if (!lazyConnect) {
|
|
170
|
+
await new Promise<void>((resolve, reject) => {
|
|
171
|
+
const timeout = setTimeout(() => {
|
|
172
|
+
removeListeners();
|
|
173
|
+
reject(Errors.timeout('Redis connection in test fixture', 10000));
|
|
174
|
+
}, 10000); // 10 second timeout
|
|
175
|
+
|
|
176
|
+
const removeListeners = () => {
|
|
177
|
+
clearTimeout(timeout);
|
|
178
|
+
client.off('ready', onReady);
|
|
179
|
+
client.off('error', onError);
|
|
180
|
+
};
|
|
181
|
+
const onReady = () => {
|
|
182
|
+
removeListeners();
|
|
183
|
+
resolve();
|
|
184
|
+
};
|
|
185
|
+
const onError = (error: Error) => {
|
|
186
|
+
removeListeners();
|
|
187
|
+
reject(error);
|
|
188
|
+
};
|
|
189
|
+
client.once('ready', onReady);
|
|
190
|
+
client.once('error', onError);
|
|
191
|
+
|
|
192
|
+
// Ensure connection starts
|
|
193
|
+
if (client.status === 'wait') {
|
|
194
|
+
client.connect().catch(onError);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
}
|
|
216
198
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
199
|
+
// Create manager if requested
|
|
200
|
+
if (withManager) {
|
|
201
|
+
// Use type assertion to avoid ioredis version compatibility issues
|
|
202
|
+
const clientConfigs = [
|
|
203
|
+
{
|
|
204
|
+
namespace: 'default',
|
|
205
|
+
...redisOptions,
|
|
206
|
+
db: redisOptions.db, // Use the test DB
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
namespace,
|
|
210
|
+
...redisOptions,
|
|
211
|
+
db: redisOptions.db, // Use the test DB
|
|
212
|
+
},
|
|
213
|
+
...(namespace !== 'cache'
|
|
214
|
+
? [
|
|
215
|
+
{
|
|
216
|
+
namespace: 'cache',
|
|
217
|
+
...redisOptions,
|
|
218
|
+
db: 14, // Use different DB for cache namespace
|
|
219
|
+
},
|
|
220
|
+
]
|
|
221
|
+
: []),
|
|
222
|
+
] as any;
|
|
223
|
+
|
|
224
|
+
manager = new RedisManager({ clients: clientConfigs }, createTestNullLogger());
|
|
225
|
+
await manager.onModuleInit();
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Create service if requested
|
|
229
|
+
if (withService && manager) {
|
|
230
|
+
service = new RedisService(manager);
|
|
231
|
+
}
|
|
232
|
+
} catch (error) {
|
|
233
|
+
try {
|
|
234
|
+
await manager?.onModuleDestroy();
|
|
235
|
+
} catch (cleanupError) {
|
|
236
|
+
throw new AggregateError([error, cleanupError], 'Redis fixture initialization and cleanup failed', { cause: cleanupError });
|
|
237
|
+
} finally {
|
|
238
|
+
client.disconnect();
|
|
239
|
+
}
|
|
240
|
+
throw error;
|
|
220
241
|
}
|
|
221
242
|
|
|
222
243
|
// Cleanup function
|
|
@@ -224,19 +245,13 @@ export async function createRedisTestFixture(options: RedisTestFixtureOptions =
|
|
|
224
245
|
try {
|
|
225
246
|
// Clear all data in test database
|
|
226
247
|
await client.flushdb();
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
248
|
+
} finally {
|
|
249
|
+
try {
|
|
250
|
+
await manager?.onModuleDestroy();
|
|
251
|
+
} finally {
|
|
252
|
+
client.disconnect();
|
|
253
|
+
client.removeAllListeners();
|
|
231
254
|
}
|
|
232
|
-
|
|
233
|
-
// Close client
|
|
234
|
-
client.disconnect();
|
|
235
|
-
|
|
236
|
-
// Remove all listeners
|
|
237
|
-
client.removeAllListeners();
|
|
238
|
-
} catch (error) {
|
|
239
|
-
console.error('Cleanup error:', error);
|
|
240
255
|
}
|
|
241
256
|
};
|
|
242
257
|
|