File: test_command_map.rb

package info (click to toggle)
ruby-sshkit 1.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 604 kB
  • ctags: 619
  • sloc: ruby: 3,045; makefile: 2
file content (69 lines) | stat: -rw-r--r-- 1,955 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
63
64
65
66
67
68
69
require 'helper'
require 'sshkit'

module SSHKit
  class TestCommandMap < UnitTest

    def test_defaults
      map = CommandMap.new
      assert_equal map[:rake], "/usr/bin/env rake"
      assert_equal map[:test], "test"
    end

    def test_setter
      map = CommandMap.new
      map[:rake] = "/usr/local/rbenv/shims/rake"
      assert_equal map[:rake], "/usr/local/rbenv/shims/rake"
    end

    def test_prefix
      map = CommandMap.new
      map.prefix[:rake].push("/home/vagrant/.rbenv/bin/rbenv exec")
      map.prefix[:rake].push("bundle exec")

      assert_equal map[:rake], "/home/vagrant/.rbenv/bin/rbenv exec bundle exec rake"
    end

    def test_prefix_procs
      map = CommandMap.new
      map.prefix[:rake].push("/home/vagrant/.rbenv/bin/rbenv exec")
      map.prefix[:rake].push(proc{ "bundle exec" })

      assert_equal map[:rake], "/home/vagrant/.rbenv/bin/rbenv exec bundle exec rake"
    end

    def test_prefix_unshift
      map = CommandMap.new
      map.prefix[:rake].push("bundle exec")
      map.prefix[:rake].unshift("/home/vagrant/.rbenv/bin/rbenv exec")

      assert_equal map[:rake], "/home/vagrant/.rbenv/bin/rbenv exec bundle exec rake"
    end

    def test_indifferent_setter
      map = CommandMap.new
      map[:rake] = "/usr/local/rbenv/shims/rake"
      map["rake"] = "/usr/local/rbenv/shims/rake2"

      assert_equal "/usr/local/rbenv/shims/rake2", map[:rake]
    end

    def test_indifferent_prefix
      map = CommandMap.new
      map.prefix[:rake].push("/home/vagrant/.rbenv/bin/rbenv exec")
      map.prefix["rake"].push("bundle exec")

      assert_equal map[:rake], "/home/vagrant/.rbenv/bin/rbenv exec bundle exec rake"
    end

    def test_prefix_initialization_is_thread_safe
      map = CommandMap.new
      threads = Array.new(3) do
        Thread.new do
          (1..1_000).each { |i| assert_equal([], map.prefix[i.to_s]) }
        end
      end
      threads.each(&:join)
    end
  end
end