Skip to content

Commit

Permalink
adds getByRaw method to API to retrieve raw etcd node (not just node.…
Browse files Browse the repository at this point in the history
…value)
  • Loading branch information
T1B0 committed Oct 13, 2016
1 parent 2177e53 commit efd7ac8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ const createAPI = (store, client, options = {cwd: '/'}) => {
});
};

const getByRaw = (index, key) => {
debug(`getBy: ${index} => ${key}`);
return store('indexes').then(getOr(null, [index, key]));
};

const get = path => {
debug(`get => ${path}`);
return store('node').then(_get(path));
Expand All @@ -50,6 +55,7 @@ const createAPI = (store, client, options = {cwd: '/'}) => {

return {
getBy,
getByRaw,
getAll,
get,
set
Expand Down
44 changes: 40 additions & 4 deletions src/test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ test('should create API', t => {
t.truthy(api);
t.truthy(api.get);
t.truthy(api.getBy);
t.truthy(api.getByRaw);
t.truthy(api.getAll);
t.truthy(api.set);
});
Expand Down Expand Up @@ -126,14 +127,14 @@ test('should get node by simple index', async t => {
);
});

test('should get null if any node matches', async t => {
test('should get null if no node matches', async t => {
t.deepEqual(
await api.getBy('value', 'nope'),
null
);
});

test('should get null if any index matches', async t => {
test('should get null if no index matches', async t => {
t.deepEqual(
await api.getBy('nope', 'nope'),
null
Expand All @@ -149,13 +150,48 @@ test('should get node by complex index', async t => {
);
});

test('should get null if any complex index matches', async t => {
test('should get null if no complex index matches', async t => {
t.deepEqual(
await api.getBy('deep.nope', 'nope'),
null
);
});

test('should get raw node by simple index', async t => {
t.deepEqual(
await api.getByRaw('value', 'foo'),
{key: '/foo', value: {value: 'foo' }}
);
});

test('should get null if no node matches (raw)', async t => {
t.deepEqual(
await api.getByRaw('value', 'nope'),
null
);
});

test('should get null if no index matches (raw)', async t => {
t.deepEqual(
await api.getByRaw('nope', 'nope'),
null
);
});

test('should get node by complex index (raw)', async t => {
t.deepEqual(
await api.getByRaw('deep.value', 'foo'),
{key: '/foo', value: {value: 'foo'}}
);
});

test('should get null if no complex index matches (raw)', async t => {
t.deepEqual(
await api.getByRaw('deep.nope', 'nope'),
null
);
});

test('should get root node by path', async t => {
t.deepEqual(
await api.get('/'),
Expand All @@ -170,7 +206,7 @@ test('should get node by path', async t => {
);
});

test('should get null if any node matches this path', async t => {
test('should get null if no node matches this path', async t => {
t.deepEqual(
await api.get('/nope'),
null
Expand Down

0 comments on commit efd7ac8

Please sign in to comment.