Permalink
Browse files

Add a regression test for disable_publish_for_branches

  • Loading branch information...
1 parent 7968c7f commit 018465ef8495d1647743d58238e7e290164b9931 @smcv committed Feb 20, 2014
Showing with 91 additions and 0 deletions.
  1. +91 −0 src/api/test/functional/branch_publish_flag_test.rb
@@ -0,0 +1,91 @@
+# encoding: UTF-8
+require File.expand_path(File.dirname(__FILE__) + "/..") + "/test_helper"
+require 'source_controller'
+
+class BranchPublishFlagTest < ActionDispatch::IntegrationTest
+
+ fixtures :all
+
+ def setup
+ super
+ wait_for_scheduler_start
+ end
+
+ @@verbose = false
+
+ def debug(message)
+ puts message if @@verbose
+ end
+
+ def branch_helper(parent_publish_allowed, expected_publish_allowed)
+ if parent_publish_allowed
+ # publish is not disabled for Apache
+ sprj = 'Apache'
+ spkg = 'apache2'
+ else
+ # publish is disabled for BinaryprotectedProject
+ sprj = 'BinaryprotectedProject'
+ spkg = 'bdpack'
+ end
+
+ tprj = "home:king:branches:#{sprj}"
+
+ debug "branching #{sprj}/#{spkg} into #{tprj}"
+ post "/source/#{sprj}/#{spkg}", :cmd => :branch, :target_project => "#{tprj}"
+ debug @response.body
+ assert_response :success
+ if @@verbose
+ debug "here is the branch:"
+ get "/source/#{tprj}"
+ debug @response.body
+ end
+ debug "fetching branch's meta:"
+ get "/source/#{tprj}/_meta"
+ debug @response.body
+
+ if expected_publish_allowed
+ # the XML says nothing about whether publishing is enabled, which means
+ # it is
+ assert_no_xml_tag :tag => "publish"
+ else
+ # publishing is explicitly disabled
+ assert_xml_tag :tag => "publish", :child => { :tag => "disable" }
+ end
+
+ # get rid of the branch so we can try again
+ debug "deleting branch"
+ delete "/source/#{tprj}"
+ debug @response.body
+ assert_response :success
+ end
+
+ def test_branching
+ # we use an admin user so we can twiddle the configuration
+ login_king
+
+ # by default, OBS expects to have thousands of users, so publishing new
+ # branches is disabled to save resources
+ branch_helper(true, false)
+ branch_helper(false, false)
+
+ # "small team" mode: resources are unconstrained so we might as well
+ # publish everything by default
+ debug "allowing publishing for branches"
+ put '/configuration?disable_publish_for_branches=off'
+ debug @response.body
+ assert_response :success
+ branch_helper(true, true)
+ # ... but if the parent project isn't published, neither is the branch
+ branch_helper(false, false)
+
+ # explicitly go back to the default and check that the result is still
+ # the same
+ debug "explicitly disallowing publishing for branches"
+ put '/configuration?disable_publish_for_branches=on'
+ debug @response.body
+ assert_response :success
+ branch_helper(true, false)
+ branch_helper(false, false)
+ end
+end
+

0 comments on commit 018465e

Please sign in to comment.