BULK: Fix recursion of next command results.
[pwmd.git] / tests / import.test
blob7d503ac182b664c59ec062a821678869cac5afa5
1 #!/bin/bash
2 source common.sh
3 source import-common.sh
5 do_import list
7 cat > config << EOF
8 [global]
9 log_level=9
10 #enable_logging=true
11 [import]
12 passphrase_file=`pwd`/passphrase.key
13 EOF
15 set -e
16 mv -f data/list data/import
17 launch_pwmd import
19 begin_test
20 test_header "Test 1. Import invalid syntax (fail)."
21 set +o errexit
22 cat << EOF | pwmc $PWMC_ARGS --inquire IMPORT import
23 <element _name="import">import value</invalid>
24 EOF
25 if [ ${PIPESTATUS[1]} == 0 ]; then
26 echo "The previous command should have failed. Stopping."
27 exit 1
30 set -e
32 echo
33 test_header "Test 2. Import to root."
34 cat << EOF | pwmc $PWMC_ARGS --inquire IMPORT import -S
35 <element _name="import">import value</element>
36 EOF
37 echo -ne 'GET import' | pwmc $PWMC_ARGS import > result
38 cmp import.result2 result
39 rm -f result
41 echo
42 test_header "Test 3. Import to root (overwrite)."
43 cat << EOF | pwmc $PWMC_ARGS --inquire IMPORT import -S
44 <element _name="import">new import value</element>
45 EOF
46 echo -ne 'GET import' | pwmc $PWMC_ARGS import > result
47 cmp import.result3 result
48 rm -f result
50 echo
51 test_header "Test 4. Import to child."
52 cat << EOF | tr -d '\n' | pwmc $PWMC_ARGS --inquire "IMPORT --root=import" import -S
53 <element _name="child">child import value</element>
54 EOF
55 echo -ne 'GET import\tchild' | pwmc $PWMC_ARGS import > result
56 cmp import.result4 result
57 rm -f result
59 echo
60 test_header "Test 5. Import to child (overwrite)."
61 cat << EOF | tr -d '\n' | pwmc $PWMC_ARGS --inquire "IMPORT --root=import" import -S
62 <element _name="child">new child import value</element>
63 EOF
64 echo -ne 'GET import\tchild' | pwmc $PWMC_ARGS import > result
65 cmp import.result5 result
66 rm -f result
68 echo
69 test_header "Test 6. Import siblings."
70 cat << EOF | tr -d '\n' | pwmc $PWMC_ARGS --inquire "IMPORT --root=import\troot" import -S
71 <element _name="a">A value<element _name="b">A B value</element></element>
72 <element _name="b">B value</element>
73 EOF
74 echo -ne 'GET import\troot\ta\tb' | pwmc $PWMC_ARGS import > result
75 cmp import.result6 result
76 rm -f result
78 echo
79 test_header "Test 7. Import siblings (overwrite)."
80 cat << EOF | tr -d '\n' | pwmc $PWMC_ARGS --inquire "IMPORT --root=import\troot" import -S
81 <element _name="a">A value<element _name="b"/></element>
82 <element _name="b">B value</element>
83 EOF
84 echo -ne 'GET import\troot\tb' | pwmc $PWMC_ARGS import > result
85 cmp import.result7 result
86 rm -f result
88 echo
89 test_header "Test 8. Import siblings (fail)."
90 set +o errexit
91 echo -ne 'GET import\troot\ta\tb' | pwmc $PWMC_ARGS import > result
93 if [ ${PIPESTATUS[1]} == 0 ]; then
94 echo "The previous command should have failed. Stopping."
95 exit 1
98 set -e
100 test_success