|
1 | | -var ConsulFeatureStore = require('../consul_feature_store'); |
2 | | -var testBase = require('launchdarkly-node-server-sdk/test/feature_store_test_base'); |
3 | | -var consul = require('consul'); |
4 | | - |
5 | | -function stubLogger() { |
6 | | - return { |
7 | | - debug: jest.fn(), |
8 | | - info: jest.fn(), |
9 | | - warn: jest.fn(), |
10 | | - error: jest.fn() |
11 | | - }; |
12 | | -} |
13 | | - |
14 | | -describe('ConsulFeatureStore', function() { |
| 1 | +const ConsulFeatureStore = require('../consul_feature_store'); |
| 2 | +const { |
| 3 | + runPersistentFeatureStoreTests, |
| 4 | +} = require('launchdarkly-node-server-sdk/sharedtest/store_tests'); |
| 5 | +const consul = require('consul'); |
15 | 6 |
|
16 | | - var client = consul(); |
| 7 | +// Runs the standard test suites provided by the SDK's store_tests module. |
17 | 8 |
|
18 | | - function clearTable(done) { |
19 | | - client.kv.del({ key: 'launchdarkly', recurse: true }, function() { |
20 | | - done(); |
21 | | - }); |
22 | | - } |
| 9 | +function actualPrefix(prefix) { |
| 10 | + return prefix || 'launchdarkly'; |
| 11 | +} |
23 | 12 |
|
24 | | - const sdkConfig = { logger: stubLogger() }; |
| 13 | +function clearAllData(client) { |
| 14 | + return async (prefix) => { |
| 15 | + await client.kv.del({ key: actualPrefix(prefix), recurse: true }); |
| 16 | + }; |
| 17 | +} |
25 | 18 |
|
26 | | - function makeStore() { |
27 | | - return ConsulFeatureStore()(sdkConfig); |
28 | | - } |
| 19 | +describe('ConsulFeatureStore', function() { |
29 | 20 |
|
30 | | - function makeStoreWithoutCache() { |
31 | | - return ConsulFeatureStore({ cacheTTL: 0 })(sdkConfig); |
32 | | - } |
| 21 | + const client = consul({ promisify: true }); |
33 | 22 |
|
34 | | - function makeStoreWithPrefix(prefix) { |
35 | | - return ConsulFeatureStore({ prefix: prefix, cacheTTL: 0 })(sdkConfig); |
| 23 | + function createStore(prefix, cacheTTL, logger) { |
| 24 | + return ConsulFeatureStore({ prefix, cacheTTL })({ logger }); |
36 | 25 | } |
37 | 26 |
|
38 | | - function makeStoreWithHook(hook) { |
39 | | - var store = makeStore(); |
| 27 | + function createStoreWithConcurrentUpdateHook(prefix, logger, hook) { |
| 28 | + const store = createStore(prefix, 0, logger); |
40 | 29 | store.underlyingStore.testUpdateHook = hook; |
41 | 30 | return store; |
42 | 31 | } |
43 | 32 |
|
44 | | - describe('cached', function() { |
45 | | - testBase.baseFeatureStoreTests(makeStore, clearTable, true); |
46 | | - }); |
47 | | - |
48 | | - describe('uncached', function() { |
49 | | - testBase.baseFeatureStoreTests(makeStoreWithoutCache, clearTable, false, makeStoreWithPrefix); |
50 | | - }); |
51 | | - |
52 | | - testBase.concurrentModificationTests(makeStore, makeStoreWithHook); |
| 33 | + runPersistentFeatureStoreTests( |
| 34 | + createStore, |
| 35 | + clearAllData(client), |
| 36 | + createStoreWithConcurrentUpdateHook, |
| 37 | + ); |
53 | 38 | }); |
0 commit comments