lookup: lmdb_kv: add tests

This commit is contained in:
Rene Moser 2019-09-20 18:54:41 +02:00 committed by René Moser
parent a2270ead2f
commit 6370c63efc
5 changed files with 63 additions and 0 deletions

View file

@ -0,0 +1,2 @@
shippable/posix/group2
destructive

View file

@ -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 }}"

View file

@ -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 "$@"

View file

@ -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

View file

@ -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())