-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from keyvhq/revamp+iterator
- Loading branch information
Showing
16 changed files
with
95 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,4 @@ test('Collection option merges into default options if URL is passed', t => { | |
collection: 'foo' | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const keyvIteratorTests = (test, Keyv, store) => { | ||
test.beforeEach(async () => { | ||
const keyv = new Keyv({ store: store() }); | ||
await keyv.clear(); | ||
}); | ||
|
||
test.serial('.iterator() returns an asyncIterator', t => { | ||
const keyv = new Keyv({ store: store() }); | ||
t.true(typeof keyv.iterator()[Symbol.asyncIterator] === 'function'); | ||
}); | ||
|
||
test.serial('iterator() iterates over all values', async t => { | ||
const keyv = new Keyv({ store: store() }); | ||
const map = new Map(Array.from({ length: 5 }).fill(0).map((x, i) => [String(i), String(i + 10)])); | ||
const toResolve = []; | ||
for (const [key, value] of map) { | ||
toResolve.push(keyv.set(key, value)); | ||
} | ||
|
||
await Promise.all(toResolve); | ||
t.plan(map.size); | ||
for await (const [key, value] of keyv.iterator()) { | ||
const doesKeyExist = map.has(key); | ||
const isValueSame = map.get(key) === value; | ||
t.true(doesKeyExist && isValueSame); | ||
} | ||
}); | ||
}; | ||
|
||
module.exports = keyvIteratorTests; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,7 @@ | ||
const test = require('ava'); | ||
const keyvTestSuite = require('@keyvhq/keyv-test-suite'); | ||
const { keyvOfficialTests } = keyvTestSuite; | ||
const Keyv = require('this'); | ||
const KeyvMongo = require('@keyvhq/keyv-mongo'); | ||
|
||
keyvOfficialTests(test, Keyv, 'mongodb://127.0.0.1:27017', 'mongodb://127.0.0.1:1234'); | ||
|
||
const store = () => new KeyvMongo('mongodb://127.0.0.1:27017'); | ||
keyvTestSuite(test, Keyv, store); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,7 @@ | ||
const test = require('ava'); | ||
const keyvTestSuite = require('@keyvhq/keyv-test-suite'); | ||
const { keyvOfficialTests } = keyvTestSuite; | ||
const Keyv = require('this'); | ||
const KeyvMysql = require('@keyvhq/keyv-mysql'); | ||
|
||
keyvOfficialTests(test, Keyv, 'mysql://mysql@localhost/keyv_test', 'mysql://foo'); | ||
|
||
const store = () => new KeyvMysql('mysql://mysql@localhost/keyv_test'); | ||
keyvTestSuite(test, Keyv, store); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,7 @@ | ||
const test = require('ava'); | ||
const keyvTestSuite = require('@keyvhq/keyv-test-suite'); | ||
const { keyvOfficialTests } = keyvTestSuite; | ||
const Keyv = require('this'); | ||
const KeyvPostgres = require('postgres'); | ||
|
||
keyvOfficialTests(test, Keyv, 'postgresql://postgres@localhost:5432/keyv_test', 'postgresql://foo'); | ||
|
||
const store = () => new KeyvPostgres('postgresql://postgres@localhost:5432/keyv_test'); | ||
keyvTestSuite(test, Keyv, store); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,7 @@ | ||
const test = require('ava'); | ||
const keyvTestSuite = require('@keyvhq/keyv-test-suite'); | ||
const { keyvOfficialTests } = keyvTestSuite; | ||
const Keyv = require('this'); | ||
const KeyvRedis = require('redis'); | ||
|
||
keyvOfficialTests(test, Keyv, 'redis://localhost', 'redis://foo'); | ||
|
||
const store = () => new KeyvRedis('redis://localhost'); | ||
keyvTestSuite(test, Keyv, store); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,7 @@ | ||
const test = require('ava'); | ||
const keyvTestSuite = require('@keyvhq/keyv-test-suite'); | ||
const { keyvOfficialTests } = keyvTestSuite; | ||
const Keyv = require('this'); | ||
const KeyvSqlite = require('sqlite'); | ||
|
||
keyvOfficialTests(test, Keyv, 'sqlite://test/testdb.sqlite', 'sqlite://non/existent/database.sqlite'); | ||
|
||
const store = () => new KeyvSqlite('sqlite://test/testdb.sqlite'); | ||
keyvTestSuite(test, Keyv, store); |