sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit f291f7f35f4a67ab42bef5e30d51b784e1261450
parent dbc841a41778506745eadebeb6ff759b6886cc98
Author: Scott Bonds <scott@ggr.com>
Date:   Mon, 22 Sep 2014 13:19:12 -0700

source uri: set up tests

stub maildir and mbox tests

experiments with tests

got tests for special characters working

use the same approach for mbox and maildir testing

use the old minitest naming to make Travis happy

remove extra line in email

Diffstat:
A test/integration/test_maildir.rb | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A test/integration/test_mbox.rb | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 144 insertions(+), 0 deletions(-)
diff --git a/test/integration/test_maildir.rb b/test/integration/test_maildir.rb
@@ -0,0 +1,75 @@
+require "test_helper"
+
+class TestMaildir < MiniTest::Unit::TestCase
+
+  def setup
+    @path = Dir.mktmpdir
+
+    @test_message_1 = <<EOS
+From: Bob <bob@bob.com>
+To: a dear friend
+
+Hello there friend. How are you? Blah is blah blah.
+Wow. Maildir FTW, am I right?
+EOS
+
+  end
+
+  def teardown
+    ObjectSpace.each_object(Class).select {|a| a < Redwood::Singleton}.each do |klass|
+      klass.deinstantiate! unless klass == Redwood::Logger
+    end
+    FileUtils.rm_r @path
+  end
+
+  def create_a_maildir(extra='')
+    maildir = File.join @path, "test_maildir#{extra}"
+    ['', 'cur', 'new', 'tmp'].each do |dir|
+      Dir.mkdir(File.join maildir, dir)
+    end
+    maildir
+  end
+
+  def create_a_maildir_email(folder, content)
+    File.write(File.join(folder, "#{Time.now.to_f}.hostname:2,S"), content)
+  end
+
+  def start_sup_and_add_source(source)
+    start
+    Index.init @path
+    Index.load
+    SourceManager.instance.instance_eval '@sources = {}'
+    SourceManager.instance.add_source source
+    PollManager.poll_from source
+  end
+
+  # and now, let the tests begin!
+
+  def test_can_index_a_maildir_directory
+
+    maildir = create_a_maildir
+    create_a_maildir_email(File.join(maildir, 'cur'), @test_message_1)
+    start_sup_and_add_source Maildir.new "maildir:#{maildir}"
+
+    messages_in_index = []
+    Index.instance.each_message {|a| messages_in_index << a}
+    refute_empty messages_in_index, 'There are no messages in the index'
+    assert_equal(messages_in_index.first.raw_message, @test_message_1)
+
+  end
+
+  def test_can_index_a_maildir_directory_with_special_characters
+
+    maildir = create_a_maildir URI_ENCODE_CHARS
+    create_a_maildir_email(File.join(maildir, 'cur'), @test_message_1)
+    start_sup_and_add_source Maildir.new "maildir:#{maildir}"
+
+    messages_in_index = []
+    Index.instance.each_message {|a| messages_in_index << a}
+    refute_empty messages_in_index, 'There are no messages in the index'
+    assert_equal(messages_in_index.first.raw_message, @test_message_1)
+
+  end
+
+end
+
diff --git a/test/integration/test_mbox.rb b/test/integration/test_mbox.rb
@@ -0,0 +1,69 @@
+require "test_helper"
+
+class TestMbox < MiniTest::Unit::TestCase
+
+  def setup
+    @path = Dir.mktmpdir
+
+    @test_message_1 = <<EOS
+From sup-talk-bounces@rubyforge.org Mon Apr 27 12:56:18 2009
+From: Bob <bob@bob.com>
+To: Joe <joe@joe.com>
+
+Hello there friend. How are you? Blah is blah blah.
+I like mboxes, don't you?
+EOS
+
+  end
+
+  def teardown
+    ObjectSpace.each_object(Class).select {|a| a < Redwood::Singleton}.each do |klass|
+      klass.deinstantiate! unless klass == Redwood::Logger
+    end
+    FileUtils.rm_r @path
+  end
+
+  def create_a_mbox(extra='')
+    mbox = File.join(@path, "test_mbox#{extra}.mbox")
+    File.write(mbox, @test_message_1)
+    mbox
+  end
+
+  def start_sup_and_add_source(source)
+    start
+    Index.init @path
+    Index.load
+    SourceManager.instance.instance_eval '@sources = {}'
+    SourceManager.instance.add_source source
+    PollManager.poll_from source
+  end
+
+  # and now, let the tests begin!
+
+  def test_can_index_a_mbox_directory
+
+    mbox = create_a_mbox
+    start_sup_and_add_source MBox.new "mbox:#{mbox}"
+
+    messages_in_index = []
+    Index.instance.each_message {|a| messages_in_index << a}
+    refute_empty messages_in_index, 'There are no messages in the index'
+    test_message_without_first_line = @test_message_1.sub(/^.*\n/,'')
+    assert_equal(messages_in_index.first.raw_message, test_message_without_first_line)
+
+  end
+
+  def test_can_index_a_mbox_directory_with_special_characters
+
+    mbox = create_a_mbox URI_ENCODE_CHARS
+    start_sup_and_add_source MBox.new "mbox:#{mbox}"
+
+    messages_in_index = []
+    Index.instance.each_message {|a| messages_in_index << a}
+    refute_empty messages_in_index, 'There are no messages in the index'
+    test_message_without_first_line = @test_message_1.sub(/^.*\n/,'')
+    assert_equal(messages_in_index.first.raw_message, test_message_without_first_line)
+
+  end
+
+end