teuton 2.8.0 → 2.9.1
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.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/docs/changelog/changelog.1.md +119 -0
- data/docs/changelog/changelog.2.md +109 -0
- data/docs/diagram.md +10 -10
- data/docs/dsl/expect.md +76 -25
- data/docs/dsl/result.md +24 -30
- data/docs/learn/02-target.md +32 -27
- data/docs/learn/25-expect-result.md +39 -0
- data/docs/learn/26-expect_sequence.md +79 -0
- data/docs/learn/27-run_script.md +91 -0
- data/docs/learn/28-upload.md +55 -0
- data/docs/learn/README.md +4 -15
- data/docs/videos.md +14 -8
- data/lib/teuton/case/case.rb +3 -2
- data/lib/teuton/case/config.rb +0 -5
- data/lib/teuton/case/dsl/all.rb +5 -1
- data/lib/teuton/case/dsl/expect.rb +13 -42
- data/lib/teuton/case/dsl/expect_exitcode.rb +31 -0
- data/lib/teuton/case/dsl/expect_sequence.rb +173 -0
- data/lib/teuton/case/dsl/getset.rb +0 -1
- data/lib/teuton/case/dsl/host.rb +5 -0
- data/lib/teuton/case/dsl/macro.rb +7 -3
- data/lib/teuton/case/dsl/run_script.rb +35 -0
- data/lib/teuton/case/dsl/upload.rb +42 -0
- data/lib/teuton/case/dsl/weight.rb +12 -0
- data/lib/teuton/case/host.rb +68 -0
- data/lib/teuton/case/play.rb +2 -6
- data/lib/teuton/{utils → case}/result/ext_array.rb +0 -1
- data/lib/teuton/{utils → case}/result/ext_compare.rb +0 -1
- data/lib/teuton/{utils → case}/result/ext_filter.rb +0 -2
- data/lib/teuton/{utils → case}/result/result.rb +13 -21
- data/lib/teuton/check/checker.rb +82 -0
- data/lib/teuton/check/dsl/all.rb +37 -0
- data/lib/teuton/check/{builtin.rb → dsl/builtin.rb} +1 -3
- data/lib/teuton/check/dsl/expect.rb +90 -0
- data/lib/teuton/check/dsl/expect_sequence.rb +29 -0
- data/lib/teuton/check/dsl/getset.rb +23 -0
- data/lib/teuton/check/dsl/run.rb +35 -0
- data/lib/teuton/check/main.rb +29 -0
- data/lib/teuton/check/show.rb +75 -100
- data/lib/teuton/deprecated/application_test.rb +32 -0
- data/lib/teuton/readme/dsl/all.rb +32 -0
- data/lib/teuton/readme/dsl/expect.rb +29 -0
- data/lib/teuton/readme/dsl/getset.rb +33 -0
- data/lib/teuton/readme/dsl/run.rb +51 -0
- data/lib/teuton/readme/lang.rb +8 -10
- data/lib/teuton/readme/main.rb +27 -0
- data/lib/teuton/readme/readme.rb +31 -58
- data/lib/teuton/readme/result.rb +7 -0
- data/lib/teuton/utils/configfile_reader.rb +25 -10
- data/lib/teuton/utils/logger.rb +32 -0
- data/lib/teuton/utils/verbose.rb +1 -1
- data/lib/teuton/version.rb +1 -1
- data/lib/teuton.rb +6 -5
- metadata +45 -39
- data/docs/CHANGELOG.md +0 -10
- data/docs/changelog/v2.0.md +0 -18
- data/docs/changelog/v2.1.md +0 -54
- data/docs/changelog/v2.2.md +0 -42
- data/docs/changelog/v2.3.md +0 -10
- data/docs/changelog/v2.4.md +0 -41
- data/docs/changelog/v2.5.md +0 -6
- data/docs/changelog/v2.6.md +0 -4
- data/docs/changelog/v2.7.md +0 -23
- data/docs/changelog/v2.8.md +0 -11
- data/docs/changelog/version2.1.md +0 -4
- data/docs/learn/videos.md +0 -13
- data/lib/teuton/case/execute/copy_ssh.rb +0 -70
- data/lib/teuton/check/dsl.rb +0 -112
- data/lib/teuton/check/laboratory.rb +0 -59
- data/lib/teuton/readme/dsl.rb +0 -126
- /data/lib/teuton/case/dsl/{goto.rb → run.rb} +0 -0
- /data/lib/teuton/{utils → deprecated}/application.rb +0 -0
- /data/lib/teuton/{case/deprecated → deprecated}/runner.rb +0 -0
- /data/lib/teuton/{case/deprecated → deprecated}/utils.rb +0 -0
data/lib/teuton/check/show.rb
CHANGED
@@ -1,91 +1,29 @@
|
|
1
1
|
require "terminal-table"
|
2
2
|
require "rainbow"
|
3
3
|
|
4
|
+
require_relative "../utils/logger"
|
4
5
|
require_relative "../utils/project"
|
5
6
|
require_relative "../utils/configfile_reader"
|
6
7
|
|
7
|
-
class
|
8
|
-
def
|
9
|
-
@
|
10
|
-
|
11
|
-
show_stats
|
12
|
-
revise_config_content
|
8
|
+
class ShowCheck
|
9
|
+
def initialize(stats:, path:)
|
10
|
+
@stats = stats
|
11
|
+
@path = path
|
13
12
|
end
|
14
13
|
|
15
|
-
def
|
16
|
-
|
17
|
-
process_content
|
18
|
-
@verbose = true
|
19
|
-
recomended_panelconfig_content
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def verbose(text)
|
25
|
-
print text if @verbose
|
26
|
-
end
|
27
|
-
|
28
|
-
def verboseln(text)
|
29
|
-
puts text if @verbose
|
30
|
-
end
|
31
|
-
|
32
|
-
def process_content
|
33
|
-
groups = Project.value[:groups]
|
34
|
-
option = Project.value[:options]
|
35
|
-
@stats[:uses] = Project.value[:uses].size
|
36
|
-
verboseln ""
|
37
|
-
groups.each do |t|
|
38
|
-
@stats[:groups] += 1
|
39
|
-
unless option[:panel]
|
40
|
-
msg = "GROUP: #{t[:name]}"
|
41
|
-
my_screen_table = Terminal::Table.new { |st| st.add_row [msg] }
|
42
|
-
verboseln my_screen_table
|
43
|
-
end
|
44
|
-
instance_eval(&t[:block])
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def find_script_vars
|
49
|
-
script_vars = [:tt_members]
|
50
|
-
@hosts.each_key do |k|
|
51
|
-
next if k == :localhost
|
52
|
-
|
53
|
-
if k.instance_of? Symbol
|
54
|
-
script_vars << (k.to_s + "_ip").to_sym
|
55
|
-
script_vars << (k.to_s + "_username").to_sym
|
56
|
-
script_vars << (k.to_s + "_password").to_sym
|
57
|
-
else
|
58
|
-
script_vars << k.to_s + "_ip"
|
59
|
-
script_vars << k.to_s + "_username"
|
60
|
-
script_vars << k.to_s + "_password"
|
61
|
-
end
|
62
|
-
end
|
63
|
-
@gets.each_key { |k| script_vars << k }
|
64
|
-
script_vars
|
65
|
-
end
|
66
|
-
|
67
|
-
def recomended_config_content
|
68
|
-
warn Rainbow("[WARN] Configfile not found").bright.yellow
|
69
|
-
warn Rainbow(" #{@path[:config]}").white
|
70
|
-
warn Rainbow("[INFO] Recomended content:").bright.yellow
|
71
|
-
output = {global: nil, cases: []}
|
72
|
-
output[:cases][0] = {}
|
73
|
-
script_vars = find_script_vars
|
74
|
-
script_vars.each { |i| output[:cases][0][i] = "VALUE" }
|
75
|
-
verboseln Rainbow(YAML.dump(output)).white
|
76
|
-
end
|
77
|
-
|
78
|
-
def recomended_panelconfig_content
|
79
|
-
output = {global: nil, cases: [{}]}
|
14
|
+
def suggest_config_content
|
15
|
+
output = {"global" => nil, "cases" => [{}]}
|
80
16
|
script_vars = find_script_vars
|
81
|
-
|
82
|
-
|
83
|
-
verboseln YAML.dump(output)
|
17
|
+
script_vars.each { |i| output["cases"][0][i.to_s] = "VALUE" }
|
18
|
+
Logger.info YAML.dump(output)
|
84
19
|
end
|
85
20
|
|
86
21
|
def revise_config_content
|
87
22
|
unless File.exist?(@path[:config])
|
88
|
-
|
23
|
+
Logger.warn "[WARN] Configfile not found"
|
24
|
+
Logger.debug " #{@path[:config]}"
|
25
|
+
Logger.warn "[INFO] Recomended content:"
|
26
|
+
suggest_config_content
|
89
27
|
return
|
90
28
|
end
|
91
29
|
|
@@ -100,46 +38,83 @@ class Laboratory
|
|
100
38
|
script_vars.each do |value|
|
101
39
|
next unless item[value].nil?
|
102
40
|
|
103
|
-
|
41
|
+
setted = false
|
42
|
+
@stats[:sets].each do |assign|
|
43
|
+
setted = true if assign.include?(":#{value}=")
|
44
|
+
end
|
104
45
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
verboseln Rainbow("] or set tt_skip = true").red
|
46
|
+
unless setted
|
47
|
+
text = " * Define '#{value}' value for Case[#{index}] or set tt_skip = true"
|
48
|
+
Logger.error text
|
49
|
+
end
|
110
50
|
end
|
111
51
|
end
|
112
52
|
end
|
113
53
|
|
114
|
-
##
|
115
|
-
# Display stats on screen
|
116
54
|
def show_stats
|
117
|
-
@stats[:hosts] = 0
|
118
|
-
@hosts.each_pair { |_k, v| @stats[:hosts] += v }
|
119
|
-
|
120
55
|
my_screen_table = Terminal::Table.new do |st|
|
121
56
|
st.add_row ["DSL Stats", "Count"]
|
122
57
|
st.add_separator
|
123
|
-
|
58
|
+
|
59
|
+
if Project.value[:uses].size.positive?
|
60
|
+
st.add_row ["Uses", Project.value[:uses].size]
|
61
|
+
end
|
62
|
+
if Project.value[:macros].size.positive?
|
63
|
+
st.add_row ["Macros", Project.value[:macros].size]
|
64
|
+
Project.value[:macros].each_key { st.add_row ["", _1] }
|
65
|
+
end
|
124
66
|
st.add_row ["Groups", @stats[:groups]]
|
125
67
|
st.add_row ["Targets", @stats[:targets]]
|
126
|
-
|
127
|
-
|
128
|
-
st.add_row ["
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
68
|
+
runs = @stats[:hosts].values.inject(0) { |acc, item| acc + item }
|
69
|
+
st.add_row ["Runs", runs]
|
70
|
+
@stats[:hosts].each_pair { |k, v| st.add_row [" * #{k}", v] }
|
71
|
+
if @stats[:uniques].positive?
|
72
|
+
st.add_row ["Uniques", @stats[:uniques]]
|
73
|
+
end
|
74
|
+
if @stats[:logs].positive?
|
75
|
+
st.add_row ["Logs", @stats[:logs]]
|
76
|
+
end
|
77
|
+
if @stats[:readmes].positive?
|
78
|
+
st.add_row ["Readmes", @stats[:readmes]]
|
79
|
+
end
|
80
|
+
|
81
|
+
if @stats[:gets].size.positive?
|
82
|
+
total = @stats[:gets].values.inject(0) { |acc, value| acc + value }
|
83
|
+
st.add_row ["Gets", total]
|
84
|
+
list = @stats[:gets].sort_by { |_k, v| v }
|
135
85
|
list.reverse_each { |item| st.add_row [" * #{item[0]}", item[1].to_s] }
|
136
86
|
end
|
137
87
|
|
138
|
-
|
139
|
-
|
140
|
-
@sets.
|
88
|
+
if @stats[:sets].size.positive?
|
89
|
+
st.add_row ["Sets", @stats[:sets].size]
|
90
|
+
@stats[:sets].each { st.add_row ["", _1] }
|
91
|
+
end
|
92
|
+
if @stats[:uploads].size.positive?
|
93
|
+
st.add_row ["Uploads", @stats[:uploads].size]
|
94
|
+
@stats[:uploads].each { st.add_row ["", _1] }
|
95
|
+
end
|
96
|
+
end
|
97
|
+
Logger.info my_screen_table.to_s + "\n"
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
def find_script_vars
|
103
|
+
script_vars = [:tt_members]
|
104
|
+
@stats[:hosts].each_key do |k|
|
105
|
+
next if k == :localhost
|
106
|
+
|
107
|
+
if k.instance_of? Symbol
|
108
|
+
script_vars << (k.to_s + "_ip").to_sym
|
109
|
+
script_vars << (k.to_s + "_username").to_sym
|
110
|
+
script_vars << (k.to_s + "_password").to_sym
|
111
|
+
else
|
112
|
+
script_vars << k.to_s + "_ip"
|
113
|
+
script_vars << k.to_s + "_username"
|
114
|
+
script_vars << k.to_s + "_password"
|
141
115
|
end
|
142
116
|
end
|
143
|
-
|
117
|
+
@stats[:gets].keys.each { script_vars << _1 }
|
118
|
+
script_vars
|
144
119
|
end
|
145
120
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require_relative "../../lib/teuton/utils/application"
|
3
|
+
|
4
|
+
class ApplicationTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@app = Application.instance
|
7
|
+
@app.reset
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_init_params
|
11
|
+
assert_equal ".", @app.letter[:good]
|
12
|
+
assert_equal "F", @app.letter[:bad]
|
13
|
+
assert_equal "?", @app.letter[:error]
|
14
|
+
assert_equal " ", @app.letter[:none]
|
15
|
+
assert_equal "var", @app.output_basedir
|
16
|
+
assert_equal false, @app.debug
|
17
|
+
assert_equal true, @app.verbose
|
18
|
+
|
19
|
+
assert_equal true, @app.global == {}
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_quiet?
|
23
|
+
@app.verbose = false
|
24
|
+
assert_equal false, @app.verbose
|
25
|
+
assert_equal true, Application.instance.quiet?
|
26
|
+
@app.verbose = true
|
27
|
+
assert_equal true, @app.verbose
|
28
|
+
assert_equal false, Application.instance.quiet?
|
29
|
+
@app.options["quiet"] = true
|
30
|
+
assert_equal true, Application.instance.quiet?
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "expect"
|
4
|
+
require_relative "getset"
|
5
|
+
require_relative "run"
|
6
|
+
|
7
|
+
module ReadmeDSL
|
8
|
+
def readme(text)
|
9
|
+
if @action[:target].nil?
|
10
|
+
@current[:readme] << text # It's a group readme
|
11
|
+
else
|
12
|
+
@action[:readme] << text # It's a target readme
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def target(desc, args = {})
|
17
|
+
previous_host = @action[:host]
|
18
|
+
@action = {target: desc, host: previous_host, readme: []}
|
19
|
+
weight = 1.0
|
20
|
+
weight = args[:weight].to_f if args[:weight]
|
21
|
+
@action[:weight] = weight
|
22
|
+
end
|
23
|
+
alias_method :goal, :target
|
24
|
+
|
25
|
+
def unique(_key, _value)
|
26
|
+
# Nothing to do
|
27
|
+
end
|
28
|
+
|
29
|
+
def log(text = "", type = :info)
|
30
|
+
# Nothing to do
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ReadmeDSL
|
4
|
+
def expect(_cond, _args = {})
|
5
|
+
@current[:actions] << @action
|
6
|
+
result.reset
|
7
|
+
end
|
8
|
+
alias_method :expect_any, :expect
|
9
|
+
alias_method :expect_exit, :expect
|
10
|
+
alias_method :expect_first, :expect
|
11
|
+
alias_method :expect_last, :expect
|
12
|
+
alias_method :expect_one, :expect
|
13
|
+
|
14
|
+
def expect_fail
|
15
|
+
@current[:actions] << @action
|
16
|
+
result.reset
|
17
|
+
end
|
18
|
+
alias_method :expect_ok, :expect_fail
|
19
|
+
|
20
|
+
def expect_none(cond = nil)
|
21
|
+
expect(cond)
|
22
|
+
end
|
23
|
+
alias_method :expect_nothing, :expect_none
|
24
|
+
|
25
|
+
def expect_sequence(&block)
|
26
|
+
@current[:actions] << @action
|
27
|
+
result.reset
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module ReadmeDSL
|
2
|
+
def get(value)
|
3
|
+
unless @config[:global][value].nil?
|
4
|
+
@global_params[value] = @config[:global][value]
|
5
|
+
return @config[:global][value]
|
6
|
+
end
|
7
|
+
|
8
|
+
return value.to_s.upcase if @setted_params.include? value
|
9
|
+
|
10
|
+
@cases_params << value
|
11
|
+
value.to_s.upcase
|
12
|
+
end
|
13
|
+
|
14
|
+
def gett(value)
|
15
|
+
a = get(value)
|
16
|
+
if @cases_params.include? value
|
17
|
+
"[#{value}](#required-params)"
|
18
|
+
elsif @setted_params[value]
|
19
|
+
"[#{value}](#created-params)"
|
20
|
+
elsif @global_params.include? value
|
21
|
+
"[#{a}](#global-params)"
|
22
|
+
end
|
23
|
+
a
|
24
|
+
end
|
25
|
+
|
26
|
+
def set(key, value)
|
27
|
+
@setted_params[key] = value
|
28
|
+
end
|
29
|
+
|
30
|
+
def unset(_key)
|
31
|
+
# Nothing to do
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module ReadmeDSL
|
2
|
+
def goto(host = :localhost, args = {})
|
3
|
+
unless host == :localhost
|
4
|
+
b = {}
|
5
|
+
a = "#{host}_ip".to_sym
|
6
|
+
if @config[:global][a].nil? && !@setted_params.include?(a)
|
7
|
+
@cases_params << a
|
8
|
+
end
|
9
|
+
b[:ip] = @config[:global][a] if @config[:global][a]
|
10
|
+
b[:ip] = @setted_params[a] if @setted_params[a]
|
11
|
+
|
12
|
+
a = "#{host}_username".to_sym
|
13
|
+
if @config[:global][a].nil? && !@setted_params.include?(a)
|
14
|
+
@cases_params << a
|
15
|
+
end
|
16
|
+
b[:username] = @config[:global][a] if @config[:global][a]
|
17
|
+
b[:username] = @setted_params[a] if @setted_params[a]
|
18
|
+
|
19
|
+
a = "#{host}_password".to_sym
|
20
|
+
if @config[:global][a].nil? && !@setted_params.include?(a)
|
21
|
+
@cases_params << a
|
22
|
+
end
|
23
|
+
b[:password] = @config[:global][a] if @config[:global][a]
|
24
|
+
b[:password] = @setted_params[a] if @setted_params[a]
|
25
|
+
|
26
|
+
@required_hosts[host.to_s] = b
|
27
|
+
end
|
28
|
+
@action[:host] = host
|
29
|
+
@action[:exec] = args[:exec] || "noexec"
|
30
|
+
end
|
31
|
+
|
32
|
+
def run(command, args = {})
|
33
|
+
args[:exec] = command
|
34
|
+
host = :localhost
|
35
|
+
host = args[:on] if args[:on]
|
36
|
+
goto(host, args)
|
37
|
+
end
|
38
|
+
|
39
|
+
def run_script(command, args = {})
|
40
|
+
host = :localhost
|
41
|
+
host = args[:on] if args[:on]
|
42
|
+
filename = command.split[1]
|
43
|
+
upload filename, on: host
|
44
|
+
run command, args = {}
|
45
|
+
goto(host, args)
|
46
|
+
end
|
47
|
+
|
48
|
+
def upload(filename, args = {})
|
49
|
+
# Nothing to do
|
50
|
+
end
|
51
|
+
end
|
data/lib/teuton/readme/lang.rb
CHANGED
@@ -4,24 +4,22 @@ module Lang
|
|
4
4
|
def self.get(key)
|
5
5
|
lang = {}
|
6
6
|
lang["en"] = {
|
7
|
-
version: "Teuton
|
8
|
-
|
9
|
-
date: "Date : %s",
|
7
|
+
version: "Teuton : %s",
|
8
|
+
date: "Date : %s",
|
10
9
|
hosts: "\n### Required hosts\n",
|
11
10
|
params: "\n### Required params\n",
|
12
11
|
goto: "\nGo to [%s](#required-hosts) host, and do next:\n",
|
13
|
-
|
14
|
-
|
12
|
+
global_params: "\nGlobal parameters:\n",
|
13
|
+
created_params: "\nCreated during execution:\n"
|
15
14
|
}
|
16
15
|
lang["es"] = {
|
17
|
-
version: "
|
18
|
-
|
19
|
-
date: "Fecha : %s",
|
16
|
+
version: "Teuton : %s",
|
17
|
+
date: "Fecha : %s",
|
20
18
|
hosts: "\n### Máquinas que se necesitan\n",
|
21
19
|
params: "\n### Parámetros de necesarios\n",
|
22
20
|
goto: "\nIr a la máquina [%s](#required-hosts), y hacer lo siguiente:\n",
|
23
|
-
|
24
|
-
|
21
|
+
global_params: "\nParámetros globales que pueden ser modificados:\n",
|
22
|
+
created_params: "\nParámetros creados durante la ejecución del reto:\n"
|
25
23
|
}
|
26
24
|
# locale = Application.instance.options["lang"].downcase
|
27
25
|
locale = Project.value[:options]["lang"].downcase
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative "../utils/project"
|
2
|
+
require_relative "readme"
|
3
|
+
|
4
|
+
def use(filename)
|
5
|
+
filename += ".rb"
|
6
|
+
rbfiles = File.join(Project.value[:project_path], "**", filename)
|
7
|
+
files = Dir.glob(rbfiles)
|
8
|
+
use = []
|
9
|
+
files.sort.each { |f| use << f if f.include?(filename) }
|
10
|
+
require_relative use[0]
|
11
|
+
Project.value[:uses] << use[0]
|
12
|
+
end
|
13
|
+
|
14
|
+
def define_macro(name, *args, &block)
|
15
|
+
Project.value[:macros][name] = {args: args, block: block}
|
16
|
+
end
|
17
|
+
|
18
|
+
def group(name, &block)
|
19
|
+
Project.value[:groups] << {name: name, block: block}
|
20
|
+
end
|
21
|
+
alias task group
|
22
|
+
|
23
|
+
def start(&block)
|
24
|
+
# don't do nothing
|
25
|
+
end
|
26
|
+
# alias_method "play", "start" # REVISE THIS
|
27
|
+
alias play start
|
data/lib/teuton/readme/readme.rb
CHANGED
@@ -1,44 +1,19 @@
|
|
1
|
+
require_relative "../utils/logger"
|
1
2
|
require_relative "../utils/project"
|
2
3
|
require_relative "../utils/configfile_reader"
|
3
|
-
require_relative "../
|
4
|
+
require_relative "../case/dsl/macro"
|
4
5
|
require_relative "../version"
|
5
|
-
require_relative "dsl"
|
6
|
+
require_relative "dsl/all"
|
6
7
|
require_relative "lang"
|
7
|
-
|
8
|
-
def use(filename)
|
9
|
-
filename += ".rb"
|
10
|
-
rbfiles = File.join(Project.value[:project_path], "**", filename)
|
11
|
-
files = Dir.glob(rbfiles)
|
12
|
-
use = []
|
13
|
-
files.sort.each { |f| use << f if f.include?(filename) }
|
14
|
-
require_relative use[0]
|
15
|
-
Project.value[:uses] << use[0]
|
16
|
-
end
|
17
|
-
|
18
|
-
def define_macro(name, *args, &block)
|
19
|
-
puts "macro: #{name}"
|
20
|
-
Project.value[:macros][name] = {args: args, block: block}
|
21
|
-
end
|
22
|
-
|
23
|
-
def group(name, &block)
|
24
|
-
Project.value[:groups] << {name: name, block: block}
|
25
|
-
end
|
26
|
-
alias task group
|
27
|
-
|
28
|
-
def start(&block)
|
29
|
-
# don't do nothing
|
30
|
-
end
|
31
|
-
# alias_method "play", "start" # REVISE THIS
|
32
|
-
alias play start
|
8
|
+
require_relative "result"
|
33
9
|
|
34
10
|
class Readme
|
35
|
-
|
11
|
+
include DSL
|
12
|
+
include ReadmeDSL
|
36
13
|
attr_reader :result
|
37
14
|
attr_reader :data
|
38
15
|
|
39
16
|
def initialize(script_path, config_path)
|
40
|
-
# script_path Path to main rb file (start.rb)
|
41
|
-
# config_path Path to main config file (config.yaml)
|
42
17
|
@path = {}
|
43
18
|
@path[:script] = script_path
|
44
19
|
@path[:dirname] = File.dirname(script_path)
|
@@ -57,13 +32,11 @@ class Readme
|
|
57
32
|
private
|
58
33
|
|
59
34
|
def reset
|
60
|
-
# app = Application.instance
|
61
35
|
@config = ConfigFileReader.read(Project.value[:config_path])
|
62
36
|
@verbose = Project.value[:verbose]
|
63
|
-
@result =
|
37
|
+
@result = ReadmeResult.new
|
64
38
|
@data = {}
|
65
39
|
@data[:macros] = []
|
66
|
-
@data[:logs] = []
|
67
40
|
@data[:groups] = []
|
68
41
|
@data[:play] = []
|
69
42
|
reset_action
|
@@ -74,11 +47,11 @@ class Readme
|
|
74
47
|
end
|
75
48
|
|
76
49
|
def process_content
|
77
|
-
Project.value[:groups].each do |
|
78
|
-
@current = {name:
|
50
|
+
Project.value[:groups].each do |group|
|
51
|
+
@current = {name: group[:name], readme: [], actions: []}
|
79
52
|
@data[:groups] << @current
|
80
53
|
reset_action
|
81
|
-
instance_eval(&
|
54
|
+
instance_eval(&group[:block])
|
82
55
|
end
|
83
56
|
end
|
84
57
|
|
@@ -88,12 +61,11 @@ class Readme
|
|
88
61
|
|
89
62
|
def show_head
|
90
63
|
puts "```"
|
91
|
-
puts format(Lang.get(:testname), Project.value[:test_name])
|
92
64
|
puts format(Lang.get(:date), Time.now)
|
93
65
|
puts format(Lang.get(:version), Teuton::VERSION)
|
94
66
|
puts "```"
|
95
67
|
puts "\n"
|
96
|
-
puts "# #{Project.value[:test_name]}\n"
|
68
|
+
puts "# Test: #{Project.value[:test_name]}\n"
|
97
69
|
|
98
70
|
i = 1
|
99
71
|
unless @required_hosts.empty?
|
@@ -114,7 +86,6 @@ class Readme
|
|
114
86
|
@cases_params.sort!
|
115
87
|
puts Lang.get(:params)
|
116
88
|
@cases_params.uniq.each { |i| puts format("* %s", i) }
|
117
|
-
puts "\n> NOTE: Save every 'param: value' into config file."
|
118
89
|
end
|
119
90
|
end
|
120
91
|
|
@@ -122,7 +93,7 @@ class Readme
|
|
122
93
|
@data[:groups].each do |group|
|
123
94
|
next if group[:actions].empty?
|
124
95
|
|
125
|
-
puts "\n## #{group[:name].capitalize}\n
|
96
|
+
puts "\n## #{group[:name].capitalize}\n"
|
126
97
|
group[:readme].each { |line| puts "#{line}\n" }
|
127
98
|
previous_host = nil
|
128
99
|
group[:actions].each_with_index do |item, index|
|
@@ -133,10 +104,8 @@ class Readme
|
|
133
104
|
previous_host = item[:host] || "null"
|
134
105
|
puts format(Lang.get(:goto), previous_host.upcase)
|
135
106
|
end
|
136
|
-
|
137
|
-
|
138
|
-
weight = "(x#{item[:weight]}) " if item[:weight].to_i != 1
|
139
|
-
last = (item[:target].end_with?(".") ? "" : ".")
|
107
|
+
weight = "(x#{item[:weight]}) "
|
108
|
+
last = item[:target].end_with?(".", ":") ? "" : "."
|
140
109
|
puts "* #{weight}#{item[:target]}#{last}"
|
141
110
|
item[:readme].each { |line| puts " * #{line}\n" }
|
142
111
|
end
|
@@ -144,21 +113,25 @@ class Readme
|
|
144
113
|
end
|
145
114
|
|
146
115
|
def show_tail
|
147
|
-
return if @global_params.
|
116
|
+
return if (@global_params.size + @setted_params.size).zero?
|
148
117
|
|
149
118
|
puts "\n---"
|
150
119
|
puts "# ANEXO"
|
151
|
-
puts "\n##
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
120
|
+
puts "\n## Params"
|
121
|
+
|
122
|
+
if @global_params.size.positive?
|
123
|
+
puts Lang.get(:global_params)
|
124
|
+
puts "\n"
|
125
|
+
puts "| Param | Value |"
|
126
|
+
puts "| --- | --- |"
|
127
|
+
@global_params.each_pair { |k, v| puts "|#{k}|#{v}|" }
|
128
|
+
end
|
129
|
+
if @setted_params.size.positive?
|
130
|
+
puts Lang.get(:created_params)
|
131
|
+
puts "\n"
|
132
|
+
puts "| Param | Value |"
|
133
|
+
puts "| --- | --- |"
|
134
|
+
@setted_params.each_pair { |k, v| puts "|#{k}|#{v}|" }
|
135
|
+
end
|
163
136
|
end
|
164
137
|
end
|
@@ -30,11 +30,15 @@ module ConfigFileReader
|
|
30
30
|
def self.read_yaml(filepath)
|
31
31
|
begin
|
32
32
|
data = YAML.load(File.open(filepath))
|
33
|
+
# data = YAML.safe_load(
|
34
|
+
# File.open(filepath),
|
35
|
+
# permitted_classes: [Array, Date, Hash, Symbol]
|
36
|
+
# )
|
33
37
|
rescue => e
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
+
warn "\n" + ("=" * 80)
|
39
|
+
warn "[ERROR] ConfigFileReader#read <#{filepath}>"
|
40
|
+
warn " I suggest to revise file format!"
|
41
|
+
warn " #{e.message}\n" + ("=" * 80)
|
38
42
|
exit 1
|
39
43
|
end
|
40
44
|
data = convert_string_keys_to_symbol(data)
|
@@ -72,13 +76,24 @@ module ConfigFileReader
|
|
72
76
|
else
|
73
77
|
File.join(File.dirname(filepath), data[:global][:tt_include])
|
74
78
|
end
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
files.
|
79
|
+
exts = {
|
80
|
+
yaml: ['.yaml', '.YAML', '.yml', '.YML'],
|
81
|
+
json: ['.json', '.JSON']
|
82
|
+
}
|
83
|
+
files = Dir.glob(File.join(basedir, "**/*"))
|
84
|
+
files.each { |filename|
|
80
85
|
begin
|
81
|
-
|
86
|
+
ext = File.extname(filename)
|
87
|
+
if exts[:yaml].include? ext
|
88
|
+
data[:cases] << YAML.load(File.open(filename))
|
89
|
+
elsif exts[:json].include? ext
|
90
|
+
data[:cases] = JSON.parse(File.read(filename), symbolize_names: true)
|
91
|
+
elsif File.file? filename
|
92
|
+
msg = "[ERROR] Loading configuration files: " \
|
93
|
+
" No yaml/json valid extension " \
|
94
|
+
" (#{file})"
|
95
|
+
warn msg
|
96
|
+
end
|
82
97
|
rescue => e
|
83
98
|
puts "\n" + ("=" * 80)
|
84
99
|
puts "[ERROR] ConfigFileReader#read <#{file}>"
|