teuton 3.0.3 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,27 +7,23 @@ require_relative "../../utils/project"
7
7
  module CheckCasesExtension
8
8
  def check_cases!
9
9
  # Start checking every single case
10
- app = Project.value
11
10
  # Load configurations from config file
12
11
  configdata = ConfigFileReader.call(Project.value[:config_path])
13
- app[:ialias] = configdata[:alias]
14
- app[:global] = configdata[:global]
15
- app[:global][:tt_testname] = app[:global][:tt_testname] || app[:test_name]
16
- app[:global][:tt_sequence] = false if app[:global][:tt_sequence].nil?
12
+ Project.add_config(configdata)
17
13
 
18
14
  # Create out dir
19
- outdir = app[:global][:tt_outdir] || File.join("var", app[:global][:tt_testname])
20
- FileUtils.mkdir_p(outdir) unless Dir.exist?(outdir)
21
- @report.output_dir = outdir
15
+ output_dir = Project.value[:output_dir]
16
+ FileUtils.mkdir_p(output_dir) unless Dir.exist?(output_dir)
17
+ @report.output_dir = output_dir
22
18
 
23
19
  # Fill report head
24
- open_main_report(app[:config_path])
20
+ open_main_report(Project.value[:config_path])
25
21
 
26
22
  # create cases and run
27
23
  configdata[:cases].each { |config| @cases << Case.new(config) }
28
24
  start_time = run_all_cases # run cases
29
25
 
30
- # TODO: merge these 2 methdos
26
+ # TODO: merge these 2 methods
31
27
  # TODO: CloseManager.call ???
32
28
  uniques = collect_uniques_for_all_cases
33
29
  close_reports_for_all_cases(uniques)
@@ -3,7 +3,7 @@ require_relative "../utils/project"
3
3
 
4
4
  class SendManager
5
5
  def initialize
6
- logpath = File.join(Project.value[:output_basedir], Project.value[:test_name], "send.log")
6
+ logpath = File.join(Project.value[:output_basedir], Project.value[:testname], "send.log")
7
7
  @logfile = File.open(logpath, "a")
8
8
  end
9
9
 
@@ -2,7 +2,7 @@ require_relative "../utils/project"
2
2
 
3
3
  class StatsManager
4
4
  def initialize
5
- filepath = File.join(Project.value[:output_basedir], Project.value[:test_name], "stats.txt")
5
+ filepath = File.join(Project.value[:output_basedir], Project.value[:testname], "stats.txt")
6
6
  @file = File.open(filepath, "w")
7
7
  end
8
8
 
data/lib/teuton/cli.rb CHANGED
@@ -44,7 +44,7 @@ class CLI < Thor
44
44
  LONGDESC
45
45
  def config(projectpath)
46
46
  # Check Test: suggest the content of the configuration file based on the test
47
- opt = { "onlyconfig" => true }
47
+ opt = {"onlyconfig" => true}
48
48
  Teuton.check(projectpath, opt)
49
49
  end
50
50
 
@@ -11,8 +11,7 @@ class Readme
11
11
  include DSL
12
12
  include ReadmeDSL
13
13
 
14
- attr_reader :result
15
- attr_reader :data
14
+ attr_reader :result, :data
16
15
 
17
16
  def initialize(script_path, config_path)
18
17
  @path = {}
@@ -66,7 +65,7 @@ class Readme
66
65
  puts format(Lang.get(:version), Teuton::VERSION)
67
66
  puts "```"
68
67
  puts "\n"
69
- puts "# Test: #{Project.value[:test_name]}\n"
68
+ puts "# Test: #{Project.value[:testname]}\n"
70
69
 
71
70
  i = 1
72
71
  unless @required_hosts.empty?
@@ -83,11 +82,11 @@ class Readme
83
82
  puts "\n> NOTE: SSH Service installation is required on every host."
84
83
  end
85
84
 
86
- unless @cases_params.empty?
87
- @cases_params.sort!
88
- puts Lang.get(:params)
89
- @cases_params.uniq.each { |i| puts format("* %s", i) }
90
- end
85
+ return if @cases_params.empty?
86
+
87
+ @cases_params.sort!
88
+ puts Lang.get(:params)
89
+ @cases_params.uniq.each { |i| puts format("* %s", i) }
91
90
  end
92
91
 
93
92
  def show_content
@@ -98,9 +97,7 @@ class Readme
98
97
  group[:readme].each { |line| puts "#{line}\n" }
99
98
  previous_host = nil
100
99
  group[:actions].each_with_index do |item, index|
101
- if item[:host].nil? && index.positive?
102
- item[:host] = group[:actions][0][:host]
103
- end
100
+ item[:host] = group[:actions][0][:host] if item[:host].nil? && index.positive?
104
101
  if previous_host.nil? || item[:host] != previous_host
105
102
  previous_host = item[:host] || "null"
106
103
  puts format(Lang.get(:goto), previous_host.upcase)
@@ -127,12 +124,12 @@ class Readme
127
124
  puts "| ----- | ----- |"
128
125
  @global_params.each_pair { |k, v| puts "|#{k}|#{v}|" }
129
126
  end
130
- if @setted_params.size.positive?
131
- puts Lang.get(:created_params)
132
- puts "\n"
133
- puts "| Param |"
134
- puts "| ----- |"
135
- @setted_params.each_pair { |k, v| puts "|#{k}|" }
136
- end
127
+ return unless @setted_params.size.positive?
128
+
129
+ puts Lang.get(:created_params)
130
+ puts "\n"
131
+ puts "| Param |"
132
+ puts "| ----- |"
133
+ @setted_params.each_pair { |k, v| puts "|#{k}|" }
137
134
  end
138
135
  end
@@ -30,7 +30,7 @@ class BaseFormatter
30
30
 
31
31
  def trim(input)
32
32
  output = input.to_s
33
- output = "...#{input[-50, input.size]}" if output.size > 65
34
- output.to_s
33
+ output = "...#{output[-50, 50]}" if output.size > 65
34
+ output
35
35
  end
36
36
  end
@@ -112,7 +112,7 @@ class TXTFormatter < ArrayFormatter
112
112
  when :red
113
113
  Rainbow(text).color(:red)
114
114
  else
115
- puts "[ERROR] TXTFormatter#colorize option=#{option}"
115
+ puts Rainbow("[ERROR] TXTFormatter#colorize option=#{option}").bright.red
116
116
  exit 1
117
117
  end
118
118
  end
@@ -41,9 +41,9 @@ module Formatter
41
41
  def self.call(report, options, filename)
42
42
  klass = get(options[:format])
43
43
  if klass.nil?
44
- puts "[ERROR] Formatter:"
45
- puts " Unkown format <#{options[:format]}>. Fix line <export format: FORMAT>"
46
- puts " Available formats: #{Formatter.available_formats.join(",")}."
44
+ warn Rainbow("[ERROR] Formatter:").bright.red
45
+ warn Rainbow("[ERROR] - Unkown format <#{options[:format]}>. Fix line <export format: FORMAT>").white
46
+ warn Rainbow("[ERROR] - Available formats: #{Formatter.available_formats.join(",")}.").white
47
47
  exit 1
48
48
  end
49
49
  formatter = klass.new(report)
@@ -11,7 +11,7 @@ module ConfigFileReader
11
11
 
12
12
  return read_json(filepath) if File.extname(filepath) == ".json"
13
13
 
14
- raise "[ERROR] ConfigFileReader.call: <#{filepath}>. Unkown extension!"
14
+ raise Rainbow("[ERROR] ConfigFileReader.call: <#{filepath}>. Unkown extension!").bright.red
15
15
  end
16
16
 
17
17
  def self.convert_string_keys_to_symbol(input)
@@ -37,7 +37,7 @@ module ConfigFileReader
37
37
  data = {}
38
38
  data[:global] = {}
39
39
  data[:alias] = {}
40
- data[:cases] = [{ tt_members: "anonymous" }]
40
+ data[:cases] = [{tt_members: "anonymous"}]
41
41
  data
42
42
  end
43
43
 
@@ -60,9 +60,9 @@ module ConfigFileReader
60
60
  def self.read_yaml(filepath)
61
61
  begin
62
62
  data = YAML.load(File.open(filepath))
63
- rescue StandardError => e
64
- warn "[ERROR] ConfigFileReader.read_yaml: #{e}"
65
- warn "[ERROR] Revise file content! <#{filepath}>"
63
+ rescue => e
64
+ warn Rainbow("[ERROR] ConfigFileReader.read_yaml: #{e}").bright.red
65
+ warn Rainbow("[ERROR] Revise file content! <#{filepath}>").white
66
66
  exit 1
67
67
  end
68
68
  data = convert_string_keys_to_symbol(data)
@@ -88,10 +88,10 @@ module ConfigFileReader
88
88
 
89
89
  include_dir = data[:global][:tt_include]
90
90
  basedir = if include_dir == File.absolute_path(include_dir)
91
- include_dir
92
- else
93
- File.join(File.dirname(filepath), data[:global][:tt_include])
94
- end
91
+ include_dir
92
+ else
93
+ File.join(File.dirname(filepath), data[:global][:tt_include])
94
+ end
95
95
  filepaths = Dir.glob(File.join(basedir, "**/*"))
96
96
  filepaths.each do |filepath|
97
97
  if File.directory?(filepath)
@@ -110,10 +110,10 @@ module ConfigFileReader
110
110
  def self.read_included_yaml_file(filepath)
111
111
  begin
112
112
  data = YAML.load(File.open(filepath))
113
- rescue StandardError => e
114
- warn "[ERROR] Reading configurations from yaml:"
115
- warn "[ERROR] - File : #{filepath}"
116
- warn "[ERROR] - Type : #{e}"
113
+ rescue => e
114
+ warn Rainbow("[ERROR] Reading configurations from yaml:").bright.red
115
+ warn Rainbow("[ERROR] - File : #{filepath}").white
116
+ warn Rainbow("[ERROR] - Type : #{e}").white
117
117
  exit 1
118
118
  end
119
119
  data[:tt_source_file] = relative_path(filepath)
@@ -123,10 +123,10 @@ module ConfigFileReader
123
123
  def self.read_included_json_file(filepath)
124
124
  begin
125
125
  data = JSON.parse(File.read(filepath), symbolize_names: true)
126
- rescue StandardError => e
127
- warn "[ERROR] Reading configurations from json:"
128
- warn "[ERROR] - File : #{filepath}"
129
- warn "[ERROR] - Type : #{e}"
126
+ rescue => e
127
+ warn Rainbow("[ERROR] Reading configurations from json:").bright.red
128
+ warn Rainboe("[ERROR] - File : #{filepath}").white
129
+ warn Rainbow("[ERROR] - Type : #{e}").white
130
130
  exit 1
131
131
  end
132
132
  data[:tt_source_file] = relative_path(filepath)
@@ -1,18 +1,14 @@
1
1
  require "rainbow"
2
2
 
3
3
  class NameFileFinder
4
- attr_reader :options
5
- attr_reader :project_path
6
- attr_reader :script_path
7
- attr_reader :config_path
8
- attr_reader :test_name
4
+ attr_reader :options, :project_path, :script_path, :config_path, :testname
9
5
 
10
6
  def initialize(options = {})
11
7
  @options = options
12
8
  @project_path = nil
13
9
  @script_path = nil # Path to DSL script file
14
10
  @config_path = nil # Path to YAML config file
15
- @test_name = nil
11
+ @testname = nil
16
12
  end
17
13
 
18
14
  ##
@@ -44,7 +40,7 @@ class NameFileFinder
44
40
 
45
41
  @project_path = folder_path
46
42
  @script_path = script_path
47
- @test_name = folder_path.split(File::SEPARATOR)[-1]
43
+ @testname = folder_path.split(File::SEPARATOR)[-1]
48
44
 
49
45
  find_configfilename_from_directory(folder_path)
50
46
  end
@@ -59,9 +55,7 @@ class NameFileFinder
59
55
  # Config name file is introduced by cname arg option from teuton command
60
56
  config_name = options["cname"] unless options["cname"].nil?
61
57
  config_path = File.join(folder_path, "#{config_name}.json")
62
- unless File.exist? config_path
63
- config_path = File.join(folder_path, "#{config_name}.yaml")
64
- end
58
+ config_path = File.join(folder_path, "#{config_name}.yaml") unless File.exist? config_path
65
59
  else
66
60
  # Config path file is introduced by cpath arg option from teuton command
67
61
  config_path = options["cpath"]
@@ -81,7 +75,7 @@ class NameFileFinder
81
75
 
82
76
  @project_path = File.dirname(script_path)
83
77
  @script_path = script_path
84
- @test_name = File.basename(script_path, ".rb")
78
+ @testname = File.basename(script_path, ".rb")
85
79
  find_configfilenames_from_rb(script_path)
86
80
  end
87
81
 
@@ -95,9 +89,7 @@ class NameFileFinder
95
89
  config_name = options["cname"] unless options["cname"].nil?
96
90
 
97
91
  config_path = File.join(@project_path, config_name + ".json")
98
- unless File.exist? config_path
99
- config_path = File.join(@project_path, config_name + ".yaml")
100
- end
92
+ config_path = File.join(@project_path, config_name + ".yaml") unless File.exist? config_path
101
93
  else
102
94
  # Config path file is introduced by cpath arg option from teuton command
103
95
  config_path = options["cpath"]
@@ -7,6 +7,7 @@ class Project
7
7
  @project = {}
8
8
  @project[:running_basedir] = Dir.getwd
9
9
  @project[:output_basedir] = "var"
10
+ @project[:output_dir] = @project[:output_basedir]
10
11
  @project[:name] = "teuton"
11
12
  @project[:format] = :txt # Default export format
12
13
  @project[:debug] = false # Disable/enable local executions
@@ -42,7 +43,7 @@ class Project
42
43
  # Preprocess input options:
43
44
  # * Convert input case options String to an Array of integers
44
45
  # * Read color input option
45
- def self.add_input_params(projectpath, options)
46
+ def self.add_options(projectpath, options)
46
47
  value[:options].merge! options
47
48
  Rainbow.enabled = value[:options]["color"]
48
49
 
@@ -51,7 +52,7 @@ class Project
51
52
  value[:project_path] = finder.project_path
52
53
  value[:script_path] = finder.script_path
53
54
  value[:config_path] = finder.config_path
54
- value[:test_name] = finder.test_name
55
+ value[:testname] = finder.testname
55
56
 
56
57
  return if value[:options]["case"].nil?
57
58
 
@@ -59,6 +60,19 @@ class Project
59
60
  value[:options]["case"] = numbers.collect!(&:to_i)
60
61
  end
61
62
 
63
+ def self.add_config(configdata)
64
+ # Load configurations from config file
65
+ value[:ialias] = configdata[:alias] || {}
66
+ value[:global] = configdata[:global] || {}
67
+ value[:global][:tt_sequence] = false if value[:global][:tt_sequence].nil?
68
+ running_basedir = "#{value[:running_basedir]}/"
69
+ value[:global][:tt_script_path] = value[:script_path].gsub(running_basedir, "")
70
+ value[:global][:tt_config_path] = value[:config_path].gsub(running_basedir, "")
71
+
72
+ value[:testname] = value[:global][:tt_testname] if value[:global][:tt_testname]
73
+ value[:output_dir] = (value[:global][:tt_output_dir] || File.join(value[:output_basedir], value[:testname]))
74
+ end
75
+
62
76
  def self.relative_path(filepath)
63
77
  if filepath.start_with?(Dir.pwd)
64
78
  filepath[Dir.pwd.length + 1, filepath.length]
@@ -1,5 +1,5 @@
1
1
  module Teuton
2
- VERSION = "3.0.3".freeze
2
+ VERSION = "3.2.0".freeze
3
3
  APPNAME = "teuton".freeze
4
4
  GEMNAME = "teuton".freeze
5
5
  DOCKERNAME = "dvarrui/#{GEMNAME}".freeze
data/lib/teuton.rb CHANGED
@@ -8,7 +8,7 @@ module Teuton
8
8
  end
9
9
 
10
10
  def self.check(projectpath, options = {})
11
- Project.add_input_params(projectpath, options)
11
+ Project.add_options(projectpath, options)
12
12
  require_dsl_and_script("teuton/check/main")
13
13
  require_relative "teuton/check/checker"
14
14
  checker = Checker.new(
@@ -19,12 +19,12 @@ module Teuton
19
19
  end
20
20
 
21
21
  def self.run(projectpath, options = {})
22
- Project.add_input_params(projectpath, options)
22
+ Project.add_options(projectpath, options)
23
23
  require_dsl_and_script("teuton/case_manager/dsl")
24
24
  end
25
25
 
26
26
  def self.readme(projectpath, options = {})
27
- Project.add_input_params(projectpath, options)
27
+ Project.add_options(projectpath, options)
28
28
  require_dsl_and_script("teuton/readme/main")
29
29
  readme = Readme.new(
30
30
  Project.value[:script_path],
@@ -39,10 +39,10 @@ module Teuton
39
39
  begin
40
40
  mainscriptfile = Project.value[:script_path]
41
41
  require_relative mainscriptfile
42
- rescue StandardError => e
42
+ rescue => e
43
43
  warn Rainbow("[ERROR] #{e}").bright.red
44
44
  e.backtrace&.first(3)&.each do |line|
45
- warn Rainbow("[ERROR] #{line}").red
45
+ warn Rainbow("[ERROR] #{line}").white
46
46
  end
47
47
  exit 1
48
48
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teuton
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Vargas Ruiz
@@ -349,7 +349,7 @@ files:
349
349
  - lib/teuton/version.rb
350
350
  homepage: https://github.com/teuton-software/teuton
351
351
  licenses:
352
- - MPL-2.0
352
+ - AGPL-3.0
353
353
  metadata: {}
354
354
  rdoc_options: []
355
355
  require_paths: