require_relative './test_config' require 'helix_web_services_client' describe 'HelixWebServicesClient Helix Sync' do my_project_id = 'My~20Project' context 'create_helix_sync_client' do it 'should create a new client for a user' do client_as_jdoe do |c| c.add_setting('HVE_PROJECTS_PATH', '//depot/main') info = c.create_helix_sync_client(my_project_id, 'client_user_test', '/dev/null') expect(info.client).to include(my_project_id) expect(info.client).to include('client_user_test') expect(info.client).to include('jdoe') end end end context 'create_helix_sync_pending_changelist' do it 'should create or return a pending changelist for a user' do client_as_jdoe do |c| c.add_setting('HVE_PROJECTS_PATH', '//depot/main') info = c.create_helix_sync_pending_changelist(my_project_id) expect(info.change).to_not be_nil end end end context 'fetch_helix_sync_pending_changelist' do it 'should return a pending changelist for a user' do client_as_jdoe do |c| c.add_setting('HVE_PROJECTS_PATH', '//depot/main') info = c.fetch_helix_sync_pending_changelist(my_project_id) expect(info.change).to_not be_nil end end end context 'fetch_helix_sync_latest_changelist' do it 'should return a latest changelist for a user' do client_as_jdoe do |c| c.add_setting('HVE_PROJECTS_PATH', '//depot/main') info = c.fetch_helix_sync_latest_changelist(my_project_id) expect(info.change.to_i).to be > 1 end end end context 'submit_helix_sync_pending_change' do it 'should submit a pending change for a project' do client_as_jdoe do |c| c.add_setting('HVE_PROJECTS_PATH', '//depot/main') root = Dir.mktmpdir('client_test_helix_sync') # Obtain our client pointing to a temporary directory info = c.create_helix_sync_client(my_project_id, 'submit_test', root) client_name = info.client # Get the pending changelist pending_change = c.create_helix_sync_pending_changelist(my_project_id).change # Update the pending changelist to use the project client p4_as_jdoe do |p4| p4.client = client_name change_spec = p4.fetch_change(pending_change) change_spec._client = client_name p4.save_change(change_spec) end # Add and shelve a new test file rand_str = (0...8).map { (65 + rand(26)).chr }.join path = File.absolute_path("#{root}/#{rand_str}") unless Dir.exist?(File.dirname(path)) FileUtils.mkdir_p(File.dirname(path)) end IO.write(path, "I'm a little teapot") p4_as_jdoe do |p4| p4.client = client_name results = p4.run_add('-c', pending_change, path) #puts "add: #{results}" results = p4.run_shelve('-c', pending_change) #puts "shelve: #{results}" results = p4.run_revert('-c', pending_change, path) #puts "revert: #{results}" end # Submit the change (on success, this will just not throw an exception) c.submit_helix_sync_pending_change(my_project_id) end end end end