producer-core 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/features/{actions/echo.feature → action_echo.feature} +1 -1
  3. data/features/{actions/file_append.feature → action_file_append.feature} +1 -1
  4. data/features/{actions/file_replace_content.feature → action_file_replace_content.feature} +11 -14
  5. data/features/{actions/file_write.feature → action_file_write.feature} +7 -12
  6. data/features/{actions/mkdir.feature → action_mkdir.feature} +8 -13
  7. data/features/{actions/sh.feature → action_sh.feature} +14 -14
  8. data/features/{cli/dry_run.feature → cli_dry_run.feature} +0 -0
  9. data/features/{cli/usage.feature → cli_usage.feature} +1 -0
  10. data/features/{cli/verbose.feature → cli_verbose.feature} +12 -23
  11. data/features/{recipes/ask.feature → recipe_ask.feature} +1 -0
  12. data/features/{recipes/macro.feature → recipe_macro.feature} +4 -4
  13. data/features/{recipes/source.feature → recipe_source.feature} +3 -1
  14. data/features/{recipes/target.feature → recipe_target.feature} +3 -1
  15. data/features/recipe_test_macro.feature +52 -0
  16. data/features/{recipes/registry.feature → registry.feature} +9 -4
  17. data/features/{ssh/config.feature → ssh_config.feature} +3 -1
  18. data/features/support/env.rb +32 -0
  19. data/features/support/env_aruba_timeout.rb +3 -0
  20. data/features/{tasks/condition.feature → task_condition.feature} +1 -1
  21. data/features/{tests/dir.feature → test_dir.feature} +1 -1
  22. data/features/{tests/env.feature → test_env.feature} +24 -34
  23. data/features/{tests/executable.feature → test_executable.feature} +12 -14
  24. data/features/{tests/file.feature → test_file.feature} +1 -1
  25. data/features/{tests/file_contains.feature → test_file_contains.feature} +1 -1
  26. data/features/{tests/negated_test.feature → test_negated_test.feature} +0 -0
  27. data/features/test_shell_command_status.feature +48 -0
  28. data/lib/producer/core/cli.rb +19 -15
  29. data/lib/producer/core/condition/dsl.rb +17 -8
  30. data/lib/producer/core/condition.rb +2 -2
  31. data/lib/producer/core/env.rb +6 -10
  32. data/lib/producer/core/errors.rb +2 -1
  33. data/lib/producer/core/recipe/dsl.rb +4 -0
  34. data/lib/producer/core/remote.rb +1 -1
  35. data/lib/producer/core/tests/condition_test.rb +23 -0
  36. data/lib/producer/core/version.rb +1 -1
  37. data/lib/producer/core.rb +1 -0
  38. data/spec/producer/core/cli_spec.rb +73 -44
  39. data/spec/producer/core/condition/dsl_spec.rb +33 -5
  40. data/spec/producer/core/env_spec.rb +41 -36
  41. data/spec/producer/core/recipe/dsl_spec.rb +10 -0
  42. data/spec/producer/core/remote_spec.rb +16 -7
  43. data/spec/producer/core/tests/condition_test_spec.rb +55 -0
  44. metadata +56 -55
  45. data/features/recipes/evaluation.feature +0 -9
  46. data/features/tasks/evaluation.feature +0 -11
  47. data/features/tasks/registry.feature +0 -13
  48. data/features/tests/shell_command_status.feature +0 -58
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 515591ca8ef96ecfcc27483fd7747f2ec8a1f4cb
4
- data.tar.gz: f210d937db08c53613eac2dccdeccac336238791
3
+ metadata.gz: 4895dde05c3db8c7fddcaece8d7f94aa525ff45d
4
+ data.tar.gz: 919123f791a2de0b2364e192c42662de44ec922d
5
5
  SHA512:
6
- metadata.gz: 9b33e1e5cf7c6c2c1f66460b3c10181eb1c8369ef530ca05cb20851ad348ff5b8c297f320190c0db0ffff5257e0c27752593b16f426b4f0a6ad28a43ff9d8c17
7
- data.tar.gz: bf84a175211505298d77f92796952996618721c1c92d15e2168cbcf6842d2b35491d614d5d2500091c9fb3a99a9a341e135085be9beb7b3a753cc1c062ffa304
6
+ metadata.gz: c073aa03b75b67b5b3a0d300820fce5d009c9a245e8c8d7abecc167e02a2f2842628b42d8d40b213e481b4d1824759fc972f139e7fbe7fcbf1d4ab5660418483
7
+ data.tar.gz: 7c5f80f18a7d7b694eb2b3027d678cf79e6b13e015c4f6722ad2a060e5b02c3dbecca418d005f3972b0cfef9eadfce8d6cc79568260d0c26b76ea4e33186106f
@@ -3,7 +3,7 @@ Feature: `echo' task action
3
3
  Scenario: prints text on standard output
4
4
  Given a recipe with:
5
5
  """
6
- task :say_hello do
6
+ task :echo_action do
7
7
  echo 'hello'
8
8
  end
9
9
  """
@@ -9,7 +9,7 @@ Feature: `file_append' task action
9
9
  """
10
10
  target 'some_host.test'
11
11
 
12
- task :append_content_to_file do
12
+ task :file_append_action do
13
13
  file_append 'some_file', ' added'
14
14
  end
15
15
  """
@@ -3,27 +3,24 @@ Feature: `file_replace_content' task action
3
3
 
4
4
  Background:
5
5
  Given a remote file named "some_file" with "some content"
6
-
7
- Scenario: replaces a string by another in the requested file
8
- Given a recipe with:
6
+ And a remote file named "other_file" with "some content"
7
+ And a recipe with:
9
8
  """
10
9
  target 'some_host.test'
11
10
 
12
- task :replace_string_in_file do
11
+ task :file_replace_content_action_string do
13
12
  file_replace_content 'some_file', 'content', 'other content'
14
13
  end
14
+
15
+ task :file_replace_content_action_regexp do
16
+ file_replace_content 'other_file', /\w+\z/, 'other content'
17
+ end
15
18
  """
19
+
20
+ Scenario: replaces a string by another in the requested file
16
21
  When I successfully execute the recipe
17
- And the remote file "some_file" must contain exactly "some other content"
22
+ Then the remote file "some_file" must contain exactly "some other content"
18
23
 
19
24
  Scenario: replaces a regular expression by a string in the requested file
20
- Given a recipe with:
21
- """
22
- target 'some_host.test'
23
-
24
- task :replace_regexp_in_file do
25
- file_replace_content 'some_file', /\w+\z/, 'other content'
26
- end
27
- """
28
25
  When I successfully execute the recipe
29
- And the remote file "some_file" must contain exactly "some other content"
26
+ Then the remote file "other_file" must contain exactly "some other content"
@@ -1,28 +1,23 @@
1
1
  @sshd
2
2
  Feature: `file_write' task action
3
3
 
4
- Scenario: writes given data to given file path
4
+ Background:
5
5
  Given a recipe with:
6
6
  """
7
7
  target 'some_host.test'
8
8
 
9
- task :write_some_data do
10
- file_write 'some_file', 'some_content'
9
+ task :file_write_action do
10
+ file_write 'some_file', 'some_content'
11
+ file_write 'some_file_0600', 'some_content', 0600
12
+ file_write 'some_file_0700', 'some_content', 0700
11
13
  end
12
14
  """
15
+
16
+ Scenario: writes given data to given file path
13
17
  When I successfully execute the recipe
14
18
  Then the remote file "some_file" must contain "some_content"
15
19
 
16
20
  Scenario: creates file with given permissions
17
- Given a recipe with:
18
- """
19
- target 'some_host.test'
20
-
21
- task :write_some_data do
22
- file_write 'some_file_0600', 'some_content', 0600
23
- file_write 'some_file_0700', 'some_content', 0700
24
- end
25
- """
26
21
  When I successfully execute the recipe
27
22
  Then the remote file "some_file_0600" must have 0600 mode
28
23
  And the remote file "some_file_0700" must have 0700 mode
@@ -1,28 +1,23 @@
1
1
  @sshd
2
2
  Feature: `mkdir' task action
3
3
 
4
- Scenario: creates directory given as argument
4
+ Background:
5
5
  Given a recipe with:
6
6
  """
7
7
  target 'some_host.test'
8
8
 
9
- task :create_some_dir do
9
+ task :mkdir_action do
10
10
  mkdir 'some_directory'
11
+ mkdir 'some_directory_0700', 0700
12
+ mkdir 'some_directory_0500', 0500
11
13
  end
12
14
  """
15
+
16
+ Scenario: creates directory given as argument
13
17
  When I successfully execute the recipe
14
18
  Then the remote directory "some_directory" must exists
15
19
 
16
20
  Scenario: creates directory with given permissions
17
- Given a recipe with:
18
- """
19
- target 'some_host.test'
20
-
21
- task :create_some_dir do
22
- mkdir '0700_directory', 0700
23
- mkdir '0500_directory', 0500
24
- end
25
- """
26
21
  When I successfully execute the recipe
27
- Then the remote directory "0700_directory" must have 0700 mode
28
- And the remote directory "0500_directory" must have 0500 mode
22
+ Then the remote directory "some_directory_0700" must have 0700 mode
23
+ And the remote directory "some_directory_0500" must have 0500 mode
@@ -1,24 +1,12 @@
1
1
  @sshd
2
2
  Feature: `sh' task action
3
3
 
4
- Scenario: executes command
5
- Given a recipe with:
6
- """
7
- target 'some_host.test'
8
-
9
- task :some_task do
10
- sh '\true'
11
- end
12
- """
13
- When I execute the recipe
14
- Then the exit status must be 0
15
-
16
4
  Scenario: forwards standard ouput
17
5
  Given a recipe with:
18
6
  """
19
7
  target 'some_host.test'
20
8
 
21
- task :some_task do
9
+ task :sh_action do
22
10
  sh '\echo hello from remote'
23
11
  end
24
12
  """
@@ -30,10 +18,22 @@ Feature: `sh' task action
30
18
  """
31
19
  target 'some_host.test'
32
20
 
33
- task :some_task do
21
+ task :sh_action_aborting do
34
22
  sh '\false'
35
23
  sh '\echo after_fail'
36
24
  end
37
25
  """
38
26
  When I execute the recipe
39
27
  Then the output must not contain "after_fail"
28
+
29
+ Scenario: prints command when execution fail
30
+ Given a recipe with:
31
+ """
32
+ target 'some_host.test'
33
+
34
+ task :sh_action_command_error do
35
+ sh '\false'
36
+ end
37
+ """
38
+ When I execute the recipe
39
+ Then the output must match /\A\w+Error:\s+\\false/
@@ -1,5 +1,6 @@
1
1
  Feature: CLI usage
2
2
 
3
+ @exec
3
4
  Scenario: prints the usage when an argument is missing
4
5
  When I run `producer`
5
6
  Then the exit status must be 64
@@ -1,42 +1,31 @@
1
1
  Feature: CLI verbose option
2
2
 
3
- Scenario: prints tasks name
4
- Given a recipe with:
5
- """
6
- task :say_hello do
7
- end
8
- """
9
- When I successfully execute the recipe with option -v
10
- Then the output must match /Task:.+say_hello/
11
-
12
- Scenario: prints whether condition is met
3
+ Background:
13
4
  Given a recipe with:
14
5
  """
15
6
  task :task_ok do
16
7
  condition { true }
8
+
9
+ echo 'some mesasge'
17
10
  end
11
+
18
12
  task :task_ko do
19
13
  condition { false }
20
14
  end
21
15
  """
16
+
17
+ Scenario: prints tasks name
18
+ When I successfully execute the recipe with option -v
19
+ Then the output must match /Task:.+task_ok/
20
+
21
+ Scenario: prints whether condition is met
22
22
  When I successfully execute the recipe with option -v
23
23
  Then the output must match /task_ok.+ condition: met.*task_ko.* condition: NOT met/
24
24
 
25
25
  Scenario: prints actions info
26
- Given a recipe with:
27
- """
28
- task :say_hello do
29
- echo 'hello message'
30
- end
31
- """
32
26
  When I successfully execute the recipe with option -v
33
- Then the output must match /say_hello.+ action: echo/
27
+ Then the output must match /task_ok.+ action: echo/
34
28
 
35
29
  Scenario: formats message with our simple logger
36
- Given a recipe with:
37
- """
38
- task :say_hello do
39
- end
40
- """
41
30
  When I successfully execute the recipe with option -v
42
- Then the output must match /\ATask:.+say_hello.*\n.*condition/
31
+ Then the output must match /\ATask:.+task_ok.*\n.*condition/
@@ -1,5 +1,6 @@
1
1
  Feature: `ask' recipe keyword
2
2
 
3
+ @exec
3
4
  Scenario: prompts user with a list of choices on standard output
4
5
  Given a recipe with:
5
6
  """
@@ -1,6 +1,6 @@
1
1
  Feature: `macro' recipe keyword
2
2
 
3
- Scenario: declares new keyword accepting task code
3
+ Scenario: declares a new keyword accepting task code
4
4
  Given a recipe with:
5
5
  """
6
6
  macro :hello do
@@ -28,7 +28,7 @@ Feature: `macro' recipe keyword
28
28
  Given a recipe with:
29
29
  """
30
30
  macro :my_echo do |message|
31
- condition { message =~ /bar/ }
31
+ condition { message =~ /foo/ }
32
32
 
33
33
  echo message
34
34
  end
@@ -36,5 +36,5 @@ Feature: `macro' recipe keyword
36
36
  %w[foo bar].each { |e| my_echo e }
37
37
  """
38
38
  When I successfully execute the recipe
39
- Then the output must not contain "foo"
40
- And the output must contain "bar"
39
+ Then the output must contain "foo"
40
+ And the output must not contain "bar"
@@ -9,7 +9,9 @@ Feature: `source' recipe keyword
9
9
  Scenario: requires a recipe file
10
10
  Given a file named "sourced_recipe.rb" with:
11
11
  """
12
- puts 'sourced recipe'
12
+ task :some_task do
13
+ echo 'sourced recipe'
14
+ end
13
15
  """
14
16
  When I successfully execute the recipe
15
17
  Then the output must contain "sourced recipe"
@@ -5,7 +5,9 @@ Feature: `target' recipe keyword
5
5
  """
6
6
  target 'some_host.example'
7
7
 
8
- puts env.target
8
+ task :some_task do
9
+ echo env.target
10
+ end
9
11
  """
10
12
  When I successfully execute the recipe
11
13
  Then the output must contain exactly "some_host.example\n"
@@ -0,0 +1,52 @@
1
+ Feature: `test_macro' recipe keyword
2
+
3
+ Scenario: declares a new test keyword
4
+ Given a recipe with:
5
+ """
6
+ test_macro :even? do |n|
7
+ n % 2 == 0
8
+ end
9
+
10
+ [1, 2].each do |n|
11
+ task "test_macro-even-#{n}" do
12
+ condition { even? n }
13
+ echo n
14
+ end
15
+ end
16
+ """
17
+ When I successfully execute the recipe
18
+ Then the output must contain "2"
19
+ And the output must not contain "1"
20
+
21
+ @sshd
22
+ Scenario: has access to core tests
23
+ Given a recipe with:
24
+ """
25
+ target 'some_host.test'
26
+
27
+ test_macro(:other_env?) { |k| env? k }
28
+
29
+ [:shell, :non_existent_var].each do |k|
30
+ task "test_macro-condition-#{k}" do
31
+ condition { other_env? k }
32
+ echo "#{k}_ok"
33
+ end
34
+ end
35
+ """
36
+ When I successfully execute the recipe
37
+ Then the output must contain "shell_ok"
38
+ Then the output must not contain "non_existent_var_ok"
39
+
40
+ Scenario: has access to other tests declared with `test_macro'
41
+ Given a recipe with:
42
+ """
43
+ test_macro(:one?) { |e| e == 1 }
44
+ test_macro(:one_alias?) { |e| one? e }
45
+
46
+ task :test_macro_macro do
47
+ condition { one_alias? 1 }
48
+ echo 'one_alias_ok'
49
+ end
50
+ """
51
+ When I successfully execute the recipe
52
+ Then the output must contain "one_alias_ok"
@@ -1,21 +1,26 @@
1
1
  Feature: key/value registry
2
2
 
3
- Scenario: `set' keyword registers a value in the registry
3
+ Scenario: `get' keyword in a task fetches a value registered with `set'
4
4
  Given a recipe with:
5
5
  """
6
6
  set :some_key, 'some_value'
7
7
 
8
- puts env.registry[:some_key]
8
+ task :registry_testing do
9
+ echo get :some_key
10
+ end
9
11
  """
10
12
  When I successfully execute the recipe
11
13
  Then the output must contain "some_value"
12
14
 
13
- Scenario: `get' keyword fetches a value from the registry
15
+ Scenario: `get' keyword fetches a value from the recipe
14
16
  Given a recipe with:
15
17
  """
16
18
  set :some_key, 'some_value'
19
+ set :other_key, get(:some_key)
17
20
 
18
- puts get :some_key
21
+ task :registry_testing do
22
+ echo get :other_key
23
+ end
19
24
  """
20
25
  When I successfully execute the recipe
21
26
  Then the output must contain "some_value"
@@ -5,7 +5,9 @@ Feature: SSH settings
5
5
  """
6
6
  target 'some_host.example'
7
7
 
8
- puts env.remote.user_name
8
+ task :some_task do
9
+ echo env.remote.user_name
10
+ end
9
11
  """
10
12
 
11
13
  Scenario: uses current user login name as SSH user name by default
@@ -1,2 +1,34 @@
1
1
  require 'aruba/cucumber'
2
+ require 'aruba/in_process'
2
3
  require 'cucumber/sshd/cucumber'
4
+ require 'producer/core'
5
+
6
+
7
+ class ArubaProgramWrapper
8
+ def initialize(argv, stdin = $stdin, stdout = $stdout, stderr = $stderr,
9
+ kernel = Kernel)
10
+ @argv = argv
11
+ @stdin = stdin
12
+ @stdout = stdout
13
+ @stderr = stderr
14
+ @kernel = kernel
15
+ end
16
+
17
+ def execute!
18
+ Producer::Core::CLI.run!(
19
+ @argv.dup, stdin: @stdin, stdout: @stdout, stderr: @stderr
20
+ )
21
+ rescue SystemExit => e
22
+ @kernel.exit(e.status)
23
+ end
24
+ end
25
+
26
+
27
+ Before('@exec') do
28
+ Aruba.process = Aruba::SpawnProcess
29
+ end
30
+
31
+ Before('~@exec') do
32
+ Aruba::InProcess.main_class = ArubaProgramWrapper
33
+ Aruba.process = Aruba::InProcess
34
+ end