Debian Codegraph @

test/integration/targets/inventory_cache/runme.sh

raw
1 #!/usr/bin/env bash
2
3 set -eux
4
5 export ANSIBLE_INVENTORY_PLUGINS=./plugins/inventory
6
7 cleanup() {
8 for f in ./cache/ansible_inventory*; do
9 if [ -f "$f" ]; then rm -rf "$f"; fi
10 done
11 }
12
13 trap 'cleanup' EXIT
14
15 # Test no warning when writing to the cache for the first time
16 test "$(ansible-inventory -i cache_host.yml --graph 2>&1 | tee out.txt | grep -c '\[WARNING\]')" = 0
17 writehost="$(grep "testhost[0-9]\{1,2\}" out.txt)"
18
19 # Test reading from the cache
20 test "$(ansible-inventory -i cache_host.yml --graph 2>&1 | tee out.txt | grep -c '\[WARNING\]')" = 0
21 readhost="$(grep 'testhost[0-9]\{1,2\}' out.txt)"
22
23 test "$readhost" = "$writehost"
24
25 test "$(ansible-inventory -i exercise_cache.yml --graph 2>&1 | grep -c '\[WARNING\]')" = 0