dorkbox 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/executables/dorkbox +1 -0
  2. data/lib/dorkbox_test.rb +220 -0
  3. metadata +2 -1
@@ -29,4 +29,5 @@ VALID_COMMANDS = ['create', 'connect', 'sync', 'sync_tracked', 'cleanup_tracked'
29
29
  VALID_COMMANDS.include?(command) or exit(1)
30
30
  ## TODO: something like dorkbox clone with remote
31
31
 
32
+ include Dorkbox
32
33
  Dorkbox::send(command.to_sym, *ARGV)
@@ -0,0 +1,220 @@
1
+ require 'minitest/unit'
2
+ require 'minitest/spec'
3
+ require 'minitest/mock'
4
+ require 'minitest/autorun'
5
+ require 'fileutils'
6
+ require 'tempfile'
7
+ require_relative 'dorkbox'
8
+
9
+
10
+ class TestCreation < MiniTest::Unit::TestCase
11
+ include Dorkbox
12
+
13
+ def test_create
14
+ Dir.mktmpdir() { |remote_repo_dir|
15
+ `git init --bare #{remote_repo_dir}`
16
+
17
+ Dir.mktmpdir() { |local_dorkbox_repo_dir|
18
+ Dir.chdir(local_dorkbox_repo_dir) {
19
+ create(remote_repo_dir)
20
+ assert(File.exists?(GITIGNORE))
21
+ }
22
+ }
23
+
24
+ }
25
+ cleanup_tracked()
26
+ end
27
+
28
+ def test_connect
29
+ Dir.mktmpdir() { |remote_repo_dir|
30
+ `git init --bare #{remote_repo_dir}`
31
+
32
+ first_client_name = nil
33
+ Dir.mktmpdir() { |first_repo_dir|
34
+ Dir.chdir(first_repo_dir) {
35
+ first_client_name = create(remote_repo_dir)
36
+ }
37
+
38
+ Dir.mktmpdir() { |second_repo_dir|
39
+ Dir.chdir(second_repo_dir) {
40
+ second_client_name = connect(remote_repo_dir)
41
+ all_branches = c("git branch -a")
42
+ assert(all_branches.include?(first_client_name))
43
+ assert(all_branches.include?(second_client_name))
44
+ }
45
+ }
46
+ }
47
+ }
48
+ cleanup_tracked()
49
+ end
50
+ end
51
+
52
+ class TestSync < MiniTest::Unit::TestCase
53
+ include Dorkbox
54
+
55
+ def setup
56
+ @remote_repo_dir = Dir.mktmpdir()
57
+ `git init --bare #{@remote_repo_dir}`
58
+
59
+ @first_client_dir = Dir.mktmpdir()
60
+ @second_client_dir = Dir.mktmpdir()
61
+
62
+ Dir.chdir(@first_client_dir) {
63
+ create(@remote_repo_dir)
64
+ }
65
+
66
+ Dir.chdir(@second_client_dir) {
67
+ connect(@remote_repo_dir)
68
+ }
69
+ end
70
+
71
+ def teardown
72
+ FileUtils.remove_entry_secure(@remote_repo_dir)
73
+ FileUtils.remove_entry_secure(@first_client_dir)
74
+ FileUtils.remove_entry_secure(@second_client_dir)
75
+ cleanup_tracked()
76
+ end
77
+
78
+ def test_syncing_between_two_clients
79
+ Dir.chdir(@first_client_dir) {
80
+ File.open("something", "w") { |f| f.write("asd") }
81
+ sync()
82
+ }
83
+
84
+ Dir.chdir(@second_client_dir) {
85
+ sync()
86
+ File.open("something") { |f| assert_equal("asd", f.read()) }
87
+ }
88
+
89
+ Dir.chdir(@second_client_dir) {
90
+ File.open("something", "a") { |f| f.write("xyz") }
91
+ sync()
92
+ }
93
+
94
+ Dir.chdir(@first_client_dir) {
95
+ sync()
96
+ File.open("something", "r") { |f| assert_equal("asdxyz", f.read()) }
97
+ }
98
+ end
99
+
100
+ def test_tracking_between_two_clients
101
+ Dir.chdir(@first_client_dir) {
102
+ File.open("something", "w") { |f| f.write("asd") }
103
+ sync_tracked()
104
+ }
105
+
106
+ Dir.chdir(@second_client_dir) {
107
+ sync_tracked()
108
+ File.open("something") { |f| assert_equal("asd", f.read()) }
109
+ }
110
+
111
+ Dir.chdir(@second_client_dir) {
112
+ File.open("something", "a") { |f| f.write("xyz") }
113
+ sync_tracked()
114
+ }
115
+
116
+ Dir.chdir(@first_client_dir) {
117
+ sync_tracked()
118
+ File.open("something", "r") { |f| assert_equal("asdxyz", f.read()) }
119
+ }
120
+ end
121
+
122
+ def test_conflicted_client_doesnt_sync_until_fixed
123
+ Dir.chdir(@first_client_dir) {
124
+ File.open("something", "w") { |f| f.write("asd") }
125
+ sync()
126
+ }
127
+
128
+ Dir.chdir(@second_client_dir) {
129
+ File.open("something", "w") { |f| f.write("whatsup") }
130
+ begin
131
+ sync()
132
+ rescue StandardError => e
133
+ end
134
+
135
+ assert(File.exists? CONFLICT_STRING)
136
+
137
+ }
138
+
139
+ Dir.chdir(@second_client_dir) {
140
+ begin
141
+ sync()
142
+ flunk('should have raised exception')
143
+ rescue StandardError => e
144
+ end
145
+ }
146
+
147
+ Dir.chdir(@second_client_dir) {
148
+ `git merge dorkbox/master || true`
149
+ File.open("something", "w") { |f| f.write("merged") }
150
+ `git commit -am 'merged'`
151
+ File.delete(CONFLICT_STRING)
152
+ sync()
153
+ }
154
+
155
+ Dir.chdir(@first_client_dir) {
156
+ sync()
157
+ File.open("something") { |f| assert_equal("merged", f.read()) }
158
+ }
159
+ end
160
+
161
+ def test_multiple_sync_without_changes_doesnt_crash
162
+ Dir.chdir(@second_client_dir) {
163
+ sync()
164
+ sync()
165
+ sync()
166
+ }
167
+
168
+ end
169
+
170
+
171
+ end
172
+
173
+
174
+ class TestCrontabAdding < MiniTest::Unit::TestCase
175
+ include Dorkbox
176
+
177
+ def setup
178
+ begin
179
+ @save_user_crontab = c('crontab -l 2>/dev/null')
180
+ rescue
181
+ @save_user_crontab = nil
182
+ end
183
+ `crontab -r || /bin/true`
184
+ end
185
+
186
+ def teardown
187
+ if @save_user_crontab.nil?
188
+ `crontab -r`
189
+ else
190
+ tmp = Tempfile.new('dorkbox-temp')
191
+ tmp.puts(@save_user_crontab)
192
+ tmp.flush()
193
+ `crontab #{tmp.path}`
194
+ tmp.close()
195
+ end
196
+ end
197
+
198
+ def test_dorkbox_cron_is_enabled_when_crontab_empty
199
+ enable_dorkbox_cronjob()
200
+ v = c('crontab -l')
201
+ assert(v.scan(/#{DORKBOX_CRONTAB_COMMENT}/).size == 2)
202
+ end
203
+
204
+ def test_dorkbox_cron_is_not_duplicated_if_already_there
205
+ enable_dorkbox_cronjob()
206
+ enable_dorkbox_cronjob('asdasd')
207
+ v = c('crontab -l')
208
+ assert(v.scan(/#{DORKBOX_CRONTAB_COMMENT}/).size == 2)
209
+ end
210
+
211
+ def test_dorkbox_cron_is_updated_if_already_there
212
+ enable_dorkbox_cronjob()
213
+ enable_dorkbox_cronjob('asdasd')
214
+ v = c('crontab -l')
215
+ assert(v.scan(/#{DORKBOX_CRONTAB_COMMENT}/).size == 2)
216
+ assert(v.scan(/asdasd/).size == 1)
217
+ end
218
+ end
219
+
220
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dorkbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -20,6 +20,7 @@ extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
22
  - lib/dorkbox.rb
23
+ - lib/dorkbox_test.rb
23
24
  - executables/dorkbox
24
25
  - executables/test
25
26
  homepage: https://github.com/alanfranz/dorkbox