jstorimer-deep-test 1.4.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. data/.gitignore +1 -0
  2. data/README.rdoc +41 -70
  3. data/Rakefile +47 -119
  4. data/TODO +2 -2
  5. data/VERSION +1 -1
  6. data/infrastructure/dynamic_teardown.rb +22 -0
  7. data/{test → infrastructure}/fake_deadlock_error.rb +0 -0
  8. data/infrastructure/load.rb +11 -0
  9. data/infrastructure/test_central_command.rb +15 -0
  10. data/infrastructure/test_exception.rb +7 -0
  11. data/{test → infrastructure}/test_factory.rb +0 -0
  12. data/infrastructure/test_logger.rb +11 -0
  13. data/infrastructure/test_operator.rb +15 -0
  14. data/infrastructure/test_result.rb +15 -0
  15. data/infrastructure/thread_agent.rb +21 -0
  16. data/infrastructure/timewarp/Rakefile +14 -0
  17. data/infrastructure/timewarp/lib/timewarp.rb +21 -0
  18. data/infrastructure/timewarp/test/timewarp_test.rb +45 -0
  19. data/lib/deep_test.rb +28 -40
  20. data/lib/deep_test/agent.rb +108 -0
  21. data/lib/deep_test/central_command.rb +165 -0
  22. data/lib/deep_test/cpu_info.rb +22 -0
  23. data/lib/deep_test/database/mysql_setup_listener.rb +11 -12
  24. data/lib/deep_test/database/setup_listener.rb +23 -23
  25. data/lib/deep_test/demon.rb +25 -0
  26. data/lib/deep_test/distributed/beachhead.rb +104 -0
  27. data/lib/deep_test/distributed/dispatch_controller.rb +17 -10
  28. data/lib/deep_test/distributed/establish_beachhead.rb +19 -0
  29. data/lib/deep_test/distributed/landing_fleet.rb +30 -0
  30. data/lib/deep_test/distributed/landing_ship.rb +60 -0
  31. data/lib/deep_test/distributed/remote_deployment.rb +56 -0
  32. data/lib/deep_test/distributed/rsync.rb +25 -12
  33. data/lib/deep_test/distributed/shell_environment.rb +50 -0
  34. data/lib/deep_test/distributed/ssh_client_connection_info.rb +14 -0
  35. data/lib/deep_test/failure_message.rb +19 -0
  36. data/lib/deep_test/lib_root.rb +4 -0
  37. data/lib/deep_test/listener_list.rb +1 -1
  38. data/lib/deep_test/local_deployment.rb +46 -0
  39. data/lib/deep_test/logger.rb +17 -2
  40. data/lib/deep_test/main.rb +41 -0
  41. data/lib/deep_test/marshallable_exception_wrapper.rb +4 -4
  42. data/lib/deep_test/metrics/data.rb +34 -0
  43. data/lib/deep_test/metrics/measurement.rb +39 -0
  44. data/lib/deep_test/{null_worker_listener.rb → null_listener.rb} +14 -14
  45. data/lib/deep_test/options.rb +41 -56
  46. data/lib/deep_test/proxy_io.rb +77 -0
  47. data/lib/deep_test/rake_tasks.rb +3 -1
  48. data/lib/deep_test/result_reader.rb +10 -6
  49. data/lib/deep_test/rspec_detector.rb +1 -1
  50. data/lib/deep_test/spec.rb +5 -1
  51. data/lib/deep_test/spec/extensions/example_methods.rb +7 -1
  52. data/lib/deep_test/spec/extensions/spec_task.rb +3 -2
  53. data/lib/deep_test/spec/runner.rb +32 -17
  54. data/lib/deep_test/spec/work_result.rb +2 -0
  55. data/lib/deep_test/test/run_test_suite.rb +5 -0
  56. data/lib/deep_test/test/runner.rb +2 -2
  57. data/lib/deep_test/test/supervised_test_suite.rb +9 -10
  58. data/lib/deep_test/test/work_result.rb +1 -0
  59. data/lib/deep_test/test_task.rb +1 -1
  60. data/lib/deep_test/ui/console.rb +9 -11
  61. data/lib/deep_test/warlock.rb +37 -25
  62. data/lib/telegraph.rb +29 -0
  63. data/lib/telegraph/ack_sequence.rb +14 -0
  64. data/lib/telegraph/logging.rb +20 -0
  65. data/lib/telegraph/message.rb +39 -0
  66. data/lib/telegraph/operator.rb +47 -0
  67. data/lib/telegraph/switchboard.rb +57 -0
  68. data/lib/telegraph/wire.rb +73 -0
  69. data/negative_acceptance_tests/dying_spec.rb +13 -0
  70. data/negative_acceptance_tests/dying_test.rb +13 -0
  71. data/negative_acceptance_tests/failing_spec.rb +9 -0
  72. data/{test/failing.rb → negative_acceptance_tests/failing_test.rb} +3 -1
  73. data/negative_acceptance_tests/kill_agent_one_on_start_work.rb +16 -0
  74. data/negative_acceptance_tests/passing_spec.rb +10 -0
  75. data/negative_acceptance_tests/passing_test.rb +12 -0
  76. data/negative_acceptance_tests/tasks.rake +87 -0
  77. data/negative_acceptance_tests/tests.rb +60 -0
  78. data/sample_rails_project/deep_test.rb +4 -0
  79. data/sample_rails_project/lib/{foreign_host_worker_simulation_listener.rb → foreign_host_agent_simulation_listener.rb} +6 -4
  80. data/sample_rails_project/lib/tasks/deep_test.rake +13 -4
  81. data/spec/deep_test/options_spec.rb +80 -59
  82. data/spec/deep_test/spec/extensions/example_methods_spec.rb +5 -4
  83. data/spec/deep_test/spec/extensions/spec_task_spec.rb +4 -6
  84. data/spec/deep_test/spec/runner_spec.rb +59 -32
  85. data/spec/spec_helper.rb +14 -6
  86. data/test/deep_test/agent_test.rb +175 -0
  87. data/test/deep_test/central_command_test.rb +147 -0
  88. data/test/deep_test/cpu_info_test.rb +33 -0
  89. data/test/deep_test/database/mysql_setup_listener_test.rb +13 -9
  90. data/test/deep_test/demon_test.rb +23 -0
  91. data/test/deep_test/distributed/beachhead_test.rb +67 -0
  92. data/test/deep_test/distributed/dispatch_controller_test.rb +130 -177
  93. data/test/deep_test/distributed/filename_resolver_test.rb +38 -34
  94. data/test/deep_test/distributed/landing_fleet_test.rb +55 -0
  95. data/test/deep_test/distributed/landing_ship_test.rb +48 -0
  96. data/test/deep_test/distributed/remote_deployment_test.rb +134 -0
  97. data/test/deep_test/distributed/rsync_test.rb +42 -62
  98. data/test/deep_test/distributed/shell_environment_fixtures/set_bar_to_foo +1 -0
  99. data/test/deep_test/distributed/shell_environment_fixtures/set_foo_to_bar +1 -0
  100. data/test/deep_test/distributed/shell_environment_fixtures/set_foo_to_baz +1 -0
  101. data/test/deep_test/distributed/shell_environment_test.rb +108 -0
  102. data/test/deep_test/distributed/ssh_client_connection_info_test.rb +34 -0
  103. data/test/deep_test/listener_list_test.rb +17 -15
  104. data/test/deep_test/local_deployment_test.rb +19 -0
  105. data/test/deep_test/logger_test.rb +34 -7
  106. data/test/deep_test/main_test.rb +12 -0
  107. data/test/deep_test/marshallable_exception_wrapper_test.rb +31 -29
  108. data/test/deep_test/metrics/data_test.rb +22 -0
  109. data/test/deep_test/metrics/measurement_test.rb +18 -0
  110. data/test/deep_test/proxy_io_test.rb +104 -0
  111. data/test/deep_test/result_reader_test.rb +95 -95
  112. data/test/deep_test/test/extensions/error_test.rb +38 -36
  113. data/test/deep_test/test/runner_test.rb +7 -3
  114. data/test/deep_test/test/supervised_test_suite_test.rb +89 -61
  115. data/test/deep_test/test/work_result_test.rb +80 -76
  116. data/test/deep_test/test/work_unit_test.rb +53 -51
  117. data/test/deep_test/test_task_test.rb +10 -38
  118. data/test/deep_test/ui/console_test.rb +8 -4
  119. data/test/deep_test/warlock_test.rb +33 -31
  120. data/test/test_helper.rb +20 -5
  121. data/test/test_task_test.rb +60 -57
  122. metadata +94 -84
  123. data/bin/deep_test +0 -15
  124. data/jstorimer-deep-test-0.1.0.gem +0 -0
  125. data/jstorimer-deep-test.gemspec +0 -1425
  126. data/lib/deep_test/distributed/drb_client_connection_info.rb +0 -15
  127. data/lib/deep_test/distributed/master_test_server.rb +0 -52
  128. data/lib/deep_test/distributed/multi_test_server_proxy.rb +0 -44
  129. data/lib/deep_test/distributed/null_work_unit.rb +0 -12
  130. data/lib/deep_test/distributed/remote_worker_client.rb +0 -54
  131. data/lib/deep_test/distributed/remote_worker_server.rb +0 -82
  132. data/lib/deep_test/distributed/show_status.rhtml +0 -41
  133. data/lib/deep_test/distributed/test_server.rb +0 -78
  134. data/lib/deep_test/distributed/test_server_status.rb +0 -9
  135. data/lib/deep_test/distributed/test_server_workers.rb +0 -24
  136. data/lib/deep_test/distributed/throughput_runner.rb +0 -42
  137. data/lib/deep_test/distributed/throughput_statistics.rb +0 -26
  138. data/lib/deep_test/distributed/throughput_worker_client.rb +0 -19
  139. data/lib/deep_test/extensions/drb_extension.rb +0 -34
  140. data/lib/deep_test/local_workers.rb +0 -55
  141. data/lib/deep_test/metrics/gatherer.rb +0 -67
  142. data/lib/deep_test/metrics/queue_lock_wait_time_measurement.rb +0 -133
  143. data/lib/deep_test/option.rb +0 -60
  144. data/lib/deep_test/process_orchestrator.rb +0 -49
  145. data/lib/deep_test/server.rb +0 -75
  146. data/lib/deep_test/spec/extensions/reporter.rb +0 -29
  147. data/lib/deep_test/worker.rb +0 -57
  148. data/script/internal/run_test_suite.rb +0 -7
  149. data/script/public/master_test_server.rb +0 -24
  150. data/script/public/test_server.rb +0 -18
  151. data/script/public/test_throughput.rb +0 -29
  152. data/spec/deep_test/option_spec.rb +0 -33
  153. data/spec/thread_worker.rb +0 -25
  154. data/test/deep_test/distributed/drb_client_connection_info_test.rb +0 -42
  155. data/test/deep_test/distributed/master_test_server_test.rb +0 -32
  156. data/test/deep_test/distributed/multi_test_server_proxy_test.rb +0 -96
  157. data/test/deep_test/distributed/remote_worker_client_test.rb +0 -180
  158. data/test/deep_test/distributed/remote_worker_server_test.rb +0 -99
  159. data/test/deep_test/distributed/test_server_test.rb +0 -94
  160. data/test/deep_test/distributed/test_server_workers_test.rb +0 -26
  161. data/test/deep_test/distributed/throughput_runner_test.rb +0 -68
  162. data/test/deep_test/distributed/throughput_worker_client_test.rb +0 -28
  163. data/test/deep_test/local_workers_test.rb +0 -22
  164. data/test/deep_test/metrics/gatherer_test.rb +0 -66
  165. data/test/deep_test/process_orchestrator_test.rb +0 -11
  166. data/test/deep_test/server_test.rb +0 -58
  167. data/test/deep_test/worker_test.rb +0 -94
  168. data/test/failing.rake +0 -11
  169. data/test/simple_test_blackboard.rb +0 -45
  170. data/test/simple_test_blackboard_test.rb +0 -33
@@ -0,0 +1,48 @@
1
+ require File.dirname(__FILE__) + "/../../test_helper"
2
+
3
+ module DeepTest
4
+ module Distributed
5
+ unit_tests do
6
+ test "generates a local working copy path based on host and source of request" do
7
+ Socket.stubs(:gethostname).returns("myhost")
8
+ Telegraph::Wire.stubs(:connect).returns :wire
9
+ landing_ship = LandingShip.new(:address => "host")
10
+ options = Options.new(:sync_options => {:source => "/my/local/dir"})
11
+ RSync.expects(:push).with("host", options.sync_options, "/tmp/myhost_my_local_dir")
12
+ landing_ship.push_code(options)
13
+ end
14
+
15
+ test "establish_beachhead launches beachhead process on remote machine" do
16
+ Socket.stubs(:gethostname).returns("myhost")
17
+ Telegraph::Wire.stubs(:connect).returns :wire
18
+ landing_ship = LandingShip.new(:address => "remote_host")
19
+ options = Options.new(:sync_options => {:source => "/my/local/dir"})
20
+
21
+ landing_ship.expects(:`).with(
22
+ "ssh -4 remote_host " +
23
+ "'#{ShellEnvironment.like_login} && cd /tmp/myhost_my_local_dir && " +
24
+ "OPTIONS=#{options.to_command_line} " +
25
+ "ruby lib/deep_test/distributed/establish_beachhead.rb' 2>&1"
26
+ ).returns("blah blah\nBeachhead port: 9999\nblah")
27
+
28
+ landing_ship.establish_beachhead(options)
29
+ end
30
+
31
+ test "establish_beachhead launches beachhead process on remote machine with usernames specified in sync_options" do
32
+ Socket.stubs(:gethostname).returns("myhost")
33
+ Telegraph::Wire.stubs(:connect).returns :wire
34
+ landing_ship = LandingShip.new(:address => "remote_host")
35
+ options = Options.new(:sync_options => {:username => "me", :source => "/my/local/dir"})
36
+
37
+ landing_ship.expects(:`).with(
38
+ "ssh -4 remote_host -l me " +
39
+ "'#{ShellEnvironment.like_login} && cd /tmp/myhost_my_local_dir && " +
40
+ "OPTIONS=#{options.to_command_line} " +
41
+ "ruby lib/deep_test/distributed/establish_beachhead.rb' 2>&1"
42
+ ).returns("blah blah\nBeachhead port: 9999\nblah")
43
+
44
+ landing_ship.establish_beachhead(options)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,134 @@
1
+ require File.dirname(__FILE__) + "/../../test_helper"
2
+
3
+ module DeepTest
4
+ module Distributed
5
+ unit_tests do
6
+ test "load_files broadcasts before_sync" do
7
+ class FakeListener; end
8
+ deployment = RemoteDeployment.new(
9
+ options = Options.new(:listener => FakeListener,
10
+ :sync_options => {:source => "/tmp"}),
11
+ landing_ship = stub_everything,
12
+ failover_deployment = mock
13
+ )
14
+ FakeListener.any_instance.expects(:before_sync)
15
+ deployment.expects(:load)
16
+ deployment.load_files ["filelist"]
17
+
18
+ end
19
+
20
+ test "load_files pushes code to remote machines" do
21
+ deployment = RemoteDeployment.new(
22
+ options = Options.new(:sync_options => {:source => "/tmp"}),
23
+ landing_ship = stub_everything,
24
+ failover_deployment = mock
25
+ )
26
+
27
+ landing_ship.expects(:push_code).with(options)
28
+ deployment.expects(:load)
29
+ deployment.load_files ["filelist"]
30
+ end
31
+
32
+ test "load_files loads files locally" do
33
+ beachhead = stub_everything
34
+ deployment = RemoteDeployment.new(
35
+ Options.new(:sync_options => {:source => "/tmp"}),
36
+ landing_ship = stub_everything,
37
+ failover_deployment = mock
38
+ )
39
+
40
+ deployment.expects(:load).with("filelist")
41
+ deployment.load_files ["filelist"]
42
+ end
43
+
44
+ test "deploy_agents starts agents on agent server" do
45
+ deployment = RemoteDeployment.new(
46
+ options = Options.new(:sync_options => {:source => "/tmp"}),
47
+ landing_ship = stub_everything,
48
+ failover_deployment = mock
49
+ )
50
+
51
+ landing_ship.expects(:establish_beachhead).with(options)
52
+ deployment.expects(:load)
53
+ deployment.load_files ["filelist"]
54
+
55
+ landing_ship.expects(:deploy_agents)
56
+ deployment.deploy_agents
57
+ end
58
+
59
+ test "exception in deploy_agents causes failover to failover_deployment" do
60
+ deployment = RemoteDeployment.new(
61
+ options = Options.new(:sync_options => {:source => "/tmp"}, :ui => UI::Null),
62
+ landing_ship = stub_everything,
63
+ failover_deployment = mock
64
+ )
65
+
66
+ landing_ship.expects(:establish_beachhead).with(options)
67
+ landing_ship.expects(:load_files)
68
+ deployment.expects(:load)
69
+ deployment.load_files ["filelist"]
70
+
71
+ landing_ship.expects(:deploy_agents).raises("An Error")
72
+
73
+ failover_deployment.expects(:deploy_agents)
74
+ deployment.deploy_agents
75
+ end
76
+
77
+ test "exception in push_code causes failover to failover_deployment" do
78
+ deployment = RemoteDeployment.new(
79
+ options = Options.new(:sync_options => {:source => "/tmp"}, :ui => UI::Null),
80
+ landing_ship = mock,
81
+ failover_deployment = mock
82
+ )
83
+
84
+ landing_ship.expects(:push_code).raises("An Error")
85
+
86
+ deployment.expects(:load)
87
+ deployment.load_files ["filelist"]
88
+
89
+ failover_deployment.expects(:deploy_agents)
90
+ deployment.deploy_agents
91
+ end
92
+
93
+ test "exception in load_files causes failover to failover_deployment" do
94
+ deployment = RemoteDeployment.new(
95
+ options = Options.new(:sync_options => {:source => "/tmp"}, :ui => UI::Null),
96
+ landing_ship = mock,
97
+ failover_deployment = mock
98
+ )
99
+
100
+ landing_ship.expects(:push_code)
101
+ landing_ship.expects(:establish_beachhead)
102
+ landing_ship.expects(:load_files).raises("An Error")
103
+
104
+ deployment.expects(:load)
105
+ deployment.load_files ["filelist"]
106
+
107
+ failover_deployment.expects(:deploy_agents)
108
+ deployment.deploy_agents
109
+ end
110
+
111
+ test "exception from deploy_agents of failover_deployment is raised" do
112
+ deployment = RemoteDeployment.new(
113
+ options = Options.new(:sync_options => {:source => "/tmp"}, :ui => UI::Null),
114
+ landing_ship = stub_everything,
115
+ failover_deployment = mock
116
+ )
117
+
118
+ landing_ship.expects(:establish_beachhead).with(options)
119
+ landing_ship.expects(:load_files).raises("An Error")
120
+ deployment.expects(:load)
121
+ deployment.load_files ["filelist"]
122
+
123
+ failover_deployment.expects(:deploy_agents).raises("Failover Error").then.returns(nil)
124
+
125
+ begin
126
+ deployment.deploy_agents
127
+ flunk
128
+ rescue RuntimeError => e
129
+ assert_equal "Failover Error", e.message
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
@@ -1,67 +1,47 @@
1
1
  require File.dirname(__FILE__) + "/../../test_helper"
2
2
 
3
- unit_tests do
4
- test "executes rsync with source and destination" do
5
- options = DeepTest::Options.new(:sync_options => {:source => "source", :local => true})
6
-
7
- DeepTest::Distributed::RSync.expects(:system).
8
- with("rsync -az --delete source/ destination").returns(true)
9
-
10
- DeepTest::Distributed::RSync.sync(mock, options, "destination")
11
- end
12
-
13
- test "raises error if sync fails" do
14
- DeepTest::Distributed::RSync.expects(:system).returns(false)
15
-
16
- assert_raises(RuntimeError) do
17
- DeepTest::Distributed::RSync.sync(
18
- mock,
19
- DeepTest::Options.new(:sync_options => {:source => "a", :local => true}),
20
- "destination"
21
- )
3
+ module DeepTest
4
+ module Distributed
5
+ unit_tests do
6
+ test "push executes rsync with using destination as remote location" do
7
+ RSync.expects(:system).
8
+ with("rsync -az --delete #{DeepTest::LIB_ROOT} source host:destination").returns(true)
9
+
10
+ RSync.push('host', {:source => "source"}, "destination")
11
+ end
12
+
13
+ test "raises error if push fails" do
14
+ RSync.expects(:system).returns(false)
15
+
16
+ assert_raises(RuntimeError) do
17
+ RSync.push(mock, {:source => "a", :local => true}, "destination")
18
+ end
19
+ end
20
+
21
+ test "include rsync_options in command" do
22
+ args = RSync::Args.new(mock, {:local => true, :rsync_options => "opt1 opt2"})
23
+ assert_equal "rsync -az --delete opt1 opt2 #{DeepTest::LIB_ROOT}", args.command("", "")
24
+ end
25
+
26
+ test "includes host in remote_location" do
27
+ args = RSync::Args.new('host', {})
28
+ assert_equal "host:dest", args.remote_location('dest')
29
+ end
30
+
31
+ test "separates host and dest with double colon if using daemon" do
32
+ args = RSync::Args.new('host', {:daemon => true})
33
+ assert_equal "host::dest", args.remote_location('dest')
34
+ end
35
+
36
+ test "includes username in dest_location if specified" do
37
+ args = RSync::Args.new('host', {:username => "user"})
38
+ assert_equal "user@host:dest", args.remote_location('dest')
39
+ end
40
+
41
+ test "does not include host in dest_location if local is specified" do
42
+ args = RSync::Args.new(mock, {:local => true})
43
+ assert_equal "dest", args.remote_location('dest')
44
+ end
22
45
  end
23
46
  end
24
-
25
- test "include rsync_options in command" do
26
- options = DeepTest::Options.new(:sync_options => {:source => "source",
27
- :local => true,
28
- :rsync_options => "opt1 opt2"})
29
-
30
- args = DeepTest::Distributed::RSync::Args.new(mock, options)
31
- assert_equal "rsync -az --delete opt1 opt2 source/", args.command("")
32
- end
33
-
34
- test "includes host in source_location" do
35
- options = DeepTest::Options.new(:sync_options => {:source => "source"})
36
- args = DeepTest::Distributed::RSync::Args.new(mock(:address => 'host'),
37
- options)
38
-
39
- assert_equal "host:source", args.source_location
40
- end
41
-
42
- test "separates host and source with double colon if using daemon" do
43
- options = DeepTest::Options.new(
44
- :sync_options => {:source => "source", :daemon => true}
45
- )
46
- args = DeepTest::Distributed::RSync::Args.new(mock(:address => 'host'),
47
- options)
48
-
49
- assert_equal "host::source", args.source_location
50
- end
51
-
52
- test "includes username in source_location if specified" do
53
- options = DeepTest::Options.new(:sync_options => {:source => "source",
54
- :username => "user"})
55
- args = DeepTest::Distributed::RSync::Args.new(mock(:address => 'host'),
56
- options)
57
-
58
- assert_equal "user@host:source", args.source_location
59
- end
60
-
61
- test "does not include host in source_location if local is specified" do
62
- options = DeepTest::Options.new(:sync_options => {:source => "source", :local => true})
63
- args = DeepTest::Distributed::RSync::Args.new(mock, options)
64
-
65
- assert_equal "source", args.source_location
66
- end
67
47
  end
@@ -0,0 +1,108 @@
1
+ require File.dirname(__FILE__) + "/../../test_helper"
2
+
3
+ module DeepTest
4
+ module Distributed
5
+ unit_tests do
6
+ test "like_login creates enviroment that will behave like login shell" do
7
+ expected_env = ShellEnvironment.new
8
+ expected_env.include_first '/etc/profile'
9
+ expected_env.include_first '~/.profile', '~/.bash_profile', '~/.bashrc'
10
+
11
+ assert_equal expected_env, ShellEnvironment.like_login
12
+ end
13
+
14
+ test "include_first command loads the specified file when it exists" do
15
+ environment = ShellEnvironment.new
16
+ environment.include_first fixture_path('set_foo_to_bar')
17
+
18
+ assert_enviroment({:FOO => "bar"}, environment)
19
+ end
20
+
21
+ test "include_first does not load the file if it doesnt exist" do
22
+ environment = ShellEnvironment.new
23
+ environment.include_first fixture_path('nonexistent')
24
+ assert_enviroment({:SHELL => ENV['SHELL']}, environment)
25
+ end
26
+
27
+ test "include_first loads second file if first does not exist" do
28
+ environment = ShellEnvironment.new
29
+
30
+ environment.include_first fixture_path('nonexistent'),
31
+ fixture_path('set_foo_to_bar')
32
+
33
+ assert_enviroment({:FOO => "bar"}, environment)
34
+ end
35
+
36
+ test "include_first does not load second file if first exists" do
37
+ environment = ShellEnvironment.new
38
+
39
+ environment.include_first fixture_path('set_foo_to_bar'),
40
+ fixture_path('set_foo_to_baz')
41
+
42
+ assert_enviroment({:FOO => "bar"}, environment)
43
+ end
44
+
45
+ test "include_first loads each file when called two separate times" do
46
+ environment = DeepTest::Distributed::ShellEnvironment.new
47
+ environment.include_first fixture_path('set_foo_to_bar')
48
+ environment.include_first fixture_path('set_bar_to_foo')
49
+
50
+ assert_enviroment({:FOO => "bar", :BAR => "foo"}, environment)
51
+ end
52
+
53
+ test "include_first loads files in order in which it was called" do
54
+ environment = ShellEnvironment.new
55
+ environment.include_first fixture_path('set_foo_to_bar')
56
+ environment.include_first fixture_path('set_foo_to_baz')
57
+
58
+ assert_enviroment({:FOO => "baz"}, environment)
59
+ end
60
+
61
+ test "source file lists are equal when they will load the same files" do
62
+ assert_equal ShellEnvironment::SourceFileList.new(['a','b']),
63
+ ShellEnvironment::SourceFileList.new(['a','b'])
64
+
65
+ assert_not_equal ShellEnvironment::SourceFileList.new(['a','b']),
66
+ ShellEnvironment::SourceFileList.new(['b','a'])
67
+ end
68
+
69
+ test "environments are equal when files will load in the same order" do
70
+ env1, env2 = ShellEnvironment.new, ShellEnvironment.new
71
+
72
+ env1.include_first 'A'; env2.include_first 'A'
73
+ env1.include_first 'B'; env2.include_first 'B'
74
+
75
+ assert_equal env1, env2
76
+ end
77
+
78
+ test "environments are not equal when files will load in the different order" do
79
+ env1, env2 = ShellEnvironment.new, ShellEnvironment.new
80
+
81
+ env1.include_first 'A'; env2.include_first 'B'
82
+ env1.include_first 'B'; env2.include_first 'A'
83
+
84
+ assert_not_equal env1, env2
85
+ end
86
+
87
+ def assert_enviroment(expected_hash, environment)
88
+ output = `#{environment} && env`
89
+ assert $?.success?, "'#{environment} && env' command failed"
90
+
91
+ actual_hash = output.inject({}) do |h, line|
92
+ if line =~ /^(.*?)=(.*)/ && expected_hash.key?($1.to_sym)
93
+ h[$1.to_sym] = $2
94
+ end
95
+ h
96
+ end
97
+
98
+ assert_equal expected_hash, actual_hash
99
+ end
100
+
101
+ def fixture_path(filename)
102
+ File.expand_path(File.join(File.dirname(__FILE__),
103
+ 'shell_environment_fixtures',
104
+ filename))
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + "/../../test_helper"
2
+
3
+ module DeepTest
4
+ module Distributed
5
+ unit_tests do
6
+ test "returns ipaddress from SSH_CLIENT as address" do
7
+ info = nil
8
+ with_env("SSH_CLIENT", "168.0.0.1 33345 22") do
9
+ info = SshClientConnectionInfo.new
10
+ end
11
+ assert_equal "168.0.0.1", info.address
12
+ end
13
+
14
+ test "raises an error if SSH_CLIENT is blank" do
15
+ with_env("SSH_CLIENT", "") do
16
+ assert_raises(RuntimeError) { SshClientConnectionInfo.new }
17
+ end
18
+ end
19
+
20
+ test "raises an error if no SSH_CLIENT is found" do
21
+ with_env("SSH_CLIENT", nil) do
22
+ assert_raises(RuntimeError) { SshClientConnectionInfo.new }
23
+ end
24
+ end
25
+
26
+ def with_env(variable, value)
27
+ old_value, ENV[variable] = ENV[variable], value
28
+ yield
29
+ ensure
30
+ ENV[variable] = old_value
31
+ end
32
+ end
33
+ end
34
+ end