class TestSync

Public Instance Methods

setup() click to toggle source
# 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
teardown() click to toggle source
# 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_fixed() click to toggle source
# 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_crash() click to toggle source
# 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_clients() click to toggle source
# 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_clients() click to toggle source
# 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