# Copyright (c) 2014 Perforce Software, Inc. All rights reserved. require 'rspec' require 'helix_web_services_client' require_relative './test_config' RSpec.describe 'HelixWebServicesClient changes' do it 'should list change 1' do client_as_jdoe do |c| changes = c.changes expect(changes.length).to be >= 1 expect(changes.map(&:change)).to include('1') end end it 'should describe two files in change 1' do client_as_jdoe do |c| change = c.change('1') expect(change.depot_file.length).to eq(2) end end it 'should allow us to integrate' do randstr = (0...8).map { (65 + rand(26)).chr }.join client_as_jdoe do |c| c.create_change( 'Files' => [ { 'DepotFile' => "//depot/test-#{randstr}/Experimental/...", 'FromDepotFile' => '//depot/dev/Experimental/...', 'Action' => 'branch' } ] ) files = c.files("//depot/test-#{randstr}/Experimental") expect(files.map(&:depot_file)).to include("//depot/test-#{randstr}/Experimental/README") end end it 'should allow us to upload two files to //depot/dev/Experimental' do randstr = (0...8).map { (65 + rand(26)).chr }.join client_as_jdoe do |c| c.create_change( 'Description' => 'Upload two experimental files', 'Files' => [ { 'DepotFile' => "//depot/dev/Experimental/teapot1-#{randstr}.txt", 'Action' => 'upload', 'Content' => "I'm a little teapot" }, { 'DepotFile' => "//depot/dev/Experimental/teapot2-#{randstr}.txt", 'Action' => 'upload', 'Content' => 'Short and stout!' } ] ) files = c.files('//depot/dev/Experimental') names = files.map(&:depot_file) expect(names).to include("//depot/dev/Experimental/teapot1-#{randstr}.txt") expect(names).to include("//depot/dev/Experimental/teapot2-#{randstr}.txt") end end it 'should be able to submit changes shelved on classic clients' do rand_str = (0...8).map { (65 + rand(26)).chr }.join relative_path = "depot/shelved_stuff/#{rand_str}" temp_client_as_jdoe do |p4, p4_root| path = File.absolute_path("#{p4_root}/#{relative_path}") unless Dir.exist?(File.dirname(path)) FileUtils.mkdir_p(File.dirname(path)) end IO.write(path, "I'm a little teapot") change_spec = p4.fetch_change change_spec._description = "Testing shelving for #{rand_str}" results = p4.save_change(change_spec) change_num = /^Change (\d+) created.$/.match(results.first)[1] #puts "change_num: #{change_num}" results = p4.run_add('-c', change_num, path) #puts "add: #{results}" results = p4.run_shelve('-c', change_num) #puts "shelve: #{results}" results = p4.run_revert('-c', change_num, path) #puts "revert: #{results}" client_as_jdoe do |c| c.commit_change(change_num) end end client_as_jdoe do |c| file = c.file(relative_path) expect(file.depot_file).to eq("//#{relative_path}") end end it 'should be able to submit changes shelved on stream clients' do rand_str = (0...8).map { (65 + rand(26)).chr }.join relative_path = "shelved_stuff/#{rand_str}" stream = nil temp_stream_client_as_jdoe do |p4, p4_root, s| stream = s path = File.absolute_path("#{p4_root}/#{relative_path}") unless Dir.exist?(File.dirname(path)) FileUtils.mkdir_p(File.dirname(path)) end IO.write(path, "I'm a little teapot") change_spec = p4.fetch_change change_spec._description = "Testing shelving for #{rand_str}" results = p4.save_change(change_spec) change_num = /^Change (\d+) created.$/.match(results.first)[1] #puts "change_num: #{change_num}" results = p4.run_add('-c', change_num, path) #puts "add: #{results}" results = p4.run_shelve('-c', change_num) #puts "shelve: #{results}" results = p4.run_revert('-c', change_num, path) #puts "revert: #{results}" client_as_jdoe do |c| c.commit_change(change_num) end end client_as_jdoe do |c| file = c.file("#{stream}/#{relative_path}") expect(file.depot_file).to eq("#{stream}/#{relative_path}") end end end