From 6370c63efc67000bb749316dcf1b1e80629ed579 Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Fri, 20 Sep 2019 18:54:41 +0200 Subject: [PATCH] lookup: lmdb_kv: add tests --- .../targets/lookup_lmdb_kv/aliases | 2 ++ .../targets/lookup_lmdb_kv/dependencies.yml | 10 ++++++ .../targets/lookup_lmdb_kv/runme.sh | 9 ++++++ .../targets/lookup_lmdb_kv/test.yml | 31 +++++++++++++++++++ .../targets/lookup_lmdb_kv/test_db.py | 11 +++++++ 5 files changed, 63 insertions(+) create mode 100644 test/integration/targets/lookup_lmdb_kv/aliases create mode 100644 test/integration/targets/lookup_lmdb_kv/dependencies.yml create mode 100755 test/integration/targets/lookup_lmdb_kv/runme.sh create mode 100644 test/integration/targets/lookup_lmdb_kv/test.yml create mode 100644 test/integration/targets/lookup_lmdb_kv/test_db.py diff --git a/test/integration/targets/lookup_lmdb_kv/aliases b/test/integration/targets/lookup_lmdb_kv/aliases new file mode 100644 index 00000000000..ca7c9128514 --- /dev/null +++ b/test/integration/targets/lookup_lmdb_kv/aliases @@ -0,0 +1,2 @@ +shippable/posix/group2 +destructive diff --git a/test/integration/targets/lookup_lmdb_kv/dependencies.yml b/test/integration/targets/lookup_lmdb_kv/dependencies.yml new file mode 100644 index 00000000000..db14f6cafda --- /dev/null +++ b/test/integration/targets/lookup_lmdb_kv/dependencies.yml @@ -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 }}" diff --git a/test/integration/targets/lookup_lmdb_kv/runme.sh b/test/integration/targets/lookup_lmdb_kv/runme.sh new file mode 100755 index 00000000000..afdff7bb9d2 --- /dev/null +++ b/test/integration/targets/lookup_lmdb_kv/runme.sh @@ -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 "$@" diff --git a/test/integration/targets/lookup_lmdb_kv/test.yml b/test/integration/targets/lookup_lmdb_kv/test.yml new file mode 100644 index 00000000000..2f713e96095 --- /dev/null +++ b/test/integration/targets/lookup_lmdb_kv/test.yml @@ -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 diff --git a/test/integration/targets/lookup_lmdb_kv/test_db.py b/test/integration/targets/lookup_lmdb_kv/test_db.py new file mode 100644 index 00000000000..f251b7f4a56 --- /dev/null +++ b/test/integration/targets/lookup_lmdb_kv/test_db.py @@ -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())