sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/

test/integration/test_sup-recover-sources.rb (2271B) - raw

      1 require "test_helper"
      2 require "sup"
      3 require "yaml"
      4 
      5 class TestSupRecoverSources < Minitest::Test
      6   def setup
      7     @path = Dir.mktmpdir
      8 
      9     @maildir = File.join @path, "test_maildir"
     10     Dir.mkdir @maildir
     11     %w[cur new tmp].each do |subdir|
     12       Dir.mkdir (File.join @maildir, subdir)
     13     end
     14     msg_path = File.join @maildir, "new", "123.hostname"
     15     FileUtils.copy_file fixture_path("simple-message.eml"), msg_path
     16 
     17     @mbox = File.join @path, "test_mbox"
     18     File.open(@mbox, "wb") do |f|
     19       f.puts "From test@test #{Time.now.asctime}"
     20       f.puts File.read(fixture_path("simple-message.eml"))
     21     end
     22 
     23     _out, _err = capture_subprocess_io do
     24       assert system({"SUP_BASE" => @path}, "bin/sup-add", "maildir://#{@maildir}")
     25       assert system({"SUP_BASE" => @path}, "bin/sup-add", "mbox://#{@mbox}")
     26       assert system({"SUP_BASE" => @path}, "bin/sup-sync")
     27     end
     28   end
     29 
     30   def teardown
     31     FileUtils.rm_r @path
     32   end
     33 
     34   def test_recover_sources
     35     File.delete File.join(@path, "sources.yaml")
     36     source_uris = ["maildir://#{@maildir}", "mbox://#{@mbox}"]
     37     out, _err = capture_subprocess_io do
     38       assert system({"SUP_BASE" => @path}, "bin/sup-recover-sources", *source_uris)
     39     end
     40     assert_equal "assigned #{source_uris[0]} to 1\n", out.lines[0]
     41     assert_equal "assigned #{source_uris[1]} to 2\n", out.lines[1]
     42 
     43     sources_fn = File.join @path, "sources.yaml"
     44     sources_yaml =
     45       if YAML.respond_to?(:unsafe_load_file)  # Ruby 3.1+
     46         YAML::unsafe_load_file sources_fn
     47       else
     48         YAML::load_file sources_fn
     49       end
     50     assert_equal 2, sources_yaml.length
     51     assert_instance_of Redwood::Maildir, sources_yaml[0]
     52     assert_equal source_uris[0], sources_yaml[0].uri
     53     assert_equal 1, sources_yaml[0].id
     54     assert_instance_of Redwood::MBox, sources_yaml[1]
     55     assert_equal source_uris[1], sources_yaml[1].uri
     56     assert_equal 2, sources_yaml[1].id
     57   end
     58 
     59   def test_noop
     60     ## All sources are already defined in sources.yaml so there is nothing to recover.
     61     ## It should do nothing.
     62     source_uris = ["maildir://#{@maildir}", "mbox://#{@mbox}"]
     63     out, _err = capture_subprocess_io do
     64       assert system({"SUP_BASE" => @path}, "bin/sup-recover-sources", *source_uris)
     65     end
     66     assert out.empty?
     67   end
     68 end