Class: Tes::Request::RSpec::CiPool

Inherits:
Object
  • Object
show all
Defined in:
lib/tes/request/rspec/ci_pool.rb

Constant Summary collapse

SUPPORT_FUNCTIONS =
%i[satisfy]

Instance Method Summary collapse

Constructor Details

#initialize(tes_pool_url, pool_func) ⇒ CiPool

Returns a new instance of CiPool.



10
11
12
13
14
15
16
17
# File 'lib/tes/request/rspec/ci_pool.rb', line 10

def initialize(tes_pool_url, pool_func) #
  @pool_url = tes_pool_url
  @pool_func = pool_func
  driver = HTTPClient.new(base_url: tes_pool_url)
  driver.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
  client = ::Tes::Request::Client.new(driver)
  @pool = client.get_all_res
end

Instance Method Details

#run(*args) ⇒ Object



19
20
21
# File 'lib/tes/request/rspec/ci_pool.rb', line 19

def run(*args)
  send(@pool_func, *args)
end

#satisfy(project_dir, ci_type, res_replace_map_json_file = nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/tes/request/rspec/ci_pool.rb', line 23

def satisfy(project_dir, ci_type, res_replace_map_json_file=nil)
  res_addition_attr_map = (res_replace_map_json_file && JSON.parse(File.read(res_replace_map_json_file)))
  rspec_distribute = Distribute.new(project_dir)
  jobs = rspec_distribute.distribute_jobs(ci_type, 1, res_addition_attr_map)
  not_satisfied_profiles = jobs.inject([]) do |t, job|
    t << job[:profile] unless job[:profile].request(@pool).all?
    t
  end
  unless not_satisfied_profiles.empty?
    warn <<EOF
!!!No matched resources in pool for profiles ==>

#{not_satisfied_profiles.join("\n------------------\n")}
~~~~~~~~~~~~~~~~~~~~~~~!!!
EOF
    raise('No matched resources in pool')
  end
end