File: test_commit_with_gpg.rb

package info (click to toggle)
ruby-git 1.13.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 4,124 kB
  • sloc: ruby: 5,385; sh: 507; perl: 64; makefile: 6
file content (62 lines) | stat: -rw-r--r-- 1,596 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env ruby

require File.dirname(__FILE__) + '/../test_helper'

class TestCommitWithGPG < Test::Unit::TestCase
  def setup
    set_file_paths
  end

  def test_with_configured_gpg_keyid
    Dir.mktmpdir do |dir|
      git = Git.init(dir)
      actual_cmd = nil
      git.lib.define_singleton_method(:run_command) do |git_cmd, &block|
        actual_cmd = git_cmd
        `true`
      end
      message = 'My commit message'
      git.commit(message, gpg_sign: true)
      assert_match(/commit.*--gpg-sign['"]/, actual_cmd)
    end
  end

  def test_with_specific_gpg_keyid
    Dir.mktmpdir do |dir|
      git = Git.init(dir)
      actual_cmd = nil
      git.lib.define_singleton_method(:run_command) do |git_cmd, &block|
        actual_cmd = git_cmd
        `true`
      end
      message = 'My commit message'
      git.commit(message, gpg_sign: 'keykeykey')
      assert_match(/commit.*--gpg-sign=keykeykey['"]/, actual_cmd)
    end
  end

  def test_disabling_gpg_sign
    Dir.mktmpdir do |dir|
      git = Git.init(dir)
      actual_cmd = nil
      git.lib.define_singleton_method(:run_command) do |git_cmd, &block|
        actual_cmd = git_cmd
        `true`
      end
      message = 'My commit message'
      git.commit(message, no_gpg_sign: true)
      assert_match(/commit.*--no-gpg-sign['"]/, actual_cmd)
    end
  end

  def test_conflicting_gpg_sign_options
    Dir.mktmpdir do |dir|
      git = Git.init(dir)
      message = 'My commit message'

      assert_raises ArgumentError do
        git.commit(message, gpg_sign: true, no_gpg_sign: true)
      end
    end
  end
end