Skip to content

Commit

Permalink
lookup: lmdb_kv: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
resmo committed Sep 30, 2019
1 parent a2270ea commit 6370c63
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/integration/targets/lookup_lmdb_kv/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
shippable/posix/group2
destructive
10 changes: 10 additions & 0 deletions test/integration/targets/lookup_lmdb_kv/dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- hosts: localhost
tasks:
- name: Install LMDB Python package
pip:
name: lmdb
- name: Setup test data
script: test_db.py
args:
executable: "{{ ansible_python.executable }}"
9 changes: 9 additions & 0 deletions test/integration/targets/lookup_lmdb_kv/runme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
set -eux

ANSIBLE_ROLES_PATH=../ \
ansible-playbook dependencies.yml -v "$@"

ANSIBLE_ROLES_PATH=../ \
ansible-playbook test.yml -v "$@"
31 changes: 31 additions & 0 deletions test/integration/targets/lookup_lmdb_kv/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
- hosts: localhost
tasks:
- debug:
msg: "{{ query('lmdb_kv', 'nl', 'be', 'lu', db='jp.mdb') }}"

- debug:
var: item.1
loop: "{{ query('lmdb_kv', db='jp.mdb') }}"

- assert:
that:
- query('lmdb_kv', 'nl', 'be', 'lu', db='jp.mdb') == ['Netherlands', 'Belgium', 'Luxembourg']
- query('lmdb_kv', db='jp.mdb')|length == 5

- assert:
that:
- item.0 == 'nl'
- item.1 == 'Netherlands'
vars:
- lmdb_kv_db: jp.mdb
with_lmdb_kv:
- "n*"

- assert:
that:
- item == 'Belgium'
vars:
- lmdb_kv_db: jp.mdb
with_lmdb_kv:
- be
11 changes: 11 additions & 0 deletions test/integration/targets/lookup_lmdb_kv/test_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import lmdb
map_size = 1024 * 100
env = lmdb.open('./jp.mdb', map_size=map_size)
with env.begin(write=True) as txn:
txn.put('fr'.encode(), 'France'.encode())
txn.put('nl'.encode(), 'Netherlands'.encode())
txn.put('es'.encode(), 'Spain'.encode())
txn.put('be'.encode(), 'Belgium'.encode())
txn.put('lu'.encode(), 'Luxembourg'.encode())

0 comments on commit 6370c63

Please sign in to comment.