nugrant 2.1.2 → 2.1.4

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 (71) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +23 -23
  3. data/.travis.yml +15 -10
  4. data/CHANGELOG.md +347 -338
  5. data/CONTRIBUTORS.md +7 -5
  6. data/Gemfile +13 -13
  7. data/README.md +601 -601
  8. data/lib/nugrant/bag.rb +264 -264
  9. data/lib/nugrant/config.rb +201 -201
  10. data/lib/nugrant/helper/bag.rb +38 -38
  11. data/lib/nugrant/helper/env/exporter.rb +195 -195
  12. data/lib/nugrant/helper/env/namer.rb +47 -47
  13. data/lib/nugrant/helper/parameters.rb +12 -12
  14. data/lib/nugrant/helper/stack.rb +86 -86
  15. data/lib/nugrant/mixin/parameters.rb +178 -178
  16. data/lib/nugrant/parameters.rb +29 -29
  17. data/lib/nugrant/vagrant/errors.rb +35 -35
  18. data/lib/nugrant/vagrant/v2/action/auto_export.rb +45 -45
  19. data/lib/nugrant/vagrant/v2/action.rb +17 -17
  20. data/lib/nugrant/vagrant/v2/command/env.rb +118 -118
  21. data/lib/nugrant/vagrant/v2/command/parameters.rb +153 -153
  22. data/lib/nugrant/vagrant/v2/command/restricted_keys.rb +64 -64
  23. data/lib/nugrant/vagrant/v2/command/root.rb +95 -95
  24. data/lib/nugrant/vagrant/v2/config/user.rb +29 -29
  25. data/lib/nugrant/vagrant/v2/helper.rb +96 -96
  26. data/lib/nugrant/vagrant/v2/plugin.rb +34 -34
  27. data/lib/nugrant/version.rb +3 -3
  28. data/lib/nugrant.rb +31 -31
  29. data/locales/en.yml +24 -24
  30. data/locales/fr.yml +24 -24
  31. data/nugrant.gemspec +32 -32
  32. data/test/lib/nugrant/helper/env/test_exporter.rb +238 -238
  33. data/test/lib/nugrant/helper/test_bag.rb +16 -16
  34. data/test/lib/nugrant/helper/test_parameters.rb +17 -17
  35. data/test/lib/nugrant/helper/test_stack.rb +152 -152
  36. data/test/lib/nugrant/test_bag.rb +450 -450
  37. data/test/lib/nugrant/test_config.rb +201 -201
  38. data/test/lib/nugrant/test_parameters.rb +438 -438
  39. data/test/lib/test_helper.rb +3 -3
  40. data/test/resources/README.md +52 -52
  41. data/test/resources/json/params_current_1.json +6 -6
  42. data/test/resources/json/params_current_2.json +29 -29
  43. data/test/resources/json/params_user_nil_values.json +9 -9
  44. data/test/resources/vagrantfiles/v2.auto_export +13 -13
  45. data/test/resources/vagrantfiles/v2.bag_inside_array +15 -15
  46. data/test/resources/vagrantfiles/v2.defaults_mixed_string_symbols +18 -18
  47. data/test/resources/vagrantfiles/v2.defaults_null_values_in_vagrantuser +23 -23
  48. data/test/resources/vagrantfiles/v2.defaults_using_string +18 -18
  49. data/test/resources/vagrantfiles/v2.defaults_using_symbol +18 -18
  50. data/test/resources/vagrantfiles/v2.empty +2 -2
  51. data/test/resources/vagrantfiles/v2.fake +29 -29
  52. data/test/resources/vagrantfiles/v2.missing_parameter +3 -3
  53. data/test/resources/vagrantfiles/v2.real +22 -22
  54. data/test/resources/yaml/params_array.yml +5 -5
  55. data/test/resources/yaml/params_boolean.yml +1 -1
  56. data/test/resources/yaml/params_combinations.yml +72 -72
  57. data/test/resources/yaml/params_current_1.yml +4 -4
  58. data/test/resources/yaml/params_current_2.yml +23 -23
  59. data/test/resources/yaml/params_defaults_at_root.yml +1 -1
  60. data/test/resources/yaml/params_defaults_not_at_root.yml +2 -2
  61. data/test/resources/yaml/params_list.yml +2 -2
  62. data/test/resources/yaml/params_numeric_key.yml +3 -3
  63. data/test/resources/yaml/params_simple.yml +1 -1
  64. data/test/resources/yaml/params_system_1.yml +4 -4
  65. data/test/resources/yaml/params_system_2.yml +25 -25
  66. data/test/resources/yaml/params_unix_eol.yml +3 -3
  67. data/test/resources/yaml/params_user_1.yml +4 -4
  68. data/test/resources/yaml/params_user_2.yml +23 -23
  69. data/test/resources/yaml/params_user_nil_values.yml +5 -5
  70. data/test/resources/yaml/params_windows_eol.yml +3 -3
  71. metadata +12 -13
@@ -1,152 +1,152 @@
1
- require 'minitest/autorun'
2
-
3
- require 'nugrant/helper/stack'
4
-
5
- module Nugrant
6
- module Helper
7
- class TestStack < ::Minitest::Test
8
- def create_stack(options = {})
9
- pattern = options[:pattern] || "Vagrantfile:%s"
10
- count = options[:count] || 4
11
-
12
- stack = []
13
- (0..count).each do |index|
14
- stack << pattern.gsub("%s", index.to_s())
15
- end
16
-
17
- stack
18
- end
19
-
20
- def create_location(name, line)
21
- resource_path = File.expand_path("#{File.dirname(__FILE__)}/../../../resources/vagrantfiles")
22
-
23
- {:file => "#{resource_path}/#{name}", :line => line}
24
- end
25
-
26
- def assert_error_location(expected, entry, matcher = nil)
27
- assert_equal(expected, Stack::extract_error_location(entry, :matcher => matcher), "Not exact error location")
28
- end
29
-
30
- def assert_error_region(expected, region)
31
- expected_lines = expected.split("\n")
32
- region_lines = region.split("\n")
33
-
34
- expected_count = expected_lines.length()
35
- actual_count = region_lines.length()
36
-
37
- assert_equal(expected_count, actual_count, "Region different line count")
38
-
39
- expected_lines.each_with_index do |expected_line, index|
40
- assert_equal(expected_line.strip(), region_lines[index].strip(), "Line ##{index} are not equals")
41
- end
42
- end
43
-
44
- def test_fetch_error_region_from_location()
45
- location = create_location("v2.defaults_using_symbol", 4)
46
- error_region = Stack::fetch_error_region_from_location(location)
47
- expected_region = <<-EOT
48
- 1: Vagrant.configure("2") do |config|
49
- 2: config.user.defaults = {
50
- 3: :single => 1,
51
- 4:>> :local => {
52
- 5: :first => "value1",
53
- 6: :second => "value2"
54
- 7: }
55
- 8: }
56
- EOT
57
-
58
- assert_error_region(expected_region, error_region)
59
- end
60
-
61
- def test_fetch_error_region_from_location_custom_prefix()
62
- location = create_location("v2.defaults_using_symbol", 4)
63
- error_region = Stack::fetch_error_region_from_location(location, :prefix => "**")
64
- expected_region = <<-EOT
65
- **1: Vagrant.configure(\"2\") do |config|
66
- **2: config.user.defaults = {
67
- **3: :single => 1,
68
- **4:>> :local => {
69
- **5: :first => "value1",
70
- **6: :second => "value2"
71
- **7: }
72
- **8: }
73
- EOT
74
-
75
- assert_error_region(expected_region, error_region)
76
- end
77
-
78
- def test_fetch_error_region_from_location_custom_width()
79
- location = create_location("v2.defaults_using_symbol", 4)
80
- error_region = Stack::fetch_error_region_from_location(location, :width => 2)
81
- expected_region = <<-EOT
82
- 2: config.user.defaults = {
83
- 3: :single => 1,
84
- 4:>> :local => {
85
- 5: :first => "value1",
86
- 6: :second => "value2"
87
- EOT
88
-
89
- assert_error_region(expected_region, error_region)
90
- end
91
-
92
- def test_fetch_error_region_from_location_wrong_location()
93
- location = {:file => nil, :line => nil}
94
- assert_equal("Unknown", Stack::fetch_error_region_from_location(location))
95
- assert_equal("Failed", Stack::fetch_error_region_from_location(location, :unknown => "Failed"))
96
-
97
- location = {:file => "Vagrantfile", :line => nil}
98
- assert_equal("Vagrantfile", Stack::fetch_error_region_from_location(location))
99
-
100
- location = {:file => "NonExistingVagrantfile", :line => 4}
101
- assert_equal("NonExistingVagrantfile:4", Stack::fetch_error_region_from_location(location))
102
- end
103
-
104
- def test_find_entry()
105
- entries = ["First", "Second:", "Third:a", "Fourth:4"]
106
-
107
- assert_equal("Fourth:4", Stack::find_entry(entries))
108
- assert_equal("Third:a", Stack::find_entry(entries, :matcher => /^(.+):([a-z]+)/))
109
- end
110
-
111
- def test_extract_error_location_default_matcher()
112
- # Matches
113
- assert_error_location({:file => "/work/irb/workspace.rb", :line => 80}, "/work/irb/workspace.rb:80:in `eval'")
114
- assert_error_location({:file => "workspace.rb", :line => 80}, "workspace.rb:80:in `eval'")
115
- assert_error_location({:file => "/work/irb/workspace.rb", :line => 80}, "/work/irb/workspace.rb:80")
116
-
117
- # No match
118
- assert_error_location({:file => nil, :line => nil}, "/work/irb/workspace.rb?80")
119
- assert_error_location({:file => nil, :line => nil}, "/work/irb/workspace.rb")
120
- assert_error_location({:file =>nil, :line => nil}, "")
121
- end
122
-
123
- def test_extract_error_location_custom_matcher()
124
- # Matches
125
- assert_error_location(
126
- {:file => "/work/Vagrantfile", :line => 80},
127
- "/work/Vagrantfile:80:in `eval'",
128
- /(.*Vagrantfile):([0-9]+)/
129
- )
130
-
131
- assert_error_location(
132
- {:file => "Vagrantfile", :line => 80},
133
- "Vagrantfile:80:in `eval'",
134
- /(.*Vagrantfile):([0-9]+)/
135
- )
136
-
137
- assert_error_location(
138
- {:file => "/work/irb/Vagrantfile", :line => 80},
139
- "/work/irb/Vagrantfile:80",
140
- /(.*Vagrantfile):([0-9]+)/
141
- )
142
-
143
- # Partial match
144
- assert_error_location(
145
- {:file => "/work/Vagrantfile", :line => nil},
146
- "/work/Vagrantfile:80:in `eval'",
147
- /(.*Vagrantfile)/
148
- )
149
- end
150
- end
151
- end
152
- end
1
+ require 'minitest/autorun'
2
+
3
+ require 'nugrant/helper/stack'
4
+
5
+ module Nugrant
6
+ module Helper
7
+ class TestStack < ::Minitest::Test
8
+ def create_stack(options = {})
9
+ pattern = options[:pattern] || "Vagrantfile:%s"
10
+ count = options[:count] || 4
11
+
12
+ stack = []
13
+ (0..count).each do |index|
14
+ stack << pattern.gsub("%s", index.to_s())
15
+ end
16
+
17
+ stack
18
+ end
19
+
20
+ def create_location(name, line)
21
+ resource_path = File.expand_path("#{File.dirname(__FILE__)}/../../../resources/vagrantfiles")
22
+
23
+ {:file => "#{resource_path}/#{name}", :line => line}
24
+ end
25
+
26
+ def assert_error_location(expected, entry, matcher = nil)
27
+ assert_equal(expected, Stack::extract_error_location(entry, :matcher => matcher), "Not exact error location")
28
+ end
29
+
30
+ def assert_error_region(expected, region)
31
+ expected_lines = expected.split("\n")
32
+ region_lines = region.split("\n")
33
+
34
+ expected_count = expected_lines.length()
35
+ actual_count = region_lines.length()
36
+
37
+ assert_equal(expected_count, actual_count, "Region different line count")
38
+
39
+ expected_lines.each_with_index do |expected_line, index|
40
+ assert_equal(expected_line.strip(), region_lines[index].strip(), "Line ##{index} are not equals")
41
+ end
42
+ end
43
+
44
+ def test_fetch_error_region_from_location()
45
+ location = create_location("v2.defaults_using_symbol", 4)
46
+ error_region = Stack::fetch_error_region_from_location(location)
47
+ expected_region = <<-EOT
48
+ 1: Vagrant.configure("2") do |config|
49
+ 2: config.user.defaults = {
50
+ 3: :single => 1,
51
+ 4:>> :local => {
52
+ 5: :first => "value1",
53
+ 6: :second => "value2"
54
+ 7: }
55
+ 8: }
56
+ EOT
57
+
58
+ assert_error_region(expected_region, error_region)
59
+ end
60
+
61
+ def test_fetch_error_region_from_location_custom_prefix()
62
+ location = create_location("v2.defaults_using_symbol", 4)
63
+ error_region = Stack::fetch_error_region_from_location(location, :prefix => "**")
64
+ expected_region = <<-EOT
65
+ **1: Vagrant.configure(\"2\") do |config|
66
+ **2: config.user.defaults = {
67
+ **3: :single => 1,
68
+ **4:>> :local => {
69
+ **5: :first => "value1",
70
+ **6: :second => "value2"
71
+ **7: }
72
+ **8: }
73
+ EOT
74
+
75
+ assert_error_region(expected_region, error_region)
76
+ end
77
+
78
+ def test_fetch_error_region_from_location_custom_width()
79
+ location = create_location("v2.defaults_using_symbol", 4)
80
+ error_region = Stack::fetch_error_region_from_location(location, :width => 2)
81
+ expected_region = <<-EOT
82
+ 2: config.user.defaults = {
83
+ 3: :single => 1,
84
+ 4:>> :local => {
85
+ 5: :first => "value1",
86
+ 6: :second => "value2"
87
+ EOT
88
+
89
+ assert_error_region(expected_region, error_region)
90
+ end
91
+
92
+ def test_fetch_error_region_from_location_wrong_location()
93
+ location = {:file => nil, :line => nil}
94
+ assert_equal("Unknown", Stack::fetch_error_region_from_location(location))
95
+ assert_equal("Failed", Stack::fetch_error_region_from_location(location, :unknown => "Failed"))
96
+
97
+ location = {:file => "Vagrantfile", :line => nil}
98
+ assert_equal("Vagrantfile", Stack::fetch_error_region_from_location(location))
99
+
100
+ location = {:file => "NonExistingVagrantfile", :line => 4}
101
+ assert_equal("NonExistingVagrantfile:4", Stack::fetch_error_region_from_location(location))
102
+ end
103
+
104
+ def test_find_entry()
105
+ entries = ["First", "Second:", "Third:a", "Fourth:4"]
106
+
107
+ assert_equal("Fourth:4", Stack::find_entry(entries))
108
+ assert_equal("Third:a", Stack::find_entry(entries, :matcher => /^(.+):([a-z]+)/))
109
+ end
110
+
111
+ def test_extract_error_location_default_matcher()
112
+ # Matches
113
+ assert_error_location({:file => "/work/irb/workspace.rb", :line => 80}, "/work/irb/workspace.rb:80:in `eval'")
114
+ assert_error_location({:file => "workspace.rb", :line => 80}, "workspace.rb:80:in `eval'")
115
+ assert_error_location({:file => "/work/irb/workspace.rb", :line => 80}, "/work/irb/workspace.rb:80")
116
+
117
+ # No match
118
+ assert_error_location({:file => nil, :line => nil}, "/work/irb/workspace.rb?80")
119
+ assert_error_location({:file => nil, :line => nil}, "/work/irb/workspace.rb")
120
+ assert_error_location({:file =>nil, :line => nil}, "")
121
+ end
122
+
123
+ def test_extract_error_location_custom_matcher()
124
+ # Matches
125
+ assert_error_location(
126
+ {:file => "/work/Vagrantfile", :line => 80},
127
+ "/work/Vagrantfile:80:in `eval'",
128
+ /(.*Vagrantfile):([0-9]+)/
129
+ )
130
+
131
+ assert_error_location(
132
+ {:file => "Vagrantfile", :line => 80},
133
+ "Vagrantfile:80:in `eval'",
134
+ /(.*Vagrantfile):([0-9]+)/
135
+ )
136
+
137
+ assert_error_location(
138
+ {:file => "/work/irb/Vagrantfile", :line => 80},
139
+ "/work/irb/Vagrantfile:80",
140
+ /(.*Vagrantfile):([0-9]+)/
141
+ )
142
+
143
+ # Partial match
144
+ assert_error_location(
145
+ {:file => "/work/Vagrantfile", :line => nil},
146
+ "/work/Vagrantfile:80:in `eval'",
147
+ /(.*Vagrantfile)/
148
+ )
149
+ end
150
+ end
151
+ end
152
+ end