Class: TestSync

Inherits:
MiniTest::Unit::TestCase
  • Object
show all
Includes:
Dorkbox
Defined in:
lib/dorkbox_test.rb

Constant Summary

Constants included from Dorkbox

Dorkbox::CONFLICT_STRING, Dorkbox::DORKBOX_CONFIG_PATH, Dorkbox::DORKBOX_CRONTAB_COMMENT, Dorkbox::GITIGNORE

Instance Method Summary collapse

Methods included from Dorkbox

#align_client_ref_to_master, #cleanup_tracked, #configure_client_id, #connect, #create, #create_new_client_id, #enable_dorkbox_cronjob, #retrieve_client_id, #sync, #sync_tracked, #track

Instance Method Details

#setupObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/dorkbox_test.rb', line 55

def setup
  @remote_repo_dir = Dir.mktmpdir()
  `git init --bare #{@remote_repo_dir}`

  @first_client_dir = Dir.mktmpdir()
  @second_client_dir = Dir.mktmpdir()

  Dir.chdir(@first_client_dir) {
    create(@remote_repo_dir)
  }

  Dir.chdir(@second_client_dir) {
    connect(@remote_repo_dir)
  }
end

#teardownObject



71
72
73
74
75
76
# File 'lib/dorkbox_test.rb', line 71

def teardown
  FileUtils.remove_entry_secure(@remote_repo_dir)
  FileUtils.remove_entry_secure(@first_client_dir)
  FileUtils.remove_entry_secure(@second_client_dir)
  cleanup_tracked()
end

#test_conflicted_client_doesnt_sync_until_fixedObject



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/dorkbox_test.rb', line 122

def test_conflicted_client_doesnt_sync_until_fixed
  Dir.chdir(@first_client_dir) {
    File.open("something", "w") { |f| f.write("asd") }
    sync()
  }

  Dir.chdir(@second_client_dir) {
    File.open("something", "w") { |f| f.write("whatsup") }
    begin
      sync()
    rescue StandardError => e
    end

    assert(File.exists? CONFLICT_STRING)

  }

  Dir.chdir(@second_client_dir) {
    begin
      sync()
      flunk('should have raised exception')
    rescue StandardError => e
    end
  }

  Dir.chdir(@second_client_dir) {
    `git merge dorkbox/master || true`
    File.open("something", "w") { |f| f.write("merged") }
    `git commit  -am 'merged'`
    File.delete(CONFLICT_STRING)
    sync()
  }

  Dir.chdir(@first_client_dir) {
    sync()
    File.open("something") { |f| assert_equal("merged", f.read()) }
  }
end

#test_multiple_sync_without_changes_doesnt_crashObject



161
162
163
164
165
166
167
168
# File 'lib/dorkbox_test.rb', line 161

def test_multiple_sync_without_changes_doesnt_crash
  Dir.chdir(@second_client_dir) {
    sync()
    sync()
    sync()
  }

end

#test_syncing_between_two_clientsObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/dorkbox_test.rb', line 78

def test_syncing_between_two_clients
  Dir.chdir(@first_client_dir) {
    File.open("something", "w") { |f| f.write("asd") }
    sync()
  }

  Dir.chdir(@second_client_dir) {
    sync()
    File.open("something") { |f| assert_equal("asd", f.read()) }
  }

  Dir.chdir(@second_client_dir) {
    File.open("something", "a") { |f| f.write("xyz") }
    sync()
  }

  Dir.chdir(@first_client_dir) {
    sync()
    File.open("something", "r") { |f| assert_equal("asdxyz", f.read()) }
  }
end

#test_tracking_between_two_clientsObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/dorkbox_test.rb', line 100

def test_tracking_between_two_clients
  Dir.chdir(@first_client_dir) {
    File.open("something", "w") { |f| f.write("asd") }
    sync_tracked()
  }

  Dir.chdir(@second_client_dir) {
    sync_tracked()
    File.open("something") { |f| assert_equal("asd", f.read()) }
  }

  Dir.chdir(@second_client_dir) {
    File.open("something", "a") { |f| f.write("xyz") }
    sync_tracked()
  }

  Dir.chdir(@first_client_dir) {
    sync_tracked()
    File.open("something", "r") { |f| assert_equal("asdxyz", f.read()) }
  }
end