sundae 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,229 @@
1
+ require 'test/unit' unless defined? $ZENTEST and $ZENTEST
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), "..", "bin") # add ../bin to the Ruby library path
4
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib") # ../lib
5
+ require 'sundae'
6
+
7
+ class TestSundae < Test::Unit::TestCase
8
+
9
+ @@testdir = File.dirname(File.expand_path(__FILE__))
10
+ @@sandbox = File.join(@@testdir, 'sandbox')
11
+ @@static_dir = File.join(@@sandbox, 'static')
12
+ @@mnts_dir = File.join(@@sandbox, 'mnts')
13
+
14
+ def setup
15
+ FileUtils.mkdir_p(@@sandbox)
16
+
17
+ FileUtils.mkdir_p(@@static_dir)
18
+ File.open(File.join(@@static_dir, 'static'), 'w')
19
+ FileUtils.mkdir_p(File.join(@@mnts_dir, 'c1'))
20
+ FileUtils.mkdir_p(File.join(@@mnts_dir, 'c2'))
21
+ FileUtils.mkdir_p(File.join(@@mnts_dir, 'c1/d1'))
22
+ FileUtils.mkdir_p(File.join(@@mnts_dir, 'c1/d2'))
23
+ FileUtils.mkdir_p(File.join(@@mnts_dir, 'c2/d1'))
24
+ FileUtils.mkdir_p(File.join(@@mnts_dir, 'c2/d3'))
25
+ File.open(File.join(@@mnts_dir, 'c1/d1/f11'), 'w')
26
+ File.open(File.join(@@mnts_dir, 'c1/d1/f12'), 'w')
27
+ File.open(File.join(@@mnts_dir, 'c1/d2/f21'), 'w')
28
+ File.open(File.join(@@mnts_dir, 'c2/d1/f13'), 'w')
29
+ File.open(File.join(@@mnts_dir, 'c2/d1/f14'), 'w')
30
+ File.open(File.join(@@mnts_dir, 'c2/d3/f31'), 'w')
31
+ ['c1/d1', 'c1/d2', 'c2/d1', 'c2/d3'].each do |d|
32
+ File.open(File.join(@@mnts_dir, d, '.sundae_path'), 'w') do |f|
33
+ f.puts @@sandbox
34
+ end
35
+ end
36
+
37
+ @@path1 = File.join(@@sandbox, 'mnts')
38
+ @@collection_links = true
39
+ @@collection_link_prefix = '_'
40
+ @@ignore_rule1 = '\\.svn'
41
+
42
+ @@config_file = File.join(@@sandbox, ".sundae")
43
+ File.open(@@config_file, 'w+') do |f|
44
+ f.puts ":paths:"
45
+ f.puts " - #{@@path1}"
46
+ f.puts ":collection_links:"
47
+ f.puts " #{@@collection_links}"
48
+ f.puts ":collection_link_prefix:"
49
+ f.puts " #{@@collection_link_prefix}"
50
+ f.puts ":ignore_rules:"
51
+ f.puts " - #{@@ignore_rule1}"
52
+ f.puts " - \\.bzr"
53
+ f.puts " - \\.DS_Store"
54
+ end
55
+ Sundae.load_config_file(@@sandbox)
56
+
57
+ end
58
+
59
+ def teardown
60
+ FileUtils.rm_r(@@sandbox)
61
+ end
62
+
63
+ def test_class_all_mnts
64
+ all_mnts = Sundae.all_mnts
65
+ mnts = Sundae.mnts_in_path(@@path1)
66
+ mnts.each do |m|
67
+ assert all_mnts.include?(File.join(@@path1,m))
68
+ end
69
+ end
70
+
71
+ def test_class_combine_directories
72
+ d1 = File.join(@@mnts_dir, 'c1/d1')
73
+ d2 = File.join(@@mnts_dir, 'c1/d2')
74
+ link = File.join(@@sandbox, 'link')
75
+ FileUtils.ln_s(d1, link)
76
+ Sundae.combine_directories(link, d1, d2)
77
+ assert File.symlink?(File.join(link, 'f11'))
78
+ assert File.symlink?(File.join(link, '_c1'))
79
+ end
80
+
81
+ def test_class_create_directory_link
82
+ assert_nothing_raised do
83
+ Sundae.create_directory_link(File.join(@@mnts_dir, 'c1/d1'), File.join(@@sandbox, 'new_link'))
84
+ assert File.symlink?(File.join(@@sandbox, 'new_link'))
85
+ end
86
+ assert_raise ArgumentError do
87
+ Sundae.create_directory_link(File.join(@@mnts_dir, 'non_existent_directory'), File.join(@@sandbox, 'new_link4'))
88
+ end
89
+ assert_raise ArgumentError do
90
+ Sundae.create_directory_link(File.join(@@mnts_dir, 'c1/d1/f11'), File.join(@@sandbox, 'new_link4'))
91
+ end
92
+ end
93
+
94
+ def test_class_create_file_link
95
+ assert_nothing_raised do
96
+ Sundae.create_file_link(File.join(@@mnts_dir, 'c1/d1/f11'), File.join(@@sandbox, 'new_link'))
97
+ assert File.symlink?(File.join(@@sandbox, 'new_link'))
98
+ end
99
+ assert_nothing_raised do
100
+ FileUtils.ln_s(File.join(@@mnts_dir, 'c1/d1/f11'), File.join(@@sandbox, 'new_link2'))
101
+ Sundae.create_file_link(File.join(@@mnts_dir, 'c1/d1/f11'), File.join(@@sandbox, 'new_link2'))
102
+ end
103
+ assert_raise RuntimeError do
104
+ File.open(File.join(@@sandbox, 'new_link3'), 'w')
105
+ Sundae.create_file_link(File.join(@@mnts_dir, 'c1/d1/f11'), File.join(@@sandbox, 'new_link3'))
106
+ end
107
+ assert_raise RuntimeError do
108
+ FileUtils.ln_s(File.join(@@mnts_dir, 'c1/d1/f12'), File.join(@@sandbox, 'new_link4'))
109
+ Sundae.create_file_link(File.join(@@mnts_dir, 'c1/d1/f11'), File.join(@@sandbox, 'new_link4'))
110
+ end
111
+ assert_raise ArgumentError do
112
+ Sundae.create_file_link(File.join(@@mnts_dir, 'c1/d1'), File.join(@@sandbox, 'new_link4'))
113
+ end
114
+ end
115
+
116
+ def test_class_create_filesystem
117
+ Sundae.create_filesystem
118
+ assert File.symlink?(File.join(@@sandbox, 'f11'))
119
+ assert File.symlink?(File.join(@@sandbox, 'f31'))
120
+ assert File.symlink?(File.join(@@sandbox, '_c1'))
121
+ end
122
+
123
+ def test_class_find_static_file
124
+ assert_equal File.basename(Sundae.find_static_file(@@mnts_dir)), 'f11'
125
+ 10.times do
126
+ assert_not_nil Sundae.find_static_file(@@mnts_dir)
127
+ FileUtils.rm(Sundae.find_static_file(@@mnts_dir))
128
+ end
129
+ assert_nil Sundae.find_static_file(@@mnts_dir)
130
+ end
131
+
132
+ def test_class_generated_directories
133
+ assert_kind_of Array, Sundae.generated_directories
134
+ assert Sundae.generated_directories.include?(File.join(@@sandbox, 'f11'))
135
+ assert Sundae.generated_directories.size == 6
136
+ end
137
+
138
+ def test_class_ignore_file_eh
139
+ assert Sundae.ignore_file?('.sundae_path')
140
+ assert Sundae.ignore_file?('..')
141
+ assert Sundae.ignore_file?(@@ignore_rule1)
142
+ assert_equal Sundae.ignore_file?('normal_file.txt'), false
143
+ end
144
+
145
+ def test_class_install_location
146
+ assert_equal Sundae.install_location('/'), ENV['HOME']
147
+ assert_equal Sundae.install_location(File.join(@@mnts_dir, 'c1/d1')), @@sandbox
148
+ end
149
+
150
+ def test_class_install_locations
151
+ assert_equal Sundae.install_locations, [@@sandbox]
152
+ end
153
+
154
+ def test_class_load_config_file
155
+ sundae_paths = Sundae.instance_variable_get(:@paths)
156
+ sundae_ignore_rules = Sundae.instance_variable_get(:@ignore_rules)
157
+ sundae_collection_links = Sundae.instance_variable_get(:@collection_links)
158
+ sundae_collection_link_prefix = Sundae.instance_variable_get(:@collection_link_prefix)
159
+
160
+ assert_equal sundae_paths[0], File.expand_path(@@path1)
161
+ assert_equal sundae_ignore_rules[0], Regexp.new(@@ignore_rule1)
162
+ assert_equal sundae_collection_links, @@collection_links
163
+ assert_equal sundae_collection_link_prefix, @@collection_link_prefix
164
+ end
165
+
166
+ def test_class_minimally_create_links
167
+ c1 = File.join(@@mnts_dir, 'c1')
168
+ c2 = File.join(@@mnts_dir, 'c2')
169
+ Sundae.minimally_create_links(c1, @@sandbox)
170
+ assert File.symlink?(File.join(@@sandbox, 'd1'))
171
+ assert File.symlink?(File.join(@@sandbox, 'd2'))
172
+ Sundae.minimally_create_links(c2, @@sandbox)
173
+ assert File.directory?(File.join(@@sandbox, 'd1'))
174
+ assert File.symlink?(File.join(@@sandbox, 'd1/f11'))
175
+ assert File.symlink?(File.join(@@sandbox, 'd1/f14'))
176
+ assert File.symlink?(File.join(@@sandbox, 'd2'))
177
+ assert File.symlink?(File.join(@@sandbox, 'd3'))
178
+ end
179
+
180
+ def test_class_mnts_in_path
181
+ assert_equal Sundae.mnts_in_path(@@path1), ['c1/d1', 'c1/d2', 'c2/d1', 'c2/d3']
182
+ end
183
+
184
+ def test_class_remove_dead_links
185
+ File.open(File.join(@@sandbox, 'temp_file'), 'w')
186
+ File.open(File.join(@@sandbox, 'perm_file'), 'w')
187
+ FileUtils.ln_s(File.join(@@sandbox, 'temp_file'), File.join(@@sandbox, 'link'))
188
+ FileUtils.rm(File.join(@@sandbox, 'temp_file'))
189
+ assert_equal Sundae.remove_dead_links, [File.join(@@sandbox, 'link')]
190
+ assert ! File.exist?(File.join(@@sandbox, 'link'))
191
+ assert File.exist?(File.join(@@sandbox, 'perm_file'))
192
+ end
193
+
194
+ def test_class_remove_generated_directories
195
+ Sundae.generated_directories.each { |d| FileUtils.mkdir_p(d) }
196
+ Sundae.remove_generated_directories
197
+ Sundae.generated_directories.each do |d|
198
+ assert ! File.exist?(d)
199
+ end
200
+ end
201
+
202
+ def test_class_root_path
203
+ assert_equal Sundae.root_path(File.join(@@mnts_dir, 'c1')), File.join(@@mnts_dir, 'c1')
204
+ assert_equal Sundae.root_path(File.join(@@mnts_dir, 'c1/d1')), File.join(@@mnts_dir, 'c1')
205
+
206
+ assert_raise ArgumentError do
207
+ Sundae.root_path('/')
208
+ end
209
+ end
210
+
211
+ def test_class_create_collection_links
212
+ c1 = File.join(@@mnts_dir, 'c1')
213
+ Sundae.create_collection_links(c1, @@sandbox)
214
+ assert File.symlink?(File.join(@@sandbox, '_c1'))
215
+ end
216
+
217
+ def test_class_create_link
218
+ Sundae.create_link(File.join(@@mnts_dir, 'c1/d1/f11'), File.join(@@sandbox, 'new_link1'))
219
+ assert File.symlink?(File.join(@@sandbox, 'new_link1'))
220
+ Sundae.create_link(File.join(@@mnts_dir, 'c1/d1'), File.join(@@sandbox, 'new_link2'))
221
+ assert File.symlink?(File.join(@@sandbox, 'new_link2'))
222
+ end
223
+
224
+ def test_class_create_template_config_file
225
+ assert "I'm happy not testing this right now"
226
+ end
227
+
228
+ end
229
+
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sundae
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Don
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-10-19 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: configatron
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: hoe
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.8.0
34
+ version:
35
+ description: Mix collections of files while maintaining complete separation. Synchronize any combination of your documents and configuration settings between all of your computers.
36
+ email: don@ohspite.net
37
+ executables:
38
+ - sundae
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - Copying.txt
43
+ - History.txt
44
+ - Manifest.txt
45
+ - README.txt
46
+ files:
47
+ - Copying.txt
48
+ - History.txt
49
+ - Manifest.txt
50
+ - README.txt
51
+ - Rakefile
52
+ - bin/sundae
53
+ - setup.rb
54
+ - lib/sundae.rb
55
+ - test/test_sundae.rb
56
+ has_rdoc: true
57
+ homepage: http://rubyforge.org/projects.sundae
58
+ post_install_message:
59
+ rdoc_options:
60
+ - --main
61
+ - README.txt
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ version:
76
+ requirements: []
77
+
78
+ rubyforge_project: sundae
79
+ rubygems_version: 1.3.0
80
+ signing_key:
81
+ specification_version: 2
82
+ summary: Mix collections of files while maintaining complete separation.
83
+ test_files:
84
+ - test/test_sundae.rb