[PATCH v3 20/20] test: add tests for insert
authorPeter Wang <novalazy@gmail.com>
Sun, 20 Jan 2013 00:50:04 +0000 (11:50 +1100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:53:14 +0000 (09:53 -0800)
5b/0b4ddb319cedc9aacc8580012e58de04c43e37 [new file with mode: 0644]

diff --git a/5b/0b4ddb319cedc9aacc8580012e58de04c43e37 b/5b/0b4ddb319cedc9aacc8580012e58de04c43e37
new file mode 100644 (file)
index 0000000..53a87dd
--- /dev/null
@@ -0,0 +1,196 @@
+Return-Path: <novalazy@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 77A7C429E39\r
+       for <notmuch@notmuchmail.org>; Sat, 19 Jan 2013 16:52:29 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id bO3f1TJ0rT0H for <notmuch@notmuchmail.org>;\r
+       Sat, 19 Jan 2013 16:52:27 -0800 (PST)\r
+Received: from mail-da0-f46.google.com (mail-da0-f46.google.com\r
+       [209.85.210.46]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id E2E12429E28\r
+       for <notmuch@notmuchmail.org>; Sat, 19 Jan 2013 16:52:11 -0800 (PST)\r
+Received: by mail-da0-f46.google.com with SMTP id p5so2154476dak.5\r
+       for <notmuch@notmuchmail.org>; Sat, 19 Jan 2013 16:52:11 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+       h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to\r
+       :references; bh=LrcVOKo2VI2PCjAz2TD8/4GlNTBMVK6h7UQdPVgM1TU=;\r
+       b=VVzGWeKX19W1GfMlAGxIM3zW9EmB0UpPpW3pbf1+JapJPpRcw/fcwwiZz/sMUQFV5c\r
+       685i/5ik3vkyEb8Wdz0qznnA/ypxEnQYdszha+hKterdQ2+V+D9OPqtSlkxU+/e2lnO5\r
+       XQ4CKMMOpDpCkFHquVrp4gGWlIQneSoh63cyWBkGBlQ6+y6Q8BkiA9Bh5mGIz12KUb49\r
+       VZ8JK+iT/Riv8prI1E5cIlBp72P+YbvhBQmCEp9Hznw/DYyugIyWSU+VsPL8P6JyUs9m\r
+       UUSKc+5ht2NJnS47Adum3oCVQ+BpeRds+ckrX+joqZBJzV+UhYAsVsAtjVSIyIJAkGMs\r
+       3lCQ==\r
+X-Received: by 10.68.233.201 with SMTP id ty9mr38218668pbc.14.1358643131057;\r
+       Sat, 19 Jan 2013 16:52:11 -0800 (PST)\r
+Received: from localhost (215.42.233.220.static.exetel.com.au.\r
+       [220.233.42.215])\r
+       by mx.google.com with ESMTPS id c2sm6259934pay.34.2013.01.19.16.52.08\r
+       (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+       Sat, 19 Jan 2013 16:52:10 -0800 (PST)\r
+From: Peter Wang <novalazy@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v3 20/20] test: add tests for insert\r
+Date: Sun, 20 Jan 2013 11:50:04 +1100\r
+Message-Id: <1358643004-14522-21-git-send-email-novalazy@gmail.com>\r
+X-Mailer: git-send-email 1.7.12.1\r
+In-Reply-To: <1358643004-14522-1-git-send-email-novalazy@gmail.com>\r
+References: <1358643004-14522-1-git-send-email-novalazy@gmail.com>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 20 Jan 2013 00:52:29 -0000\r
+\r
+Add tests for new 'insert' command.\r
+---\r
+ test/insert       | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ test/notmuch-test |   1 +\r
+ 2 files changed, 107 insertions(+)\r
+ create mode 100755 test/insert\r
+\r
+diff --git a/test/insert b/test/insert\r
+new file mode 100755\r
+index 0000000..a3b6283\r
+--- /dev/null\r
++++ b/test/insert\r
+@@ -0,0 +1,106 @@\r
++#!/usr/bin/env bash\r
++test_description='"notmuch insert"'\r
++. ./test-lib.sh\r
++\r
++# Create directories and database before inserting.\r
++mkdir -p "$MAIL_DIR"/{cur,new,tmp}\r
++mkdir -p "$MAIL_DIR"/Drafts/{cur,new,tmp}\r
++notmuch new > /dev/null\r
++\r
++# We use generate_message to create the temporary message files.\r
++# They happen to be in the mail directory already but that is okay\r
++# since we do not call notmuch new hereafter.\r
++\r
++gen_insert_msg() {\r
++    generate_message \\r
++      "[subject]=\"insert-subject\"" \\r
++      "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" \\r
++      "[body]=\"insert-message\""\r
++}\r
++\r
++test_begin_subtest "Insert message, copied exactly"\r
++gen_insert_msg\r
++notmuch insert < "$gen_msg_filename"\r
++cur_msg_filename=$(notmuch search --output=files "subject:insert-subject")\r
++test_expect_equal_file "$cur_msg_filename" "$gen_msg_filename"\r
++\r
++test_begin_subtest "Insert message, default tags"\r
++output=$(notmuch show --format=json "subject:insert-subject")\r
++expected='[[[{\r
++ "id": "'"${gen_msg_id}"'",\r
++ "match": true,\r
++ "excluded": false,\r
++ "filename": "'"${cur_msg_filename}"'",\r
++ "timestamp": 946728000,\r
++ "date_relative": "2000-01-01",\r
++ "tags": ["inbox","unread"],\r
++ "headers": {\r
++  "Subject": "insert-subject",\r
++  "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",\r
++  "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",\r
++  "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},\r
++ "body": [{"id": 1,\r
++  "content-type": "text/plain",\r
++  "content": "insert-message\n"}]},\r
++ []]]]'\r
++test_expect_equal_json "$output" "$expected"\r
++\r
++test_begin_subtest "Insert message, duplicate message"\r
++notmuch insert < "$gen_msg_filename"\r
++output=$(notmuch search --output=files "subject:insert-subject" | wc -l)\r
++test_expect_equal "$output" 2\r
++\r
++test_begin_subtest "Insert message, add tag"\r
++gen_insert_msg\r
++notmuch insert +custom < "$gen_msg_filename"\r
++output=$(notmuch count tag:custom)\r
++test_expect_equal "$output" "1"\r
++\r
++test_begin_subtest "Insert message, add/remove tag"\r
++gen_insert_msg\r
++notmuch insert +custom -unread < "$gen_msg_filename"\r
++output=$(notmuch count tag:custom NOT tag:unread)\r
++test_expect_equal "$output" "1"\r
++\r
++test_begin_subtest "Insert message, folder"\r
++gen_insert_msg\r
++notmuch insert --folder=Drafts < "$gen_msg_filename"\r
++output=$(notmuch search --output=files folder:Drafts)\r
++dirname=$(dirname "$output")\r
++test_expect_equal "$dirname" "$MAIL_DIR/Drafts/cur"\r
++\r
++test_begin_subtest "Insert message, folder and tags"\r
++gen_insert_msg\r
++notmuch insert --folder=Drafts +draft -unread < "$gen_msg_filename"\r
++output=$(notmuch count folder:Drafts tag:draft NOT tag:unread)\r
++test_expect_equal "$output" "1"\r
++\r
++gen_insert_msg\r
++test_expect_code 1 "Insert message, non-existent folder" \\r
++    "notmuch insert --folder=nonesuch < $gen_msg_filename"\r
++\r
++test_begin_subtest "Insert message, create folder"\r
++gen_insert_msg\r
++notmuch insert --folder=F --create-folder +folder < "$gen_msg_filename"\r
++output=$(notmuch search --output=files folder:F tag:folder)\r
++basename=$(basename "$output")\r
++test_expect_equal_file "$gen_msg_filename" "$MAIL_DIR/F/cur/${basename}"\r
++\r
++test_begin_subtest "Insert message, create subfolder"\r
++gen_insert_msg\r
++notmuch insert --folder=F/G/H/I/J --create-folder +folder < "$gen_msg_filename"\r
++output=$(notmuch search --output=files folder:F/G/H/I/J tag:folder)\r
++basename=$(basename "$output")\r
++test_expect_equal_file "$gen_msg_filename" "${MAIL_DIR}/F/G/H/I/J/cur/${basename}"\r
++\r
++test_begin_subtest "Insert message, create existing subfolder"\r
++gen_insert_msg\r
++notmuch insert --folder=F/G/H/I/J --create-folder +folder < "$gen_msg_filename"\r
++output=$(notmuch count folder:F/G/H/I/J tag:folder)\r
++test_expect_equal "$output" "2"\r
++\r
++gen_insert_msg\r
++test_expect_code 1 "Insert message, create invalid subfolder" \\r
++    "notmuch insert --folder=../G --create-folder $gen_msg_filename"\r
++\r
++test_done\r
+diff --git a/test/notmuch-test b/test/notmuch-test\r
+index ca9c3dc..6952f0a 100755\r
+--- a/test/notmuch-test\r
++++ b/test/notmuch-test\r
+@@ -22,6 +22,7 @@ TESTS="\r
+   config\r
+   new\r
+   count\r
++  insert\r
+   search\r
+   search-output\r
+   search-by-folder\r
+-- \r
+1.7.12.1\r
+\r