@backstage/backend-test-utils
Version:
Test helpers library for Backstage backends
49 lines (43 loc) • 1.42 kB
JavaScript
;
var KeyvMemcache = require('@keyv/memcache');
var helpers = require('./helpers.cjs.js');
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
var KeyvMemcache__default = /*#__PURE__*/_interopDefaultCompat(KeyvMemcache);
const createStore = (connection) => new KeyvMemcache__default.default(connection);
async function connectToExternalMemcache(connection) {
const keyv = await helpers.attemptKeyvConnection(
createStore,
connection,
"memcached"
);
return {
store: "memcache",
connection,
keyv,
stop: async () => await keyv.disconnect()
};
}
async function startMemcachedContainer(image) {
const { GenericContainer } = require("testcontainers");
const container = await new GenericContainer(image).withExposedPorts(11211).start();
const host = container.getHost();
const port = container.getMappedPort(11211);
const connection = `${host}:${port}`;
const keyv = await helpers.attemptKeyvConnection(
createStore,
connection,
"memcached"
);
return {
store: "memcache",
connection,
keyv,
stop: async () => {
await keyv.disconnect();
await container.stop({ timeout: 1e4 });
}
};
}
exports.connectToExternalMemcache = connectToExternalMemcache;
exports.startMemcachedContainer = startMemcachedContainer;
//# sourceMappingURL=memcache.cjs.js.map