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.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -4
  3. data/docs/changelog/changelog.1.md +119 -0
  4. data/docs/changelog/changelog.2.md +109 -0
  5. data/docs/diagram.md +10 -10
  6. data/docs/dsl/expect.md +76 -25
  7. data/docs/dsl/result.md +24 -30
  8. data/docs/learn/02-target.md +32 -27
  9. data/docs/learn/25-expect-result.md +39 -0
  10. data/docs/learn/26-expect_sequence.md +79 -0
  11. data/docs/learn/27-run_script.md +91 -0
  12. data/docs/learn/28-upload.md +55 -0
  13. data/docs/learn/README.md +4 -15
  14. data/docs/videos.md +14 -8
  15. data/lib/teuton/case/case.rb +3 -2
  16. data/lib/teuton/case/config.rb +0 -5
  17. data/lib/teuton/case/dsl/all.rb +5 -1
  18. data/lib/teuton/case/dsl/expect.rb +13 -42
  19. data/lib/teuton/case/dsl/expect_exitcode.rb +31 -0
  20. data/lib/teuton/case/dsl/expect_sequence.rb +173 -0
  21. data/lib/teuton/case/dsl/getset.rb +0 -1
  22. data/lib/teuton/case/dsl/host.rb +5 -0
  23. data/lib/teuton/case/dsl/macro.rb +7 -3
  24. data/lib/teuton/case/dsl/run_script.rb +35 -0
  25. data/lib/teuton/case/dsl/upload.rb +42 -0
  26. data/lib/teuton/case/dsl/weight.rb +12 -0
  27. data/lib/teuton/case/host.rb +68 -0
  28. data/lib/teuton/case/play.rb +2 -6
  29. data/lib/teuton/{utils → case}/result/ext_array.rb +0 -1
  30. data/lib/teuton/{utils → case}/result/ext_compare.rb +0 -1
  31. data/lib/teuton/{utils → case}/result/ext_filter.rb +0 -2
  32. data/lib/teuton/{utils → case}/result/result.rb +13 -21
  33. data/lib/teuton/check/checker.rb +82 -0
  34. data/lib/teuton/check/dsl/all.rb +37 -0
  35. data/lib/teuton/check/{builtin.rb → dsl/builtin.rb} +1 -3
  36. data/lib/teuton/check/dsl/expect.rb +90 -0
  37. data/lib/teuton/check/dsl/expect_sequence.rb +29 -0
  38. data/lib/teuton/check/dsl/getset.rb +23 -0
  39. data/lib/teuton/check/dsl/run.rb +35 -0
  40. data/lib/teuton/check/main.rb +29 -0
  41. data/lib/teuton/check/show.rb +75 -100
  42. data/lib/teuton/deprecated/application_test.rb +32 -0
  43. data/lib/teuton/readme/dsl/all.rb +32 -0
  44. data/lib/teuton/readme/dsl/expect.rb +29 -0
  45. data/lib/teuton/readme/dsl/getset.rb +33 -0
  46. data/lib/teuton/readme/dsl/run.rb +51 -0
  47. data/lib/teuton/readme/lang.rb +8 -10
  48. data/lib/teuton/readme/main.rb +27 -0
  49. data/lib/teuton/readme/readme.rb +31 -58
  50. data/lib/teuton/readme/result.rb +7 -0
  51. data/lib/teuton/utils/configfile_reader.rb +25 -10
  52. data/lib/teuton/utils/logger.rb +32 -0
  53. data/lib/teuton/utils/verbose.rb +1 -1
  54. data/lib/teuton/version.rb +1 -1
  55. data/lib/teuton.rb +6 -5
  56. metadata +45 -39
  57. data/docs/CHANGELOG.md +0 -10
  58. data/docs/changelog/v2.0.md +0 -18
  59. data/docs/changelog/v2.1.md +0 -54
  60. data/docs/changelog/v2.2.md +0 -42
  61. data/docs/changelog/v2.3.md +0 -10
  62. data/docs/changelog/v2.4.md +0 -41
  63. data/docs/changelog/v2.5.md +0 -6
  64. data/docs/changelog/v2.6.md +0 -4
  65. data/docs/changelog/v2.7.md +0 -23
  66. data/docs/changelog/v2.8.md +0 -11
  67. data/docs/changelog/version2.1.md +0 -4
  68. data/docs/learn/videos.md +0 -13
  69. data/lib/teuton/case/execute/copy_ssh.rb +0 -70
  70. data/lib/teuton/check/dsl.rb +0 -112
  71. data/lib/teuton/check/laboratory.rb +0 -59
  72. data/lib/teuton/readme/dsl.rb +0 -126
  73. /data/lib/teuton/case/dsl/{goto.rb → run.rb} +0 -0
  74. /data/lib/teuton/{utils → deprecated}/application.rb +0 -0
  75. /data/lib/teuton/{case/deprecated → deprecated}/runner.rb +0 -0
  76. /data/lib/teuton/{case/deprecated → deprecated}/utils.rb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12d43ceacd278684c8415098d95fc3803486bfa437fb2bb91c5224074b42fd2d
4
- data.tar.gz: 610841aa8b490d72158d8641450fcf794fda245285621a454e259cfbbb5f2749
3
+ metadata.gz: ee10a452f23f3de91ef5ae2239480a7f72fbd07502a846b8517b8b6c4f3200f5
4
+ data.tar.gz: cd31f3dc5521fb66205c3d5bb2c72420a0455ea1e14b2cbbaa4f1288f58da279
5
5
  SHA512:
6
- metadata.gz: 2aa8c93229422728b09aabb1f2a7c95c44af37c4a4c0a02518e8ad58a74b023d2806f299fde0005f695a66e935b03daf25ac6d75ae4fc59f2105fe4dc2fce129
7
- data.tar.gz: 047415074d71174f1399422e2cf45b92fdecc3234f3aed94e4c99ce1298fcb9db2bcc4b0daec6abac5ab65162041acf3a519c9a30dda62ee1d10f29efea7a9b1
6
+ metadata.gz: 70386a6f0b98a7efd9740e82709b7632bd67b2bd1aa090698980c151c246e2d6aea53ab76422d6c0318aceef434d5636a8c5d8797e69d13c28fabbe9b2af491e
7
+ data.tar.gz: 4e0fd5a4462fa8c728aa4daeadafee33620df166eadaab8c9ee55c27ad3e5b0c63b4615a8e7e2fc0562f85083ccca2bd2ae18793a00c668aada941ed44dc9fa5
data/README.md CHANGED
@@ -47,12 +47,12 @@ CASE RESULTS
47
47
 
48
48
  # Documentation
49
49
 
50
+ * [Installation](docs/install/README.md)
50
51
  * [Getting started](docs/learn/README.md)
51
- * [Language reference](docs/dsl/README.md)
52
+ * [Examples](examples)
52
53
  * [Commands](docs/commands/README.md)
53
- * [Installation](docs/install/README.md)
54
-
55
- > [Blogs and videos](docs/videos.md)
54
+ * [Language reference](docs/dsl/README.md)
55
+ * [Blogs and videos](docs/videos.md)
56
56
 
57
57
  # Contact
58
58
 
@@ -0,0 +1,119 @@
1
+ [<< back](../CHANGELOG.md)
2
+
3
+ # CHANGELOG
4
+
5
+ ## [0.22.1] June 2017
6
+
7
+ * Now it's posible to use config files with YAML and JSON format
8
+ * Preparing migration of CLI command to use Thor gem
9
+
10
+ ## [1.0.0] July 2017
11
+
12
+ * New stable version
13
+
14
+ ## 2019
15
+
16
+ ## [1.10.0] Janyary 2019
17
+
18
+ * SysadminGame change his name by TEUTON. "project" command replaced by "teuton".
19
+ * Challenges (Teuton scripts) moved to "teuton-challenges" github repository.
20
+ * Execute "rake get_challenges" to get sample teuton challenges
21
+
22
+ ## [2.0.4] August 2019
23
+
24
+ * TEUTON project grew up and was divided into the folowing repositories: teuton, challenges, panel, resources and vagrant.
25
+ * Documentation has been moved into respository teuton wiki. Only maintain English docs.
26
+
27
+ ## [2.1.0]
28
+
29
+ **Export grades on csv file using Moodle format**
30
+
31
+ * Automaticaly exports `moodle.csv` file with all cases grades, using adecuate format so it could be imported directly into Moodle platform.
32
+ * We need to configure some params like this:
33
+
34
+ ```
35
+ ---
36
+ :global:
37
+ :cases:
38
+ - :tt_members: ...
39
+ :tt_moodle_id: User Moodle Identity
40
+ ```
41
+
42
+ **readme keyword**
43
+
44
+ We currently use the "teuton readme pry-folder" command to export README file from the challenge.
45
+
46
+ * This example shows how to use readme keyword to add group description or target description:
47
+
48
+ ```
49
+ group "GROUPNAME" do
50
+ readme "Description for this group"
51
+
52
+ target "target1"
53
+ readme "Description for this target"
54
+ goto :host, :exec => 'id root'
55
+ expec_one 'root'
56
+ ```
57
+
58
+ **Installation process**
59
+
60
+ * Use Bundler to install gems instead of rake.
61
+ * It will be usefull use sysadming-game as gem? And install it with `gem install teuton`.
62
+ * Vagrant: test how to use vagrant machines as case hosts.
63
+
64
+ **Info sobre novedades de la versión 2.1**
65
+
66
+ 1. Teuton readme y dsl readme
67
+ 2. Macros de define macro
68
+ 3. Export yaml y html
69
+ 4. Teuton --no-color
70
+ 5. teuton run --case
71
+ 6. teuton run --cname
72
+ 7. teuton run --cpath
73
+ 8. actualizar formatos de salida
74
+ 9. instalación mediante gemas
75
+ 10. teuton panel
76
+ 11. teuton client y server
77
+ 12. nuevos nombres de comandos...
78
+ 13. cambio de goto a run
79
+
80
+ ## [2.2.0]
81
+
82
+ **New features**
83
+
84
+ * Let's see new features examples:
85
+ * 10 result and moodle_id
86
+ * 11 get_vars
87
+ * 12 alias
88
+ * 13 include (tt_include config param)
89
+ * 14 macros
90
+
91
+ **Configuration file**
92
+
93
+ * Por defecto los valores de clave de los ficheros de configuración serán Strings en lugar de símbolos, aunque lo símbolos seguirán funcionando.
94
+
95
+ **get_vars: To think - We are not sure about this***
96
+
97
+ * "get" keyword simplification: Simplify getting and setting params process. For example: `_username_`, may be alias for `get(:username)`. Then
98
+
99
+ ```
100
+ target "Create user #{_username_}"
101
+ run "id #{_username_}"
102
+ expect_one _username_
103
+ ```
104
+ Same as
105
+
106
+ ```
107
+ target "Create user "+get(:username)
108
+ run "id " + get(:username)
109
+ expect_one get(:username)
110
+ ```
111
+
112
+ * Promocinar el proyecto:
113
+ * Documentar y hacer videos.
114
+ * Charlas y talleres
115
+
116
+ **Fixed**
117
+
118
+ * Solucionar fallo en --cname
119
+ * Revisar doc options como cpanel
@@ -0,0 +1,109 @@
1
+
2
+ ## [2.3.9]
3
+
4
+ - FIX: Remove warnings from linter
5
+ - FIX: Remove warning about thor gem version. Upgrade gem to 1.2
6
+
7
+ ## [2.3.11]
8
+
9
+ - Issue #18
10
+
11
+ ## [2.4.0]
12
+
13
+ New features:
14
+ - Hide feedback from reports: `export feedback: false`
15
+ - Add new DSL keyword: expect_last, expect_fisrt
16
+ - Remove os gem.
17
+ - Change test output colors to green as use others test tools.
18
+ - Change show DSL params. Accepts one param "verbose: NUMBER" to adjust verbosity output level on screen.
19
+
20
+ New doc and example:
21
+ - 14-alias
22
+ - 16-exit_codes
23
+
24
+ Bug fixed:
25
+ - All "expect*" keywords must require 2 arguments. The second is optional.
26
+
27
+ Revise
28
+ - Remove colors to log text
29
+ - teuton readme: macros, getvars, expect_last, expect_first
30
+
31
+ ## [2.4.2]
32
+
33
+ - Fix bug with result.grep_v(Array)
34
+
35
+ ## [2.4.3]
36
+
37
+ - Fix: "expect_none" without params works as "expect result.count.eq 0"
38
+ - Add: "expect_nothing" that works as "expect result.count.eq 0".
39
+
40
+ ## [2.4.4]
41
+
42
+ -- Modify: teuton check output colors and exit codes.
43
+ exit code 0 = check OK
44
+ exit code 1 = check error
45
+ -- Fix teuton check docs.
46
+
47
+ ## [2.4.5]
48
+
49
+ -- FIX: "expect_nothing" was always TRUE when SSH/Telnet connections fails!
50
+ Now when SSH/Telnet connections fails result contains "SSH: NO CONNECTION!"
51
+ So "expect_nothing" will fail.
52
+
53
+ ## [2.5.0]
54
+
55
+ - ADD: "tt_moodle_max_score" global configuration param. Teuton grades (0-100) are divided by this value when exporting data into "moodle.csv" output file.
56
+ - UPDATE: Revise documentation. Doc learn 10,11, 12,13 y 14. 10 result and moodle_id, 12 alias, 13 include, 14 macro, Doc tt_include
57
+ - UPDATE: Internal changes. Remove Colorize gem and replace with Rainbow.
58
+
59
+ ## [2.6.0]
60
+
61
+ - [ADD] When running local or SSH commands, stdout and stderr are captured and readed by "expect" sentence.
62
+
63
+ ## [2.7.0]
64
+
65
+ New features:
66
+ - [ADD] "teuton config PROJECTPATH" will suggest suitable configuration for the project.
67
+ - [ADD] Every one line command output is registered into reports.
68
+ - [ADD] "expect_exit 1", check last command exit code is equal to 1.
69
+
70
+ Internal changes:
71
+ * Application class splited into Settings and Project classes
72
+ * Create SendManager similar to ExportManager
73
+
74
+ ## [2.7.1]
75
+
76
+ - [FIX] Fixed an issue that appeared when executing test and fail connection to remote computer.
77
+
78
+ ## [2.7.2] 20230607
79
+
80
+ - [FIX] Fixed an issue that appeared when exporting reports without feedback after failing to connect to remote computer.
81
+
82
+ ## [2.7.3] 20230607
83
+
84
+ - [FIX] Hall of fame now use Project class instead of Application.
85
+
86
+ ## [2.8.0] 20230630
87
+
88
+ DSL expect:
89
+ - [ADD] "expect_ok" as "expect_exit 0 ".
90
+ - [ADD] "expect_fail" as "expect_exit NUMBER" where NUMBER > 0.
91
+ - [FIX] expect evaluation fail when there is no remote connection.
92
+
93
+ DSL send:
94
+ - [UPDATE] Rename "remote_dir" send param to "dir".
95
+ - [UPDATE] send output messages
96
+
97
+ ## [2.9.0] 20230726
98
+
99
+ - [ADD] "expect_sequence" that check if sequence is present
100
+ - [ADD] New DSL "run_script". Example: `run_script script, on: :host1`, upload script to host1 and then execute it on remote.
101
+ - [ADD] New DSL "upload". Upload local file to remote host. Example `upload "localfile", to: :host1`
102
+ - [ADD] `teuton check` works with `expect_sequence`, `run_script` and `upload`.
103
+ - [FIX] `teuton check` works fine with `macros`.
104
+ - [ADD] `teuton readme` works with `expect_sequence`, `run_script` and `upload`.
105
+ - [FIX] `teuton readme` works fine with `macros`.
106
+
107
+ ## [2.9.1] 20231117
108
+
109
+ - [FIX] Config option `tt_include` doubled readed data on Windows platforms.
data/docs/diagram.md CHANGED
@@ -9,15 +9,15 @@ subgraph user
9
9
  CLI --> Teuton
10
10
  end
11
11
 
12
- subgraph "create\nnew\nproject"
13
- Teuton -- create --> Skeleton("Sekeleton\nFiles")
12
+ subgraph "create new project"
13
+ Teuton -- create --> Skeleton("Skeleton\nFiles")
14
14
  end
15
15
 
16
- subgraph "Check\nproject files"
16
+ subgraph "Check\nproject"
17
17
  Teuton -- check --> Laboratory("Laboratory\nDSL\nShow\nBuiltin!")
18
18
  end
19
19
 
20
- subgraph "Create readme\nfrom project"
20
+ subgraph "Create\nproject readme"
21
21
  Teuton -- readme --> Readme("Readme\nDSL\nLang!")
22
22
  end
23
23
 
@@ -27,8 +27,8 @@ subgraph manager
27
27
  ReportManager --> HallOfFame
28
28
  end
29
29
 
30
- subgraph "case folder"
31
- CaseManager --> Case("Case\nConfig\nClose\nPlay\nRunner\ncase/DSL\ncase/builtin!")
30
+ subgraph "case"
31
+ CaseManager --> Case("Case\nConfig\nDSL\nPlay\nExecute\nResult\nClose\nbuiltin!")
32
32
  end
33
33
 
34
34
  subgraph utils
@@ -42,10 +42,10 @@ subgraph utils
42
42
  Readme --> Result("Result\next_array\next_compare\next_filter")
43
43
  Case --> Result
44
44
 
45
- Laboratory --> Application
46
- Readme --> Application
47
- manager/DSL -- use/macros/groups --> Application("Application\nNameFileFinder")
48
- Case --> Application
45
+ Laboratory --> Project
46
+ Readme --> Project
47
+ manager/DSL -- use/macros/groups --> Project("Project\nNameFileFinder")
48
+ Case --> Project
49
49
  end
50
50
 
51
51
  subgraph report
data/docs/dsl/expect.md CHANGED
@@ -9,33 +9,84 @@ Compare the obtained result with the expected one. This comparation process is r
9
9
  Let's see some examples:
10
10
 
11
11
  ```ruby
12
- target 'Exist user obiwan'
13
- run 'id obiwan'
14
- expect 'obiwan' # Expect previous run command output contains obiwan text
12
+ target "Exist user obiwan"
13
+ run "id obiwan"
14
+ expect "obiwan" # Expect run command output will contain "obiwan"
15
15
  ```
16
16
 
17
- ## Basic
17
+ ## Simple evaluations
18
18
 
19
- | Command | Description |
20
- | ------- | ----------- |
21
- | expect "yoda" or expect_any "yoda" | one or more line/s with "yoda" |
22
- | expect ["obiwan", "kenobi"] | one or more line/s with "obiwan" and kenobi" |
23
- | expect_first "episode" | the first line with "episode" |
24
- | expect_last "episode" | the last line with "episode" |
25
- | expect_one "rogue" | only one line with "rogue" |
19
+ | Command | Description |
20
+ | ----------------------------- | ------------------------------ |
21
+ | expect "yoda" | one or more line/s with "yoda" |
22
+ | expect_any "yoda" | one or more line/s with "yoda" |
23
+ | expect ["obiwan", "kenobi"] | one or more line/s with "obiwan" and kenobi" |
24
+ | expect_first "episode" | the first line with "episode" |
25
+ | expect_last "the end" | the last line with "the end" |
26
+ | expect_one "rogue" | only one line with "rogue" |
26
27
  | expect_one ["obiwan","kenobi"] | only one line with "obiwan" and "kenobi" |
27
- | expect_none "vader"| no line with "vader" |
28
+ | expect /Obiwan\|obi-wan/ | one or more line/s with Obiwan or obi-wan. This example uses regular expresions. |
29
+
30
+ ## Negative evaluations
31
+
32
+ | Command | Description |
33
+ | ------------------------------ | ---------------------------- |
34
+ | expect_none "vader" | Expects no line with "vader" |
28
35
  | expect_none ["darth", "vader"] | no line with "darth" or "vader" |
29
- | expect_none | no output lines expected |
30
- | expect_nothing | no output lines expected |
31
- | expect /Obiwan\|obi-wan/ | one or more line/s with Obiwan or obi-wan. This example uses regular expresions. |
32
- | expect_exit NUMBER | Check exit code is NUMBER |
33
- | expect_ok | Check exit code is 0 |
34
- | expect_fail | Check exit code is > 0 |
36
+ | expect_none | no output lines expected |
37
+ | expect_nothing | no output lines expected |
38
+
39
+ ## Exitcode evaluations
40
+
41
+ | Command | Description |
42
+ | -------------------- | ------------------------- |
43
+ | expect_ok | Check exit code is 0 |
44
+ | expect_fail | Check exit code is > 0 |
45
+ | expect_exit NUMBER | Check exit code is NUMBER |
46
+ | expect_exit MIN..MAX | Check exit code is >= MIN and < MAXNUMBER |
47
+
48
+ ## Evaluate sequence
49
+
50
+ * **Simple sequence**. Validate sequences where the elements are in order. Use `find` statement to find each element of the sequence.
51
+
52
+ ```ruby
53
+ # Examples: [A,B,C], [A,s,B,s,C], [x,A,B,s,C,x], etc.
54
+
55
+ expect_sequence do
56
+ find "A"
57
+ find "B"
58
+ find "C"
59
+ end
60
+ ```
61
+
62
+ * **Strict sequence**. validate sequences where the elements are in strict consecutive order. First use `find` to find an element in the sequence and then `next_to` for the next element in strict order.
63
+
64
+ ```ruby
65
+ # Examples: [A,B,C], [x,A,B,C,x], etc.
66
+
67
+ expect_sequence do
68
+ find "A"
69
+ next_to "B"
70
+ next_to "C"
71
+ end
72
+ ```
73
+
74
+ * **Strict sequence with jumps**. Use `ignore N` to indicate that there are N lines between 2 elements of the sequence.
75
+
76
+ ```ruby
77
+ # Examples: [A,B,s,s,C], [x,A,B,s,s,C,x], etc.
78
+
79
+ expect_sequence do
80
+ find "A"
81
+ next_to "B"
82
+ ignore 2
83
+ next_to "C"
84
+ end
85
+ ```
35
86
 
36
- ## Advanced
87
+ ## Complex evaluations
37
88
 
38
- After every execution keyword (`run`, `on` or `goto`), command outputs is saved by **result** object. Use **result** to create more complex evaluations.
89
+ After every execution keyword `run`, command outputs is wrapped into **result** object. We may use **result** to make complex evaluations.
39
90
 
40
91
  For example, if we have this execution
41
92
 
@@ -44,10 +95,10 @@ target 'Exist user vader'
44
95
  run 'cat /etc/passwd'
45
96
  ```
46
97
 
47
- Then we check result with:
98
+ Then we can check result with:
48
99
 
49
- * **expect result.find("vader").count.eq(1)**, expect there exists only 1 line with "vader" text.
50
- * **expect result.find(/Darth|darth/).find(/Vader|vader/).count.gt(2)**, expect there exists more than 2 lines with texts "Darth" and "Vader".
51
- * **expect result.not_find('#').find('vader').count.lt(3)**, expects there exists less than 3 lines with text "vader" and without "#" symbol.
100
+ * **expect result.find(/obiwan|kenobi/).count.eq(1)**, expect there exists only 1 line with "obiwan" or "kenobi".
101
+ * **expect result.find(/darth/).find(/vader/).count.gt(2)**, expect there exists more than 2 lines with texts "darth" and "vader".
102
+ * **expect result.not_find('#').find('yoda').count.lt(3)**, expects there exists less than 3 lines with text "yoda" and without "#" symbol.
52
103
 
53
- Read [result](result.md) documentation.
104
+ Read more about [result](result.md) object.
data/docs/dsl/result.md CHANGED
@@ -33,18 +33,12 @@ run "cat /etc/passwd", on: :host1
33
33
  ```
34
34
 
35
35
  And then we could do:
36
- * Get all lines that dosn't contain "nologin" and contain "/bin/bash"
37
- ```
38
- result.grep_v("nologin").grep("/bin/bash")
39
- ```
40
- * Count all lines that dosn't contain "nologin" and contain "/bin/bash"
41
- ```
42
- result.grep_v("nologin").grep("/bin/bash").count
43
- ```
44
- * Return true if the number when count all lines that dosn't contain "nologin" and contain "/bin/bash" is greater than 0
45
- ```
46
- result.grep_v("nologin").grep("/bin/bash").count.gt 0
47
- ```
36
+
37
+ | Description | Command |
38
+ | ----------- | ------- |
39
+ | Get all lines that dosn't contain "nologin" and contain "/bin/bash" | result.grep_v("nologin").grep("/bin/bash") |
40
+ | Count all lines that dosn't contain "nologin" and contain "/bin/bash" | result.grep_v("nologin").grep("/bin/bash").count |
41
+ | Return true if the number when count all lines that dosn't contain "nologin" and contain "/bin/bash" is greater than 0 | result.grep_v("nologin").grep("/bin/bash").count.gt 0 |
48
42
 
49
43
  ## Functions
50
44
 
@@ -52,33 +46,33 @@ result.grep_v("nologin").grep("/bin/bash").count.gt 0
52
46
 
53
47
  | Function | Description |
54
48
  | ------------------- | ------------------------- |
55
- | `result.eq(VALUE)` | Result equal to VALUE |
56
- | `result.neq(VALUE)` | Result not equal to VALUE |
57
- | `result.gt(VALUE)` | Result greater than VALUE |
58
- | `result.ge(VALUE)` | Result equal or greater than VALUE |
59
- | `result.lt(VALUE)` | Result lesser than VALUE |
60
- | `result.le(VALUE)` | Result equal or lesser than VALUE |
49
+ | result.eq(VALUE) | Result equal to VALUE |
50
+ | result.neq(VALUE) | Result not equal to VALUE |
51
+ | result.gt(VALUE) | Result greater than VALUE |
52
+ | result.ge(VALUE) | Result equal or greater than VALUE |
53
+ | result.lt(VALUE) | Result lesser than VALUE |
54
+ | result.le(VALUE) | Result equal or lesser than VALUE |
61
55
 
62
56
  **Filtering functions:**
63
57
 
64
58
  | Function | VALUE type | Description |
65
59
  | -------------------- | ----------- | ------------------------------------- |
66
- | `result.count` | | Count lines from result and save this number into result object. |
67
- | `result.first` | | Remove all lines except first one.|
68
- | `result.find(VALUE)` | String | Filter lines that contains VALUE text |
60
+ | result.count | | Count lines from result and save this number into result object. |
61
+ | result.first | | Remove all lines except first one.|
62
+ | result.find(VALUE) | String | Filter lines that contains VALUE text |
69
63
  | | RegExp | Filter lines that match VALUE regexp. For example `/?ello]`, filter lines with "Hello" or "hello" |
70
64
  | | Array | Apply filter to every array element. For example `["Hi","Hello"]`, filter lines with "Hi" or "Hello". |
71
- | `result.grep(VALUE)` | String, RegExp, Array | Same as find |
72
- | `result.grep_v(VALUE)` | String, RegExp, Array | Same as not_find |
73
- | `result.last` | | Remove all lines except last one.|
74
- | `result.not_find(VALUE)` | | Filter lines that not contains VALUE. VALUE may be String, Regular Expresion or an Array. |
75
- | `result.restore` | | Restore result data. After every filtering action result is modified, but this function restore data to their original state. |
65
+ | result.grep(VALUE) | String, RegExp, Array | Same as find |
66
+ | result.grep_v(VALUE) | String, RegExp, Array | Same as not_find |
67
+ | result.last | | Remove all lines except last one.|
68
+ | result.not_find(VALUE) | | Filter lines that not contains VALUE. VALUE may be String, Regular Expresion or an Array. |
69
+ | result.restore | | Restore result data. After every filtering action result is modified, but this function restore data to their original state. |
76
70
 
77
71
  **Information functions:**
78
72
 
79
73
  | Function | Description |
80
74
  | -------------------- | --------------------------------- |
81
- | `result.alterations` | Return transformations applied to the output |
82
- | `result.content` | Return all output lines |
83
- | `result.debug` | Print the result content on screen. Usefull for debugging process |
84
- | `result.value` | Return first output line or value |
75
+ | result.alterations | Return transformations applied to the output |
76
+ | result.content | Return all output lines |
77
+ | result.debug | Print the result content on screen. Usefull for debugging process |
78
+ | result.value | Return first output line or value |
@@ -7,37 +7,40 @@ A [target](../dsl/target.md) is a feature you want to check. Targets are defined
7
7
  ## Target definition
8
8
 
9
9
  * [target](dsl/target.md): Description of the element to be tested.
10
- * [run](../dsl/run.md): Execute a command `id david` on localhost.
10
+ * [run](../dsl/run.md): Execute a command `id obiwan` on localhost.
11
11
  * [expect](../&dsl/expect.md): Verify that the result contains expected value.
12
12
 
13
13
  ```ruby
14
14
  group "Learn about targets" do
15
15
 
16
- target "Create user david"
17
- run "id david"
18
- expect ["uid=", "(david)", "gid="]
16
+ target "Exist user obiwan"
17
+ run "id obiwan"
18
+ expect ["uid=", "(obiwan)", "gid="]
19
19
 
20
20
  target "Delete user vader"
21
21
  run "id vader"
22
- expect ["id:", "vader", "no exist"]
23
-
22
+ expect_fail
24
23
  end
25
24
  ```
26
25
 
27
- > In this example, our localhost's OS is GNU/Linux (or any other compatible OS) because the command executed is `id david`.
26
+ > In this example, our localhost's OS is GNU/Linux (or any other compatible OS) because the command executed is `id obiwan`.
28
27
 
29
- When the user exists, we expect this words: `uid=, (david), gid=`.
28
+ When the user exists, we expect this words: `uid=, (obiwan), gid=`.
30
29
 
31
30
  ```
32
- ❯ id david
33
- uid=1000(david) gid=1000(david) grupos=1000(david)
31
+ ❯ id obiwan
32
+ uid=1000(obiwan) gid=1000(obiwan) grupos=1000(obiwan)
34
33
  ```
35
34
 
36
35
  But when user does not exist, we expect different words: `id:, vader, no exist`.
37
36
 
38
37
  ```
39
38
  ❯ id vader
40
- id: «vader»: no existe ese usuario
39
+ id: «vader»: no such user
40
+
41
+ ❯ echo $?
42
+ 1
43
+
41
44
  ```
42
45
 
43
46
  ## Execution section
@@ -93,32 +96,34 @@ CONFIGURATION
93
96
 
94
97
  GROUPS
95
98
  - Learn about targets
96
- 01 (1.0/1.0)
97
- Description : Create user david
98
- Command : id david
99
+ 01 (0.0/1.0)
100
+ Description : Create user obiwan
101
+ Command : id obiwan
102
+ Output : id: «obiwan»: no existe ese usuario
99
103
  Duration : 0.002 (local)
100
- Alterations : find(uid=) & find((david)) & find(gid=) & count
101
- Expected : Greater than 0 (String)
102
- Result : 1 (Integer)
104
+ Alterations : find(uid=) & find((obiwan)) & find(gid=) & count
105
+ Expected : Greater than 0
106
+ Result : 0
103
107
  02 (1.0/1.0)
104
108
  Description : Delete user vader
105
109
  Command : id vader
110
+ Output : id: «vader»: no existe ese usuario
106
111
  Duration : 0.002 (local)
107
- Alterations : find(id:) & find(vader) & find(no exist) & count
108
- Expected : Greater than 0 (String)
109
- Result : 1 (Integer)
112
+ Alterations : Read exit code
113
+ Expected : Greater than 0
114
+ Result : 1
110
115
 
111
116
  RESULTS
112
117
  +--------------+---------------------------+
113
118
  | case_id | 01 |
114
- | start_time | 2023-04-10 09:09:30 +0100 |
115
- | finish_time | 2023-04-10 09:09:30 +0100 |
116
- | duration | 0.003863242 |
119
+ | start_time | 2023-06-16 08:42:13 +0100 |
120
+ | finish_time | 2023-06-16 08:42:13 +0100 |
121
+ | duration | 0.004527443 |
117
122
  | unique_fault | 0 |
118
123
  | max_weight | 2.0 |
119
- | good_weight | 2.0 |
120
- | fail_weight | 0.0 |
121
- | fail_counter | 0 |
122
- | grade | 100 |
124
+ | good_weight | 1.0 |
125
+ | fail_weight | 1.0 |
126
+ | fail_counter | 1 |
127
+ | grade | 50 |
123
128
  +--------------+---------------------------+
124
129
  ```
@@ -0,0 +1,39 @@
1
+ [<<back](README.md)
2
+
3
+ # expect vs result
4
+
5
+ * `expect` is the statement we use to evaluate the result generated by a previous `run` statement.
6
+ * `result` allows you to manipulate the output of the run command in more detail.
7
+
8
+ `expect` is easier to use but less powerful than `result`.
9
+
10
+ > Example files at [examples/25-expect-result](../../examples/25-expect-result)
11
+
12
+ ## Expect
13
+
14
+ `expect` has different ways to evaluate result.
15
+
16
+ | DSL | Description |
17
+ | ------------------ | ----------- |
18
+ | expect FILTER | it finds lines in the output with the content FILTER |
19
+ | expect_none FILTER | it finds lines in the output without the FILTER content |
20
+ | expect_nothing | is true when the result is empty |
21
+ | expect_exit NUMBER | Exit code is NUMBER |
22
+ | expect_ok | Exit code 0 |
23
+ | expect_fail | Exit code > 0 |
24
+
25
+ > Learn more about [expect](../dsl/expect.md)
26
+
27
+ ## Result
28
+
29
+ `result` is an object that encapsulates the output of the run command and allows manipulation of its contents before being evaluated by `expect`.
30
+
31
+ | Result command | Description |
32
+ | -------------- | ----------- |
33
+ | expect result.count.eq NUMBER | Is true when output has NUMBER lines |
34
+ | expect result.count.gt NUMBER | Is true when output has more than NUMBER lines |
35
+ | expect result.count.lt NUMBER | is true when output has less than NUMBER lines |
36
+ | expect result.grep(FILTER).count.eq NUMBER | output has NUMBER lines with FILTER |
37
+ | expect result.grep_v(FILTER).count.eq NUMBER | output has NUMBER lines without FILTER |
38
+
39
+ > Learn more about [result](../dsl/result.md)