mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-12-22 01:14:53 +01:00
test: use notmuch_json_show_sanitize more places
This makes the tests more robust against changing output formats, by allowing us to centralize fixes in the sanitization function. It is not appropriate for all cases, in particular it is unneeded when using test_json_nodes, and unhelpful when testing filenames.
This commit is contained in:
parent
3cb936b7c4
commit
5f6645bd2a
4 changed files with 27 additions and 26 deletions
|
@ -43,13 +43,13 @@ test_begin_subtest "Permissions on inserted message should be 0600"
|
|||
test_expect_equal "600" "$(stat -c %a "$cur_msg_filename")"
|
||||
|
||||
test_begin_subtest "Insert message adds default tags"
|
||||
output=$(notmuch show --format=json "subject:insert-subject")
|
||||
output=$(notmuch show --format=json "subject:insert-subject" | notmuch_json_show_sanitize)
|
||||
expected='[[[{
|
||||
"id": "'"${gen_msg_id}"'",
|
||||
"id": "XXXXX",
|
||||
"crypto": {},
|
||||
"match": true,
|
||||
"excluded": false,
|
||||
"filename": ["'"${cur_msg_filename}"'"],
|
||||
"filename": ["YYYYY"],
|
||||
"timestamp": 946728000,
|
||||
"date_relative": "2000-01-01",
|
||||
"tags": ["inbox","unread"],
|
||||
|
|
|
@ -5,17 +5,17 @@ test_description="--format=json output"
|
|||
|
||||
test_begin_subtest "Show message: json"
|
||||
add_message "[subject]=\"json-show-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[bcc]=\"test_suite+bcc@notmuchmail.org\"" "[reply-to]=\"test_suite+replyto@notmuchmail.org\"" "[body]=\"json-show-message\""
|
||||
output=$(notmuch show --format=json "json-show-message")
|
||||
test_expect_equal_json "$output" "[[[{\"id\": \"${gen_msg_id}\", \"crypto\": {}, \"match\": true, \"excluded\": false, \"filename\": [\"${gen_msg_filename}\"], \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], \"headers\": {\"Subject\": \"json-show-subject\", \"From\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"To\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"Bcc\": \"test_suite+bcc@notmuchmail.org\", \"Reply-To\": \"test_suite+replyto@notmuchmail.org\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 +0000\"}, \"body\": [{\"id\": 1, \"content-type\": \"text/plain\", \"content\": \"json-show-message\n\"}]}, []]]]"
|
||||
output=$(notmuch show --format=json "json-show-message" | notmuch_json_show_sanitize)
|
||||
test_expect_equal_json "$output" "[[[{\"id\": \"XXXXX\", \"crypto\": {}, \"match\": true, \"excluded\": false, \"filename\": [\"YYYYY\"], \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], \"headers\": {\"Subject\": \"json-show-subject\", \"From\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"To\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"Bcc\": \"test_suite+bcc@notmuchmail.org\", \"Reply-To\": \"test_suite+replyto@notmuchmail.org\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 +0000\"}, \"body\": [{\"id\": 1, \"content-type\": \"text/plain\", \"content\": \"json-show-message\n\"}]}, []]]]"
|
||||
|
||||
# This should be the same output as above.
|
||||
test_begin_subtest "Show message: json --body=true"
|
||||
output=$(notmuch show --format=json --body=true "json-show-message")
|
||||
test_expect_equal_json "$output" "[[[{\"id\": \"${gen_msg_id}\", \"crypto\": {}, \"match\": true, \"excluded\": false, \"filename\": [\"${gen_msg_filename}\"], \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], \"headers\": {\"Subject\": \"json-show-subject\", \"From\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"To\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"Bcc\": \"test_suite+bcc@notmuchmail.org\", \"Reply-To\": \"test_suite+replyto@notmuchmail.org\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 +0000\"}, \"body\": [{\"id\": 1, \"content-type\": \"text/plain\", \"content\": \"json-show-message\n\"}]}, []]]]"
|
||||
output=$(notmuch show --format=json --body=true "json-show-message" | notmuch_json_show_sanitize)
|
||||
test_expect_equal_json "$output" "[[[{\"id\": \"XXXXX\", \"crypto\": {}, \"match\": true, \"excluded\": false, \"filename\": [\"YYYYY\"], \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], \"headers\": {\"Subject\": \"json-show-subject\", \"From\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"To\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"Bcc\": \"test_suite+bcc@notmuchmail.org\", \"Reply-To\": \"test_suite+replyto@notmuchmail.org\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 +0000\"}, \"body\": [{\"id\": 1, \"content-type\": \"text/plain\", \"content\": \"json-show-message\n\"}]}, []]]]"
|
||||
|
||||
test_begin_subtest "Show message: json --body=false"
|
||||
output=$(notmuch show --format=json --body=false "json-show-message")
|
||||
test_expect_equal_json "$output" "[[[{\"id\": \"${gen_msg_id}\", \"crypto\": {}, \"match\": true, \"excluded\": false, \"filename\": [\"${gen_msg_filename}\"], \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], \"headers\": {\"Subject\": \"json-show-subject\", \"From\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"To\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"Bcc\": \"test_suite+bcc@notmuchmail.org\", \"Reply-To\": \"test_suite+replyto@notmuchmail.org\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 +0000\"}}, []]]]"
|
||||
output=$(notmuch show --format=json --body=false "json-show-message" | notmuch_json_show_sanitize)
|
||||
test_expect_equal_json "$output" "[[[{\"id\": \"XXXXX\", \"crypto\": {}, \"match\": true, \"excluded\": false, \"filename\": [\"YYYYY\"], \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], \"headers\": {\"Subject\": \"json-show-subject\", \"From\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"To\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"Bcc\": \"test_suite+bcc@notmuchmail.org\", \"Reply-To\": \"test_suite+replyto@notmuchmail.org\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 +0000\"}}, []]]]"
|
||||
|
||||
test_begin_subtest "Search message: json"
|
||||
add_message "[subject]=\"json-search-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"json-search-message\""
|
||||
|
@ -33,8 +33,8 @@ test_expect_equal_json "$output" "[{\"thread\": \"XXX\",
|
|||
|
||||
test_begin_subtest "Show message: json, utf-8"
|
||||
add_message "[subject]=\"json-show-utf8-body-sübjéct\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"jsön-show-méssage\""
|
||||
output=$(notmuch show --format=json "jsön-show-méssage")
|
||||
test_expect_equal_json "$output" "[[[{\"id\": \"${gen_msg_id}\", \"crypto\": {}, \"match\": true, \"excluded\": false, \"filename\": [\"${gen_msg_filename}\"], \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], \"headers\": {\"Subject\": \"json-show-utf8-body-sübjéct\", \"From\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"To\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 +0000\"}, \"body\": [{\"id\": 1, \"content-type\": \"text/plain\", \"content\": \"jsön-show-méssage\n\"}]}, []]]]"
|
||||
output=$(notmuch show --format=json "jsön-show-méssage" | notmuch_json_show_sanitize)
|
||||
test_expect_equal_json "$output" "[[[{\"id\": \"XXXXX\", \"crypto\": {}, \"match\": true, \"excluded\": false, \"filename\": [\"YYYYY\"], \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], \"headers\": {\"Subject\": \"json-show-utf8-body-sübjéct\", \"From\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"To\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 +0000\"}, \"body\": [{\"id\": 1, \"content-type\": \"text/plain\", \"content\": \"jsön-show-méssage\n\"}]}, []]]]"
|
||||
|
||||
test_begin_subtest "Show message: json, inline attachment filename"
|
||||
subject='json-show-inline-attachment-filename'
|
||||
|
|
|
@ -376,18 +376,18 @@ test_begin_subtest "--format=text --part=8, no part, expect error"
|
|||
test_expect_success "notmuch show --format=text --part=8 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
|
||||
|
||||
test_begin_subtest "--format=json --part=0, full message"
|
||||
notmuch show --format=json --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
|
||||
notmuch show --format=json --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' | notmuch_json_show_sanitize >OUTPUT
|
||||
cat <<EOF >EXPECTED
|
||||
{"id": "87liy5ap00.fsf@yoom.home.cworth.org", "crypto": {}, "match": true, "excluded": false, "filename": ["${MAIL_DIR}/multipart"], "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["attachment","inbox","signed","unread"], "headers": {"Subject": "Multipart message", "From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [
|
||||
{"id": "XXXXX", "crypto": {}, "match": true, "excluded": false, "filename": ["YYYYY"], "timestamp": 42, "date_relative": "2001-01-05", "tags": ["attachment","inbox","signed","unread"], "headers": {"Subject": "Multipart message", "From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Date": "GENERATED_DATE"}, "body": [
|
||||
{"id": 1, "content-type": "multipart/signed", "content": [
|
||||
{"id": 2, "content-type": "multipart/mixed", "content": [
|
||||
{"id": 3, "content-type": "message/rfc822", "content-disposition": "inline", "content": [{"headers": {"Subject": "html message", "From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Date": "Fri, 05 Jan 2001 15:42:57 +0000"}, "body": [
|
||||
{"id": 3, "content-type": "message/rfc822", "content-disposition": "inline", "content": [{"headers": {"Subject": "html message", "From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Date": "GENERATED_DATE"}, "body": [
|
||||
{"id": 4, "content-type": "multipart/alternative", "content": [
|
||||
{"id": 5, "content-type": "text/html", "content-length": 71},
|
||||
{"id": 5, "content-type": "text/html", "content-length": "NONZERO"},
|
||||
{"id": 6, "content-type": "text/plain", "content": "This is an embedded message, with a multipart/alternative part.\n"}]}]}]},
|
||||
{"id": 7, "content-type": "text/plain", "content-disposition": "attachment", "filename": "attachment", "content": "This is a text attachment.\n"},
|
||||
{"id": 8, "content-type": "text/plain", "content": "And this message is signed.\n\n-Carl\n"}]},
|
||||
{"id": 9, "content-type": "application/pgp-signature", "content-length": 197}]}]}
|
||||
{"id": 9, "content-type": "application/pgp-signature", "content-length": "NONZERO"}]}]}
|
||||
EOF
|
||||
test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
|
||||
|
||||
|
@ -485,7 +485,7 @@ notmuch show --format=raw 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
|
|||
test_expect_equal_file "${MAIL_DIR}"/multipart OUTPUT
|
||||
|
||||
test_begin_subtest "--format=raw --part=0, full message"
|
||||
notmuch show --format=raw --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
|
||||
notmuch show --format=raw --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' | notmuch_json_show_sanitize >OUTPUT
|
||||
test_expect_equal_file "${MAIL_DIR}"/multipart OUTPUT
|
||||
|
||||
test_begin_subtest "--format=raw --part=1, message body"
|
||||
|
@ -727,10 +727,10 @@ notmuch new > /dev/null
|
|||
|
||||
cat_expected_head () {
|
||||
cat <<EOF
|
||||
[[[{"id": "htmlmessage", "match":true, "excluded": false, "date_relative":"2000-01-01",
|
||||
[[[{"id": "XXXXX", "match":true, "excluded": false, "date_relative":"2000-01-01",
|
||||
"crypto": {},
|
||||
"timestamp": 946684800,
|
||||
"filename": ["${MAIL_DIR}/include-html"],
|
||||
"filename": ["YYYYY"],
|
||||
"tags": ["inbox", "unread"],
|
||||
"headers": { "Date": "Sat, 01 Jan 2000 00:00:00 +0000", "From": "A <a@example.com>",
|
||||
"Subject": "html message", "To": "B <b@example.com>"},
|
||||
|
@ -742,8 +742,8 @@ EOF
|
|||
cat_expected_head > EXPECTED.nohtml
|
||||
cat <<EOF >> EXPECTED.nohtml
|
||||
"content": [
|
||||
{ "id": 2, "content-charset": "UTF-8", "content-length": 21, "content-type": "text/html"},
|
||||
{ "id": 3, "content-charset": "ISO-8859-1", "content-length": 20, "content-type": "text/html"},
|
||||
{ "id": 2, "content-charset": "UTF-8", "content-length": "NONZERO", "content-type": "text/html"},
|
||||
{ "id": 3, "content-charset": "ISO-8859-1", "content-length": "NONZERO", "content-type": "text/html"},
|
||||
{ "id": 4, "content-type": "text/plain", "content": "0.5 equals \\u00bd\\n"}
|
||||
]}]},[]]]]
|
||||
EOF
|
||||
|
@ -759,11 +759,11 @@ cat <<EOF >> EXPECTED.withhtml
|
|||
EOF
|
||||
|
||||
test_begin_subtest "html parts excluded by default"
|
||||
notmuch show --format=json id:htmlmessage > OUTPUT
|
||||
notmuch show --format=json id:htmlmessage | notmuch_json_show_sanitize > OUTPUT
|
||||
test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED.nohtml)"
|
||||
|
||||
test_begin_subtest "html parts included"
|
||||
notmuch show --format=json --include-html id:htmlmessage > OUTPUT
|
||||
notmuch show --format=json --include-html id:htmlmessage | notmuch_json_show_sanitize > OUTPUT
|
||||
test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED.withhtml)"
|
||||
|
||||
test_begin_subtest "indexes mime-type #1"
|
||||
|
|
|
@ -298,7 +298,8 @@ On Tue, 05 Jan 2010 15:43:56 -0000, ☃ <snowman@example.com> wrote:
|
|||
OK"
|
||||
|
||||
test_begin_subtest "Reply with RFC 2047-encoded headers (JSON)"
|
||||
output=$(echo '{"answer":' && notmuch reply --format=json id:${gen_msg_id} 2>&1 && echo ', "success": "OK"}')
|
||||
output=$(echo '{"answer":' && notmuch reply --format=json id:${gen_msg_id} 2>&1 | notmuch_json_show_sanitize \
|
||||
&& echo ', "success": "OK"}')
|
||||
test_expect_equal_json "$output" '
|
||||
{ "answer": {
|
||||
"original": {
|
||||
|
@ -312,14 +313,14 @@ test_expect_equal_json "$output" '
|
|||
"crypto": {},
|
||||
"date_relative": "2010-01-05",
|
||||
"excluded": false,
|
||||
"filename": ["'${MAIL_DIR}'/msg-015"],
|
||||
"filename": ["YYYYY"],
|
||||
"headers": {
|
||||
"Date": "Tue, 05 Jan 2010 15:43:56 +0000",
|
||||
"From": "\u2603 <snowman@example.com>",
|
||||
"Subject": "\u00e0\u00df\u00e7",
|
||||
"To": "Notmuch Test Suite <test_suite@notmuchmail.org>"
|
||||
},
|
||||
"id": "'${gen_msg_id}'",
|
||||
"id": "XXXXX",
|
||||
"match": false,
|
||||
"tags": [
|
||||
"inbox",
|
||||
|
|
Loading…
Reference in a new issue