git_repository_test.rb revision f458e516c452c779efc7fc8949edfc2092d3fb82
f79d43bbe70a01454049b77d6f15f6369744959eStéphane Graberrequire 'test_helper'
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano# Tests a git repository
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano# Author: Eugen Kuksa <eugenk@informatik.uni-bremen.de>
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @repository.commit_file(@userinfo, @content, @filepath, @message)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.get_file(@filepath)[:name], @filepath.split('/')[-1]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.get_file(@filepath)[:content], @content
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.get_file('path/file.txt')[:mime_type], Mime::Type.lookup('text/plain')
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano assert_equal @repository.commit_message, @message
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano assert_equal @repository.commit_author[:name], @userinfo[:name]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.commit_author[:email], @userinfo[:email]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano # removed because of time zone issues
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano #assert_equal Time.at(@repository.commit_author[:time]), Time.gm(@userinfo[:time])
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @repository.commit_file(@userinfo, @content, @filepath, @message)
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano @repository.commit_file(@userinfo, @content, @filepath, @message)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @repository.commit_file(@userinfo, content2, @filepath, message2)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.get_file(@filepath)[:content], content2
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.commit_message(@repository.head_oid), message2
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_not_equal first_commit_oid, @repository.head_oid
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'reset state on empty repository with failing commit block' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @repository.commit_file(@userinfo, @content, @filepath, @message) do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano # it is actually empty, but in this test this can't be found out
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano first_commit_oid = @repository.commit_file(@userinfo, @content, @filepath, @message)
bb787bc51f0a272f6574fe359f0749302e67c550Matthias Brugger assert_equal first_commit_oid, @repository.head_oid
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano second_commit_oid = @repository.commit_file(@userinfo, "#{@content}!", @filepath, @message) do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano # it is actually equal, but in this test this can't be found out
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano #assert_equal first_commit_oid, @repository.head_oid
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi @commit_add1 = @repository.commit_file(@userinfo, @content, @filepath1, @message1)
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi @commit_add2 = @repository.commit_file(@userinfo, @content, @filepath2, @message2)
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi @commit_add3 = @repository.commit_file(@userinfo, @content, @filepath3, @message3)
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano @commit_del1 = @repository.delete_file(@userinfo, @filepath1)
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano @commit_del2 = @repository.delete_file(@userinfo, @filepath2)
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano @commit_del3 = @repository.delete_file(@userinfo, @filepath3)
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano should 'read the right number of contents in the root folder after adding the first file' do
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano assert_equal @repository.folder_contents(@commit_add1).size, 1
ac30d6a43245e0c50aad9e2ebfb88d80aaeea691Filippo Giunchedi should 'read the right contents in the root folder after adding the first file' do
ac30d6a43245e0c50aad9e2ebfb88d80aaeea691Filippo Giunchedi assert_equal @repository.folder_contents(@commit_add1), [{
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano should 'read the right number of contents in the subfolder after adding the first file' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.folder_contents(@commit_add1, @subfolder).size, 1
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano should 'read the right contents in the subfolder after adding the first file' do
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano assert_equal @repository.folder_contents(@commit_add1, @subfolder), [{
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'read the right number of contents in the root folder after adding the second file' do
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano assert_equal @repository.folder_contents(@commit_add2).size, 1
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano should 'read the right contents in the root folder after adding the second file' do
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano assert_equal @repository.folder_contents(@commit_add2), [{
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano should 'read the right number of contents in the subfolder after adding the second file' do
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano assert_equal @repository.folder_contents(@commit_add2, @subfolder).size, 2
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano should 'read the right contents in the subfolder after adding the second file' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.folder_contents(@commit_add2, @subfolder), [{
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'read the right number of contents in the root folder after adding the third file' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.folder_contents(@commit_add3).size, 2
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'read the right contents in the root folder after adding the third file' do
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano assert_equal @repository.folder_contents(@commit_add3), [{
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'read the right number of contents in the subfolder after adding the third file' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.folder_contents(@commit_add3, @subfolder).size, 2
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'read the right contents in the subfolder after adding the third file' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.folder_contents(@commit_add3, @subfolder), [{
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'read the right number of contents in the root folder after deleting the first file' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.folder_contents(@commit_del1).size, 2
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'read the right contents in the root folder after deleting the first file' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.folder_contents(@commit_del1), [{
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'read the right number of contents in the subfolder after deleting the first file' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.folder_contents(@commit_del1, @subfolder).size, 1
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'read the right contents in the subfolder after deleting the first file' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.folder_contents(@commit_del1, @subfolder), [{
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'read the right number of contents in the root folder after deleting the second file' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.folder_contents(@commit_del2).size, 1
c159cb963868d4646cf415abb064d8fd4b6ee848Daniel Lezcano should 'read the right contents in the root folder after deleting the second file' do
c159cb963868d4646cf415abb064d8fd4b6ee848Daniel Lezcano assert_equal @repository.folder_contents(@commit_del2), [{
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'read the right number of contents in the root folder after deleting the third file' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.folder_contents(@commit_del3).size, 0
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano should 'read the right contents in the root folder after deleting the third file' do
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano assert_equal @repository.folder_contents(@commit_del3), []
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_add1 = @repository.commit_file(@userinfo, 'Some content1', @filepath, 'Add')
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_change1 = @repository.commit_file(@userinfo, 'Some other content1', @filepath, 'Change')
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_other1 = @repository.commit_file(@userinfo, 'Other content1', 'file2.txt', 'Other File: Add')
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_delete1 = @repository.delete_file(@userinfo, @filepath)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_other2 = @repository.commit_file(@userinfo, 'Other content2', 'file2.txt', 'Other File: Change1')
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_other3 = @repository.commit_file(@userinfo, 'Other content3', 'file2.txt', 'Other File: Change2')
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_add2 = @repository.commit_file(@userinfo, 'Some content2', @filepath, 'Re-Add')
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_change2 = @repository.commit_file(@userinfo, 'Some other content2', @filepath, 'Re-Change')
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_delete2 = @repository.delete_file(@userinfo, @filepath)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'have the correct values in the history at the HEAD' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.entry_info_list(@filepath), [
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'have the correct values in the history a commit before the HEAD' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.entry_info_list(@filepath, @commit_change2), [
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'have the correct values in the history in the commit that changes another file' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.entry_info_list(@filepath, @commit_other3), [
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit1 = @repository.commit_file(@userinfo, @content1, @filepath, 'Message1')
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit2 = @repository.commit_file(@userinfo, @content2, @filepath, 'Message2')
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit3 = @repository.delete_file(@userinfo, @filepath)
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand should 'have the right file count when using the first commit' do
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand assert_equal @repository.get_changed_files(@commit1).size, 1
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand should 'have the right name in the list when using the first commit' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.get_changed_files(@commit1).first[:name], 'file.xml'
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'have the right path in the list when using the first commit' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.get_changed_files(@commit1).first[:path], @filepath
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'have the right type in the list when using the first commit' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.get_changed_files(@commit1).first[:type], :add
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand should 'have the right mime type in the list when using the first commit' do
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand assert_equal @repository.get_changed_files(@commit1).first[:mime_type], Mime::Type.lookup_by_extension(@file_extension)
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand should 'have the right mime category in the list when using the first commit' do
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand assert_equal @repository.get_changed_files(@commit1).first[:mime_category], 'application'
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand should 'have the right editable in the list when using the first commit' do
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand assert_equal @repository.get_changed_files(@commit1).first[:editable], true
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand should 'have the right file count when using a commit in the middle' do
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano assert_equal @repository.get_changed_files(@commit2).size, 1
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand should 'have the right name in the list when using a commit in the middle' do
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand assert_equal @repository.get_changed_files(@commit2).first[:name], @filepath.split('/')[-1]
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand should 'have the right path in the list when using a commit in the middle' do
f79d43bbe70a01454049b77d6f15f6369744959eStéphane Graber assert_equal @repository.get_changed_files(@commit2).first[:path], @filepath
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand should 'have the right type in the list when using a commit in the middle' do
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand assert_equal @repository.get_changed_files(@commit2).first[:type], :change
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand should 'have the right mime type in the list when using a commit in the middle' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.get_changed_files(@commit2).first[:mime_type], Mime::Type.lookup_by_extension(@file_extension)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'have the right mime category in the list when using a commit in the middle' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.get_changed_files(@commit2).first[:mime_category], 'application'
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand should 'have the right editable in the list when using a commit in the middle' do
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand assert_equal @repository.get_changed_files(@commit2).first[:editable], true
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'have the right file count when using the HEAD' do
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand should 'have the right name in the list when using the HEAD' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.get_changed_files.first[:name], @filepath.split('/')[-1]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'have the right path in the list when using the HEAD' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.get_changed_files.first[:path], @filepath
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand should 'have the right type in the list when using the HEAD' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.get_changed_files.first[:type], :delete
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'have the right mime type in the list when using the HEAD' do
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand assert_equal @repository.get_changed_files.first[:mime_type], Mime::Type.lookup_by_extension(@file_extension)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'have the right mime category in the list when using the HEAD' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.get_changed_files.first[:mime_category], 'application'
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'have the right editable in the list when using the HEAD' do