git_repository_test.rb revision 698f9fc237ae6b40972b7d81e6b0efcfc3124ac2
require 'test_helper'
# Tests a git repository
#
# Author: Eugen Kuksa <eugenk@informatik.uni-bremen.de>
context 'creating and deleting a repository' do
setup do
end
teardown do
@repository = nil
end
should 'create repository' do
@path_new = "#{@path}_new"
end
should 'delete repository' do
@path_new = "#{@path}_new"
end
end
context 'existing repository' do
setup do
@userinfo = {
time: Time.now
}
end
teardown do
@repository = nil
end
context 'using files' do
setup do
@content = 'Some content'
@message = 'Some commit message'
end
should 'create single commit of a file' do
# removed because of time zone issues
#assert_equal Time.at(@repository.commit_author[:time]), Time.gm(@userinfo[:time])
end
should 'delete a file' do
end
should 'overwrite a file' do
content2 = "#{@content}_2"
message2 = "#{@message}_2"
end
should 'reset state on empty repository with failing commit block' do
end
end
# it is actually empty, but in this test this can't be found out
#assert @repository.empty?
end
should 'reset state with failing commit block' do
end
end
# it is actually equal, but in this test this can't be found out
#assert_equal first_commit_oid, @repository.head_oid
end
end
context 'using folders' do
setup do
@subfolder = 'path'
@content = 'Some content'
@message1 = 'Some commit message1'
@message2 = 'Some commit message2'
@message3 = 'Some commit message3'
end
should 'read the right number of contents in the root folder after adding the first file' do
end
should 'read the right contents in the root folder after adding the first file' do
type: :dir,
}]
end
should 'read the right number of contents in the subfolder after adding the first file' do
end
should 'read the right contents in the subfolder after adding the first file' do
type: :file,
}]
end
should 'read the right number of contents in the root folder after adding the second file' do
end
should 'read the right contents in the root folder after adding the second file' do
type: :dir,
}]
end
should 'read the right number of contents in the subfolder after adding the second file' do
end
should 'read the right contents in the subfolder after adding the second file' do
type: :file,
},{
type: :file,
}]
end
should 'read the right number of contents in the root folder after adding the third file' do
end
should 'read the right contents in the root folder after adding the third file' do
type: :dir,
},{
type: :file,
}]
end
should 'read the right number of contents in the subfolder after adding the third file' do
end
should 'read the right contents in the subfolder after adding the third file' do
type: :file,
},{
type: :file,
}]
end
should 'treat path "/" and empty path equally' do
assert_equal @repository.folder_contents(@commit_add3, '/'), @repository.folder_contents(@commit_add3)
assert_equal @repository.folder_contents(@commit_add3, '/'), @repository.folder_contents(@commit_add3, nil)
end
should 'read the right number of contents in the root folder after deleting the first file' do
end
should 'read the right contents in the root folder after deleting the first file' do
type: :dir,
},{
type: :file,
}]
end
should 'read the right number of contents in the subfolder after deleting the first file' do
end
should 'read the right contents in the subfolder after deleting the first file' do
type: :file,
}]
end
should 'read the right number of contents in the root folder after deleting the second file' do
end
should 'read the right contents in the root folder after deleting the second file' do
type: :file,
}]
end
should 'read the right number of contents in the root folder after deleting the third file' do
end
should 'read the right contents in the root folder after deleting the third file' do
end
end
context 'getting the commit history' do
setup do
@commit_other1 = @repository.commit_file(@userinfo, 'Other content1', 'file2.txt', 'Other File: Add')
@commit_other2 = @repository.commit_file(@userinfo, 'Other content2', 'file2.txt', 'Other File: Change1')
@commit_other3 = @repository.commit_file(@userinfo, 'Other content3', 'file2.txt', 'Other File: Change2')
end
should 'list all commits regarding the whole branch' do
@repository.commits.map{ |c| c[:oid] }
end
end
end
end
end
setup do
@content1 = "Some\ncontent\nwith\nmany\nlines."
@content2 = "Some\ncontent,\nwith\nmany\nlines."
end
end
end
end
end
end
assert_equal @repository.changed_files(@commit1).first[:mime_type], Mime::Type.lookup_by_extension(@file_extension)
end
end
end
end
end
end
end
assert_equal @repository.changed_files(@commit2).first[:mime_type], Mime::Type.lookup_by_extension(@file_extension)
end
end
end
end
end
end
assert_equal @repository.changed_files.first[:type], :delete
end
assert_equal @repository.changed_files.first[:mime_type], Mime::Type.lookup_by_extension(@file_extension)
end
assert_equal @repository.changed_files.first[:mime_category], 'application'
end
end
end
setup do
@commit_count = 10
@commit_count.times do |n|
@content = "content #{n}"
@filepath = "file-#{n}"
@message = "message #{n}"
end
@path_clone = '/tmp/ontohub/test/unit/git/repository_clone'
end
teardown do
@path_clone = nil
end
setup do
end
teardown do
end
end
end
end
end
assert(@repository.branches & @repository_clone.branches == @repository.branches, 'The original branches are not a subset of the clone branches.')
end
end
setup do
end
teardown do
end
end
end
end
end
assert(@repository.branches & @repository_clone.branches == @repository.branches, 'The original branches are not a subset of the clone branches.')
end
end
end
end
end
setup do
@result = GitRepository.clone_svn('http://colore.googlecode.com/svn/trunk/ontologies/owltime', @path_clone_bare, @path_clone_wc)
SCRIPT_REMOTE_V = "#{DIR}/git_repository_remote_v.sh"
end
teardown do
end
# merged all tests into a single test sincy cloning takes very long time
# there are no functions tested that cause side effects
assert @repository_clone_wc.is_svn_clone?, "Working copy is not an svn clone"
assert !@repository_clone_bare.is_svn_clone?, "Bare repo is an svn clone"
assert GitRepository.is_repository_with_working_copy?(@path_clone_wc), 'Clone is not a valid repository with working copy'
# remote handling for working copy
assert_equal [@path_clone_bare], out, 'working copy does not have any remotes'
# remote handling for bare repo
end
end
setup do
@result = GitRepository.clone_svn('http://colore.googlecode.com/svn/trunk/ontologies/owltime', @path_clone_bare, @path_clone_wc, 703)
end
teardown do
end
assert result_rebase[:success], "rebase failed:\n#{result_rebase[:out]}\n#{result_rebase[:err]}"
assert(@repository_clone_wc.commits.size > @repository_clone_bare.commits.size, 'no new commits in working copy')
assert result_push[:success], "push failed:\n#{result_push[:out]}\n#{result_push[:err]}"
end
end
end