| 1 |
#!/usr/bin/env bash |
| 2 |
|
| 3 |
test_description='cli' |
| 4 |
|
| 5 |
. lib/test-lib.sh |
| 6 |
|
| 7 |
################################################################ |
| 8 |
|
| 9 |
test_expect_code 5 'dump non-existant db' \ |
| 10 |
'impass dump' |
| 11 |
|
| 12 |
test_expect_success 'add first entry' \ |
| 13 |
'impass add foo@bar' |
| 14 |
|
| 15 |
test_expect_success 'add second entry' \ |
| 16 |
"impass add 'baz asdf Dokw okb 32438uoijdf'" |
| 17 |
|
| 18 |
test_expect_code 2 'add existing context' \ |
| 19 |
'impass add foo@bar' |
| 20 |
|
| 21 |
test_begin_subtest "dump all entries" |
| 22 |
impass dump 2>&1 | sed 's/"date": ".*"/FOO/g' >OUTPUT |
| 23 |
cat <<EOF >EXPECTED |
| 24 |
{ |
| 25 |
"baz asdf Dokw okb 32438uoijdf": { |
| 26 |
FOO |
| 27 |
}, |
| 28 |
"foo@bar": { |
| 29 |
FOO |
| 30 |
} |
| 31 |
} |
| 32 |
EOF |
| 33 |
test_expect_equal_file OUTPUT EXPECTED |
| 34 |
|
| 35 |
test_begin_subtest "dump search 0" |
| 36 |
impass dump foo 2>&1 | sed 's/"date": ".*"/FOO/g' >OUTPUT |
| 37 |
cat <<EOF >EXPECTED |
| 38 |
{ |
| 39 |
"foo@bar": { |
| 40 |
FOO |
| 41 |
} |
| 42 |
} |
| 43 |
EOF |
| 44 |
test_expect_equal_file OUTPUT EXPECTED |
| 45 |
|
| 46 |
test_begin_subtest "dump search 1" |
| 47 |
impass dump asdf 2>&1 | sed 's/"date": ".*"/FOO/g' >OUTPUT |
| 48 |
cat <<EOF >EXPECTED |
| 49 |
{ |
| 50 |
"baz asdf Dokw okb 32438uoijdf": { |
| 51 |
FOO |
| 52 |
} |
| 53 |
} |
| 54 |
EOF |
| 55 |
test_expect_equal_file OUTPUT EXPECTED |
| 56 |
|
| 57 |
test_begin_subtest "dump search 2" |
| 58 |
impass dump ba 2>&1 | sed 's/"date": ".*"/FOO/g' >OUTPUT |
| 59 |
cat <<EOF >EXPECTED |
| 60 |
{ |
| 61 |
"baz asdf Dokw okb 32438uoijdf": { |
| 62 |
FOO |
| 63 |
}, |
| 64 |
"foo@bar": { |
| 65 |
FOO |
| 66 |
} |
| 67 |
} |
| 68 |
EOF |
| 69 |
test_expect_equal_file OUTPUT EXPECTED |
| 70 |
|
| 71 |
test_expect_code 2 'add existing context' 'impass add foo@bar' |
| 72 |
|
| 73 |
test_expect_code 2 'replace non-existing context' \ |
| 74 |
'impass replace aaaa' |
| 75 |
# FIXME: add replacement test |
| 76 |
|
| 77 |
test_expect_code 2 'update non-existing context' \ |
| 78 |
'impass update aaaa' |
| 79 |
test_begin_subtest "update entry" |
| 80 |
impass update foo@bar foo@example |
| 81 |
impass dump foo 2>&1 | sed 's/"date": ".*"/FOO/g' >OUTPUT |
| 82 |
cat <<EOF >EXPECTED |
| 83 |
{ |
| 84 |
"foo@example": { |
| 85 |
FOO |
| 86 |
} |
| 87 |
} |
| 88 |
EOF |
| 89 |
test_expect_equal_file OUTPUT EXPECTED |
| 90 |
|
| 91 |
test_expect_code 2 'remove non-existant entry' 'impass remove aaaa' |
| 92 |
test_begin_subtest "remove entry" |
| 93 |
echo yes | impass remove foo@example |
| 94 |
impass dump 2>&1 | sed 's/"date": ".*"/FOO/g' >OUTPUT |
| 95 |
cat <<EOF >EXPECTED |
| 96 |
{ |
| 97 |
"baz asdf Dokw okb 32438uoijdf": { |
| 98 |
FOO |
| 99 |
} |
| 100 |
} |
| 101 |
EOF |
| 102 |
test_expect_equal_file OUTPUT EXPECTED |
| 103 |
|
| 104 |
################################################################ |
| 105 |
|
| 106 |
test_done |