sanford 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,56 +0,0 @@
1
- require 'assert'
2
-
3
- class Sanford::Hosts
4
-
5
- class BaseTests < Assert::Context
6
- desc "Sanford::hosts"
7
- setup do
8
- @hosts = Sanford::Hosts.new
9
- end
10
- subject{ @hosts }
11
-
12
- should have_instance_methods :add, :first, :find
13
-
14
- end
15
-
16
- class FindTests < BaseTests
17
- desc "find"
18
- setup do
19
- @hosts.add ::NotNamedHost
20
- @hosts.add ::NamedHost
21
- @hosts.add ::BadlyNamedHost
22
- end
23
-
24
- should "allow finding hosts by their class name or configured name" do
25
- assert_includes NotNamedHost, subject
26
- assert_includes NamedHost, subject
27
- assert_equal NotNamedHost, subject.find('NotNamedHost')
28
- assert_equal NamedHost, subject.find('NamedHost')
29
- assert_equal NamedHost, subject.find('named_host')
30
- end
31
-
32
- should "check class name before configured name" do
33
- assert_includes BadlyNamedHost, subject
34
- assert_equal NotNamedHost, subject.find('NotNamedHost')
35
- end
36
-
37
- # Using this syntax because these classes need to be defined as top-level
38
- # constants for ease in using their class names in the tests
39
-
40
- ::NotNamedHost = Class.new do
41
- include Sanford::Host
42
- end
43
-
44
- ::NamedHost = Class.new do
45
- include Sanford::Host
46
- name 'named_host'
47
- end
48
-
49
- ::BadlyNamedHost = Class.new do
50
- include Sanford::Host
51
- name 'NotNamedHost'
52
- end
53
-
54
- end
55
-
56
- end
@@ -1,60 +0,0 @@
1
- require 'assert'
2
- require 'sanford/cli'
3
-
4
- class Sanford::Manager::PIDFile
5
-
6
- class BaseTests < Assert::Context
7
- desc "Sanford::Manager::PIDFile"
8
- setup do
9
- @pid_file_path = File.join(ROOT, "tmp/my.pid")
10
- @pid_file = Sanford::Manager::PIDFile.new(@pid_file_path)
11
- end
12
- teardown do
13
- FileUtils.rm_rf(@pid_file_path)
14
- end
15
- subject{ @pid_file }
16
-
17
- should have_instance_methods :pid, :to_s, :write, :remove
18
-
19
- should "return it's path with #to_s" do
20
- assert_equal @pid_file_path, subject.to_s
21
- end
22
-
23
- should "write the pid file with #write" do
24
- subject.write
25
-
26
- assert_file_exists @pid_file_path
27
- assert_equal "#{Process.pid}\n", File.read(@pid_file_path)
28
- end
29
-
30
- should "return the value stored in the pid value with #pid" do
31
- subject.write
32
-
33
- assert_equal Process.pid, subject.pid
34
- end
35
-
36
- should "remove the file with #remove" do
37
- subject.write
38
- subject.remove
39
-
40
- assert_not File.exists?(@pid_file_path)
41
- end
42
-
43
- should "complain nicely if it can't write the pid file" do
44
- pid_file_path = 'does/not/exist.pid'
45
- pid_file = Sanford::Manager::PIDFile.new(pid_file_path)
46
-
47
- err = nil
48
- begin
49
- pid_file.write
50
- rescue Exception => err
51
- end
52
-
53
- assert err
54
- assert_kind_of RuntimeError, err
55
- assert_includes File.dirname(pid_file_path), err.message
56
- end
57
-
58
- end
59
-
60
- end