Class: Tes::Request::RSpec::Distribute

Inherits:
Object
  • Object
show all
Includes:
Function
Defined in:
lib/tes/request/rspec/distribute.rb

Constant Summary collapse

DEFAULT_CI_YAML_FILE =
'.ci.yaml'
EXCLUDE_CLUSTER_RES_PATTERN_PROFILE =
'.ci_exclude_res_pattern'
@@ci_yaml_file =
DEFAULT_CI_YAML_FILE
@@ci_exclude_cluster_pattern_file =
EXCLUDE_CLUSTER_RES_PATTERN_PROFILE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Function

#get_spec_path_info, #parse_spec_profile_lines

Constructor Details

#initialize(project_dir, ci_yaml_file = @@ci_yaml_file) ⇒ Distribute

Returns a new instance of Distribute.

Parameters:

  • project_dir (String)

    测试项目的根目录路径

  • ci_yaml_file (String) (defaults to: @@ci_yaml_file)

    测试项目内的描述spec测试的配置文件路径(相对‘project_dir`)



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

def initialize(project_dir, ci_yaml_file=@@ci_yaml_file)
  @project_dir = project_dir
  @ci_cfg = YAML.load_file(File.join(@project_dir, ci_yaml_file))
end

Instance Attribute Details

#ci_cfgObject (readonly)

Returns the value of attribute ci_cfg.



24
25
26
# File 'lib/tes/request/rspec/distribute.rb', line 24

def ci_cfg
  @ci_cfg
end

#project_dirObject (readonly)

Returns the value of attribute project_dir.



24
25
26
# File 'lib/tes/request/rspec/distribute.rb', line 24

def project_dir
  @project_dir
end

Instance Method Details

#distribute_jobs(type, count, res_addition_attr_map = nil) ⇒ Array<Hash>

生成分发任务的配置结构

Returns:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/tes/request/rspec/distribute.rb', line 28

def distribute_jobs(type, count, res_addition_attr_map=nil)
  task_cfg = get_rspec_task(type)
  spec_paths = spec_files(type)
  rspec_parser = Tes::Request::RSpec::ProfileParser.new(spec_paths)
  rspec_parser.parse_profiles!

  gen_pieces(rspec_parser.profiles, count).map do |piece|
    profile = piece[:profile]
    if res_addition_attr_map and res_addition_attr_map.size > 0
      res_addition_attr_map.each do |res_filter_pattern, attr_add_map|
        request_asks = profile.data.select { |ask| ask.to_s.include? res_filter_pattern }
        request_asks.each do |ask|
          # only add the resource attribution when no request the attribution for the resource
          attr_add_map.each do |attr_name, attr_limit|
            unless ask.data.include?(attr_name)
              ask.data[attr_name] = Tes::Request::Expression.new("#{attr_name}#{attr_limit}")
            end
          end
        end
      end
    end

    specs = piece[:specs].inject([]) do |t, spec|
      file_path = spec[:file].sub(/^#{@project_dir}/, '').sub(/^\//, '')
      if (spec[:locations] and spec[:locations].size > 0) or (spec[:ids] and spec[:ids].size > 0)
        if spec[:locations] and spec[:locations].size > 0
          t.push(file_path + ':' + spec[:locations].join(':'))
        end
        if spec[:ids] and spec[:ids].size > 0
          t.push(file_path + '[' + spec[:ids].join(',') + ']')
        end
      else
        t.push file_path
      end
      t
    end

    {profile: profile, specs: specs}
  end.map { |p| p.merge(tag: task_cfg['tag']) }
end