require 'fileutils' require 'ostruct' require 'P4' #------------------------------------------------------------------------------ # Configuration #------------------------------------------------------------------------------ # Make sure everything Sinatra is in test mode ENV['RACK_ENV'] = 'test' ENABLE_GIT_FUSION = ENV['ENABLE_GIT_FUSION'] || false P4PORT = ENV['P4PORT'] || 'localhost:1666' TMP_FOLDER = '/tmp/clients' DELETE_CLIENT = !ENV.key?('KEEP_WORKSPACES') CHARSET = ENV['P4CHARSET'] || 'auto' JDOE_USER = 'jdoe' JDOE_PASSWORD = 'johndoe1A!' SUPER_USER = 'super' SUPER_PASSWORD = 'superuser1A!' # This is fairly special configuration for using rack-test # Most apps are tricky to test via mocking. We load the full stack. require 'rspec' require 'rack/test' CONFIG_RU = File.absolute_path('../../config.ru', __FILE__) HELIX_WEB_SERVICES_APP = Rack::Builder.parse_file(CONFIG_RU).first require 'hws_settings' HWSSettings.system_handle.WORKSPACE_DIR = TMP_FOLDER HWSSettings.system_handle.ENABLE_GIT_FUSION = ENABLE_GIT_FUSION #------------------------------------------------------------------------------ # Helpers #------------------------------------------------------------------------------ # These methods allow you to create temporary clients, etc. for tests that # work with lower-level (i.e. service) objects # # For most methods that interact with the HTTP API, you won't need these. def ticket_for_jdoe @webauth_for_jdoe ||= create_webauth_for_jdoe header 'X-Perforce-Helix-Web-Services-P4PASSWD', p4ticket_for_jdoe header 'X-Perforce-Helix-Web-Services-P4PORT', 'localhost:1666' @webauth_for_jdoe end def p4ticket_for_jdoe @ticket_for_jdoe ||= create_ticket_for_jdoe end def create_webauth_for_jdoe post '/projects/v1/login', {:user => JDOE_USER, :password => JDOE_PASSWORD} last_response.body end def create_ticket_for_jdoe p4 = P4.new # Make P4Ruby only raise exceptions if there are errors. Warnings # (such as 'no such file(s)' don't get the same treatment. p4.exception_level = P4::RAISE_ERRORS p4.port = P4PORT p4.user = JDOE_USER p4.password = JDOE_PASSWORD p4.charset = CHARSET unless CHARSET.nil? || CHARSET == 'none' p4.connect return Auth.ticket_from_login(p4) ensure p4.disconnect end def ticket_for_super @webauth_for_super ||= create_webauth_for_super @ticket_for_super ||= create_ticket_for_super header 'X-Perforce-Helix-Web-Services-P4PASSWD', @ticket_for_super @webauth_for_super end def create_webauth_for_super post '/projects/v1/login', {:user => SUPER_USER, :password => SUPER_PASSWORD} last_response.body end def create_ticket_for_super p4 = P4.new # Make P4Ruby only raise exceptions if there are errors. Warnings # (such as 'no such file(s)' don't get the same treatment. p4.exception_level = P4::RAISE_ERRORS p4.port = P4PORT p4.user = SUPER_USER p4.password = SUPER_PASSWORD p4.charset = CHARSET unless CHARSET.nil? || CHARSET == 'none' p4.connect return Auth.ticket_from_login(p4) ensure p4.disconnect end def p4_as_jdoe p4 = P4.new # Make P4Ruby only raise exceptions if there are errors. Warnings # (such as 'no such file(s)' don't get the same treatment. p4.exception_level = P4::RAISE_ERRORS p4.port = P4PORT p4.user = JDOE_USER p4.password = JDOE_PASSWORD p4.charset = CHARSET unless CHARSET.nil? || CHARSET == 'none' p4.connect results = p4.run_login('-p') p4.password = results.first yield p4 if block_given? return p4 ensure p4.disconnect if block_given? end def temp_client_as_jdoe(&block) p4_as_jdoe do |p4| unless Dir.exists?(TMP_FOLDER) FileUtils.makedirs(TMP_FOLDER) end name = (0...8).map { (65 + rand(26)).chr }.join root = File.join(TMP_FOLDER, name) Dir.mkdir(root) p4.client = name spec = p4.fetch_client spec._root = root spec._client = name spec._description = 'test client' # When there's one depot, the view generated maps //depot/... //view/... # instead of //depot/... //view/depot/... like it will with multiple depots. if (spec._view.length == 1) spec._view = ["//depot/... //#{name}/depot/..."] end p4.save_client(spec) p4.run_sync('//...') block.call(p4, root) if DELETE_CLIENT p4.run_client('-d', name) FileUtils.rmtree(root) end end end def temp_stream_client_as_jdoe(&block) p4_as_jdoe do |p4| name = (0...8).map { (65 + rand(26)).chr }.join # Create a stream in the stream-test depot stream_spec = p4.fetch_stream("//stream-test/main-#{name}") stream_spec._type = 'mainline' stream_spec._parent = 'none' p4.save_stream(stream_spec) unless Dir.exists?(TMP_FOLDER) FileUtils.makedirs(TMP_FOLDER) end root = File.join(TMP_FOLDER, name) Dir.mkdir(root) p4.client = name spec = p4.fetch_client spec._root = root spec._client = name spec._description = 'test client' spec._view = nil spec._stream = "//stream-test/main-#{name}" p4.save_client(spec) p4.run_sync('//...') block.call(p4, root, "//stream-test/main-#{name}") if DELETE_CLIENT p4.run_client('-d', name) FileUtils.rmtree(root) end end end
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#5 | 16271 | Doug Scheirer |
- delete the default //depot for cloud tests - mark more tests as pending - refactored sync tests a little to make cloud compatib;e - fixed a bug in the sync 'locked' logic |
||
#4 | 16148 | Doug Scheirer | Merge from main | ||
#3 | 16024 | Doug Scheirer | Some cloud spec forking, got the mock_raymond to spin up in cloud testing, split normal vs cloud spec output | ||
#2 | 16014 | Doug Scheirer | Merge down from main | ||
#1 | 15688 | Doug Scheirer |
Populate -o //guest/perforce_software/helix-web-services/... //guest/doug_scheirer/helix-web-services/.... |
||
//guest/perforce_software/helix-web-services/main/source/helix_web_services/spec/test_config.rb | |||||
#1 | 15622 | tjuricek |
Move source code to 'source/' subdirectory of branch. build/ will remain where it is. |
||
//guest/perforce_software/helix-web-services/main/helix_web_services/spec/test_config.rb | |||||
#8 | 15205 | tjuricek | Implemented tests and documentation for depot spec editing. | ||
#7 | 15147 | tjuricek |
Enable submissions by files on stream clients This obeys our earlier rules: notably the local client must not have any local files open for edit. |
||
#6 | 15132 | tjuricek | Provde a basic submit -e mechanism on classic perforce workspaces. | ||
#5 | 15114 | tjuricek | While I'm seeing ticket's files generated for the 'super' user, it's possible that this login in the test suite has 'enabled it's usage'. | ||
#4 | 15110 | tjuricek | Revise changes methods for new p4 connection handling, add server specs, remove model references in client, and update asciidoc documentation. | ||
#3 | 15077 | tjuricek |
Add new 'model' technique, revised branch spec operations, test Auth::Middleware. The Ruby client now does *not* strictly type anything, but extends OpenStruct with helper methods to help deal with inconsistent data formats. See the OpenModel class documentation for more details. The Auth::Middleware class is also *finally* implemented as well. This does not take into account all possible variations of server behavior (yet), but that will happen in follow-up work. |
||
#2 | 15073 | tjuricek | Update Auth::Middleware and add spec | ||
#1 | 15032 | tjuricek |
Starting config and doc revisions. System is now broken while revisions underway. Configuration of the p4d connection is now done via a single HWSSettings middleware object injected into the Rack env. The HWSP4Cleanup middleware now cleans up any p4 injected into the Rack env. The Auth::App class now mostly just contains one method to generate a p4 ticket. /auth/v1/login. Added yard documentation for the main project. Yard docs have been reconfigured to dump into build/ directories. This should probably be done with each release. Hm... The top level rake file contains a task, 'all:doc', to update our documentation. This should probably be run for each checkin. Hm... Specs are now using Rack::Test on top of a 'live' p4d. I'd suggest you still use the p4util mechanism, which now dumps to a /tmp folder, so we can safely add P4IGNORE rules back into your local .p4config file. Old 'perforce' application now called 'helix_versioning_engine'. Removing cache data. Helix Sync may be slow. It may also get axed. We'll see. |