test_prep_release.rb 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # -*- coding: utf-8 -*-
  2. # -*- frozen_string_literal: true -*-
  3. require "tmpdir"
  4. require "tempfile"
  5. require_relative "./../../_config/minitest"
  6. require_relative "./../../../dev/tasks/prep_release"
  7. # test dependency:
  8. require "sdbm"
  9. class TestPrepRelease < Minitest::Test
  10. def test_can_build_gem_without_warnings
  11. skip "Integration: Building gems takes too long" unless ENV["LORCA_ALL_TESTS"]
  12. _, err = capture_subprocess_io { LorcaPrepRelease.package }
  13. refute_match %r/warning/i, err
  14. end
  15. def test_imports_eff_wordlist
  16. wordlist = File.expand_path "./../../../_fixtures/dev/wordlist.txt", __FILE__
  17. Dir.mktmpdir do |dir|
  18. LorcaPrepRelease.import_wordlist wordlist, to: dir
  19. imported = "#{dir}/wordlist"
  20. # no need to replace it with Lorca. The point is to check the wordlist got
  21. # imported not that Lorca can read it.
  22. SDBM.open(imported, 0444) { |db| assert_equal "c", db.fetch("11113") }
  23. end
  24. end
  25. def test_generates_checksum_for_packed_gem
  26. expected_checksum =
  27. "bb95b01232696ce38a4ca482aebc5b7037744621eddb37071e543ad55c38db0c"\
  28. "ba0317f089916576b52f3eaddfac0dd3495057ce0fc415032bab04ef3539d2ee"
  29. Dir.mktmpdir do |_|
  30. gem = Tempfile.new.tap{ |g| g.write "ah" }.tap(&:close)
  31. checksum = LorcaPrepRelease.checksum gem, archive: _
  32. assert_equal expected_checksum, checksum
  33. end
  34. end
  35. def test_writes_checksum_to_given_directory
  36. Dir.mktmpdir do |dir|
  37. tempfile = Tempfile.new
  38. basename = File.basename tempfile
  39. LorcaPrepRelease.checksum tempfile, archive: dir
  40. assert File.exist?("#{dir}/#{basename}.sha512"), "Missing checksum"
  41. end
  42. end
  43. def test_fails_to_commit_checksum_when_checksum_missing
  44. Dir.mktmpdir do |dir|
  45. e = assert_raises { LorcaPrepRelease.commit_checksum archive: dir }
  46. assert_equal "Must create checksum file before trying to do commit",
  47. e.message
  48. end
  49. end
  50. def test_fails_to_tag_release_commit_when_checksum_missing
  51. Dir.mktmpdir do |dir|
  52. e = assert_raises { LorcaPrepRelease.tag_release_commit archive: dir }
  53. assert_equal "Must add checksum before tagging a release", e.message
  54. end
  55. end
  56. def test_publishes_gem
  57. assert_respond_to LorcaPrepRelease, :publish_gem
  58. end
  59. end