chef-attribute-validator 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +20 -0
  3. data/CHANGES +4 -0
  4. data/Gemfile +2 -0
  5. data/LICENSE +27 -0
  6. data/README.md +109 -0
  7. data/Rakefile +27 -0
  8. data/chef-attribute-validator.gemspec +25 -0
  9. data/lib/chef-attribute-validator.rb +52 -0
  10. data/lib/chef-attribute-validator/attribute_set.rb +90 -0
  11. data/lib/chef-attribute-validator/check.rb +56 -0
  12. data/lib/chef-attribute-validator/checks/looks_like.rb +52 -0
  13. data/lib/chef-attribute-validator/checks/max_children.rb +37 -0
  14. data/lib/chef-attribute-validator/checks/min_children.rb +37 -0
  15. data/lib/chef-attribute-validator/checks/regex.rb +31 -0
  16. data/lib/chef-attribute-validator/checks/required.rb +42 -0
  17. data/lib/chef-attribute-validator/checks/type.rb +48 -0
  18. data/lib/chef-attribute-validator/rule.rb +54 -0
  19. data/lib/chef-attribute-validator/version.rb +7 -0
  20. data/lib/chef-attribute-validator/violation.rb +17 -0
  21. data/test/fixtures/attr_set.rb +10 -0
  22. data/test/fixtures/check_child_count.rb +104 -0
  23. data/test/fixtures/check_looks_like_arg_ip.rb +6 -0
  24. data/test/fixtures/check_looks_like_arg_regex.rb +6 -0
  25. data/test/fixtures/check_looks_like_arg_url.rb +6 -0
  26. data/test/fixtures/check_looks_like_arg_your_mom.rb +6 -0
  27. data/test/fixtures/check_looks_like_ip.rb +57 -0
  28. data/test/fixtures/check_looks_like_url.rb +39 -0
  29. data/test/fixtures/check_regex_assorted.rb +42 -0
  30. data/test/fixtures/check_regex_literal.rb +5 -0
  31. data/test/fixtures/check_regex_nil.rb +5 -0
  32. data/test/fixtures/check_regex_object.rb +5 -0
  33. data/test/fixtures/check_regex_string.rb +5 -0
  34. data/test/fixtures/check_required_assorted.rb +82 -0
  35. data/test/fixtures/check_required_false.rb +5 -0
  36. data/test/fixtures/check_required_true.rb +5 -0
  37. data/test/fixtures/check_required_zero.rb +5 -0
  38. data/test/fixtures/check_type.rb +270 -0
  39. data/test/fixtures/rules_empty.rb +2 -0
  40. data/test/fixtures/rules_missing_path.rb +1 -0
  41. data/test/fixtures/rules_no_check.rb +1 -0
  42. data/test/fixtures/rules_type_and_min_children.rb +3 -0
  43. data/test/fixtures/rules_type_check.rb +2 -0
  44. data/test/unit/attr_set_spec.rb +55 -0
  45. data/test/unit/check_child_count_spec.rb +109 -0
  46. data/test/unit/check_looks_like_spec.rb +106 -0
  47. data/test/unit/check_regex_spec.rb +62 -0
  48. data/test/unit/check_required_spec.rb +106 -0
  49. data/test/unit/check_type_spec.rb +191 -0
  50. data/test/unit/rule_parse_spec.rb +93 -0
  51. data/test/unit/spec_helper.rb +18 -0
  52. metadata +170 -0
@@ -0,0 +1,39 @@
1
+
2
+ default['nil'] = nil
3
+
4
+ default['http']['basic'] = 'http://wwwwwwww.jodi.org'
5
+ default['http']['trailing-slash'] = 'http://example.com/'
6
+ default['http']['port'] = 'http://example.com:8080/'
7
+ default['http']['localhost'] = 'http://localhost'
8
+
9
+ rules = default['attribute-validator']['rules']
10
+ rules['url-missing'] = {
11
+ 'path' => '/nope',
12
+ 'looks_like' => 'url',
13
+ }
14
+
15
+ rules['url-nil'] = {
16
+ 'path' => '/nil',
17
+ 'looks_like' => 'url',
18
+ }
19
+
20
+ rules['url-http-basic'] = {
21
+ 'path' => '/http/basic',
22
+ 'looks_like' => 'url',
23
+ }
24
+
25
+ rules['url-http-trailing-slash'] = {
26
+ 'path' => '/http/trailing-slash',
27
+ 'looks_like' => 'url',
28
+ }
29
+
30
+ rules['url-http-port'] = {
31
+ 'path' => '/http/port',
32
+ 'looks_like' => 'url',
33
+ }
34
+ rules['url-http-localhost'] = {
35
+ 'path' => '/http/localhost',
36
+ 'looks_like' => 'url',
37
+ }
38
+
39
+
@@ -0,0 +1,42 @@
1
+
2
+
3
+ default['empty'] = ''
4
+ default['foo'] = 'foo'
5
+ default['bar'] = 'bar'
6
+ default['chow'] = 'food'
7
+ default['vittles'] = 'victuals'
8
+
9
+
10
+ rules = default['attribute-validator']['rules']
11
+
12
+ rules['empty-empty'] = {
13
+ 'path' => '/empty',
14
+ 'regex' => /^$/,
15
+ }
16
+
17
+ rules['foo-foo'] = {
18
+ 'path' => '/foo',
19
+ 'regex' => /foo/,
20
+ }
21
+
22
+ rules['foo-food'] = {
23
+ 'path' => '/chow',
24
+ 'regex' => /foo/,
25
+ }
26
+
27
+ rules['foo-victuals'] = {
28
+ 'path' => '/vittles',
29
+ 'regex' => /foo/,
30
+ }
31
+
32
+ rules['not-foo-bar'] = {
33
+ 'path' => '/bar',
34
+ 'regex' => /^(?!foo)/,
35
+ }
36
+
37
+ rules['not-foo-foo'] = {
38
+ 'path' => '/foo',
39
+ 'regex' => /^(?!foo)/,
40
+ }
41
+
42
+
@@ -0,0 +1,5 @@
1
+ rules = default['attribute-validator']['rules']
2
+ rules['check-regex-literal'] = {
3
+ 'path' => '/feh',
4
+ 'regex' => /foo/,
5
+ }
@@ -0,0 +1,5 @@
1
+ rules = default['attribute-validator']['rules']
2
+ rules['check-regex-nil'] = {
3
+ 'path' => '/feh',
4
+ 'regex' => nil,
5
+ }
@@ -0,0 +1,5 @@
1
+ rules = default['attribute-validator']['rules']
2
+ rules['check-regex-object'] = {
3
+ 'path' => '/feh',
4
+ 'regex' => Regexp.new('foo')
5
+ }
@@ -0,0 +1,5 @@
1
+ rules = default['attribute-validator']['rules']
2
+ rules['check-regex-string-valid'] = {
3
+ 'path' => '/feh',
4
+ 'regex' => 'foo\d{3}.+',
5
+ }
@@ -0,0 +1,82 @@
1
+
2
+ default['yep']['what'] = 'missed me'
3
+ default['nil'] = nil
4
+
5
+ default['empty']['string'] = ""
6
+ default['empty']['array'] = []
7
+ default['empty']['hash'] = {}
8
+
9
+ default['present']['string'] = 'foo'
10
+ default['present']['zero'] = 0
11
+ default['present']['false'] = false
12
+ default['present']['array'] = [ 'a' ]
13
+ default['present']['hash'] = { 'a' => 'b' }
14
+
15
+
16
+
17
+ rules = default['attribute-validator']['rules']
18
+ rules['missing-shallow'] = {
19
+ 'path' => '/nope',
20
+ 'required' => true,
21
+ }
22
+
23
+ rules['missing-deep'] = {
24
+ 'path' => '/yep/nope',
25
+ 'required' => true,
26
+ }
27
+
28
+ rules['value-nil'] = {
29
+ 'path' => '/nil',
30
+ 'required' => true,
31
+ }
32
+
33
+ rules['value-empty-string'] = {
34
+ 'path' => '/empty/string',
35
+ 'required' => true,
36
+ }
37
+
38
+ rules['value-empty-array'] = {
39
+ 'path' => '/empty/array',
40
+ 'required' => true,
41
+ }
42
+
43
+ rules['value-empty-hash'] = {
44
+ 'path' => '/empty/hash',
45
+ 'required' => true,
46
+ }
47
+
48
+ rules['value-present-string'] = {
49
+ 'path' => '/present/string',
50
+ 'required' => true,
51
+ }
52
+
53
+ rules['value-present-false'] = {
54
+ 'path' => '/present/false',
55
+ 'required' => true,
56
+ }
57
+
58
+ rules['value-present-zero'] = {
59
+ 'path' => '/present/zero',
60
+ 'required' => true,
61
+ }
62
+
63
+ rules['value-present-array'] = {
64
+ 'path' => '/present/array',
65
+ 'required' => true,
66
+ }
67
+
68
+ rules['value-present-hash'] = {
69
+ 'path' => '/present/hash',
70
+ 'required' => true,
71
+ }
72
+
73
+ rules['optional-present-string'] = {
74
+ 'path' => '/present/string',
75
+ 'required' => false,
76
+ }
77
+
78
+ rules['optional-missing'] = {
79
+ 'path' => '/nope',
80
+ 'required' => false,
81
+ }
82
+
@@ -0,0 +1,5 @@
1
+ rules = default['attribute-validator']['rules']
2
+ rules['check-required_false'] = {
3
+ 'path' => '/feh',
4
+ 'required' => false,
5
+ }
@@ -0,0 +1,5 @@
1
+ rules = default['attribute-validator']['rules']
2
+ rules['check-required_true'] = {
3
+ 'path' => '/feh',
4
+ 'required' => true,
5
+ }
@@ -0,0 +1,5 @@
1
+ rules = default['attribute-validator']['rules']
2
+ rules['check-required_zero'] = {
3
+ 'path' => '/feh',
4
+ 'required' => 0,
5
+ }
@@ -0,0 +1,270 @@
1
+
2
+ rules = default['attribute-validator']['rules']
3
+
4
+
5
+ default['empty'] = ""
6
+ default['foo'] = "foo"
7
+ default['number'] = 42
8
+ default['number-as-string'] = "42"
9
+ default['98point6'] = 98.6
10
+ default['zero'] = 0
11
+ default['one'] = 1
12
+ default['nil'] = nil
13
+ default['array'] = [ 'a', 'b' ]
14
+ default['hash'] = { 'a' => 'b' }
15
+ default['false'] = false
16
+ default['true'] = true
17
+ default['false-as-string'] = 'false'
18
+ default['true-as-string'] = 'true'
19
+
20
+ default['array-as-string'] = '[1,2,3,4]'
21
+ default['array-empty'] = []
22
+ default['array-incr1'] = []
23
+ default['array-incr1'] = [ 'apples' ]
24
+ default['array-incr1'] = [ 'bananas' ]
25
+
26
+ default['array-incr2'] = [ ]
27
+ default['array-incr2'][0] = "kodos"
28
+ default['array-incr2'][1] = "kang"
29
+
30
+ default['array-incr3'] = [ ]
31
+ default['array-incr3'] = [ { 'lisa' => 'clobbergirl' } ]
32
+ default['array-incr3'] = [ { 'bart' => 'stretchboy' } ]
33
+
34
+ default['hash-as-string'] = '{"foo" => "bar" }'
35
+ default['hash-empty'] = {}
36
+
37
+ default['hash-incr1'] = {}
38
+ default['hash-incr1'] = { 'monday' => 'garfield hates them' }
39
+ default['hash-incr1'] = { 'wednesday' => 'favorite of the camel' }
40
+
41
+ default['hash-incr2']['zed'] = 'is dead'
42
+ default['hash-incr2']['butch'] = 'LA privileges revoked'
43
+
44
+ default['hash-incr3'] = {
45
+ 'this' => {
46
+ 'that' => "th'other"
47
+ }
48
+ }
49
+
50
+ #===================================================#
51
+ # String
52
+ #===================================================#
53
+ rules['string-empty'] = {
54
+ 'path' => '/empty',
55
+ 'type' => 'string',
56
+ }
57
+
58
+ rules['string-nil'] = {
59
+ 'path' => '/nil',
60
+ 'type' => 'string',
61
+ }
62
+
63
+ rules['string-foo'] = {
64
+ 'path' => '/foo',
65
+ 'type' => 'string',
66
+ }
67
+
68
+ rules['string-number'] = {
69
+ 'path' => '/number',
70
+ 'type' => 'string',
71
+ }
72
+
73
+ rules['string-array'] = {
74
+ 'path' => '/array',
75
+ 'type' => 'string',
76
+ }
77
+
78
+ rules['string-hash'] = {
79
+ 'path' => '/hash',
80
+ 'type' => 'string',
81
+ }
82
+
83
+ #===================================================#
84
+ # Number
85
+ #===================================================#
86
+ rules['number-zero'] = {
87
+ 'path' => '/zero',
88
+ 'type' => 'number',
89
+ }
90
+
91
+ rules['number-nil'] = {
92
+ 'path' => '/nil',
93
+ 'type' => 'number',
94
+ }
95
+
96
+ rules['number-42'] = {
97
+ 'path' => '/number',
98
+ 'type' => 'number',
99
+ }
100
+
101
+ rules['number-98point6'] = {
102
+ 'path' => '/98point6',
103
+ 'type' => 'number',
104
+ }
105
+
106
+ rules['number-as-string'] = {
107
+ 'path' => '/number-as-string',
108
+ 'type' => 'number',
109
+ }
110
+
111
+ rules['number-array'] = {
112
+ 'path' => '/array',
113
+ 'type' => 'number',
114
+ }
115
+
116
+ rules['number-hash'] = {
117
+ 'path' => '/hash',
118
+ 'type' => 'number',
119
+ }
120
+
121
+ #===================================================#
122
+ # Boolean
123
+ #===================================================#
124
+
125
+ rules['boolean-empty'] = {
126
+ 'path' => '/empty',
127
+ 'type' => 'boolean',
128
+ }
129
+
130
+ rules['boolean-zero'] = {
131
+ 'path' => '/zero',
132
+ 'type' => 'boolean',
133
+ }
134
+
135
+ rules['boolean-one'] = {
136
+ 'path' => '/one',
137
+ 'type' => 'boolean',
138
+ }
139
+
140
+ rules['boolean-nil'] = {
141
+ 'path' => '/nil',
142
+ 'type' => 'boolean',
143
+ }
144
+
145
+ rules['boolean-true'] = {
146
+ 'path' => '/true',
147
+ 'type' => 'boolean',
148
+ }
149
+
150
+ rules['boolean-false'] = {
151
+ 'path' => '/false',
152
+ 'type' => 'boolean',
153
+ }
154
+
155
+ rules['boolean-true-as-string'] = {
156
+ 'path' => '/true-as-string',
157
+ 'type' => 'boolean',
158
+ }
159
+
160
+ rules['boolean-false-as-string'] = {
161
+ 'path' => '/false-as-string',
162
+ 'type' => 'boolean',
163
+ }
164
+
165
+ rules['boolean-array'] = {
166
+ 'path' => '/array',
167
+ 'type' => 'boolean',
168
+ }
169
+
170
+ rules['boolean-hash'] = {
171
+ 'path' => '/hash',
172
+ 'type' => 'boolean',
173
+ }
174
+
175
+ #===================================================#
176
+ # Array
177
+ #===================================================#
178
+ rules['array-empty'] = {
179
+ 'path' => '/array-empty',
180
+ 'type' => 'array',
181
+ }
182
+
183
+ rules['array-literal'] = {
184
+ 'path' => '/array',
185
+ 'type' => 'array',
186
+ }
187
+
188
+ rules['array-incremental-simple'] = {
189
+ 'path' => '/array-incr1',
190
+ 'type' => 'array',
191
+ }
192
+
193
+ rules['array-incremental-indexed'] = {
194
+ 'path' => '/array-incr2',
195
+ 'type' => 'array',
196
+ }
197
+
198
+ rules['array-incremental-deep'] = {
199
+ 'path' => '/array-incr3',
200
+ 'type' => 'array',
201
+ }
202
+
203
+ rules['array-nil'] = {
204
+ 'path' => '/nil',
205
+ 'type' => 'array',
206
+ }
207
+
208
+ rules['array-zero'] = {
209
+ 'path' => '/zero',
210
+ 'type' => 'array',
211
+ }
212
+
213
+ rules['array-as-string'] = {
214
+ 'path' => '/array-as-string',
215
+ 'type' => 'array',
216
+ }
217
+
218
+ rules['array-hash'] = {
219
+ 'path' => '/hash',
220
+ 'type' => 'array',
221
+ }
222
+
223
+ #===================================================#
224
+ # Hash
225
+ #===================================================#
226
+ rules['hash-empty'] = {
227
+ 'path' => '/hash-empty',
228
+ 'type' => 'hash',
229
+ }
230
+
231
+ rules['hash-literal'] = {
232
+ 'path' => '/hash',
233
+ 'type' => 'hash',
234
+ }
235
+
236
+ rules['hash-incremental-simple'] = {
237
+ 'path' => '/hash-incr1',
238
+ 'type' => 'hash',
239
+ }
240
+
241
+ rules['hash-incremental-indexed'] = {
242
+ 'path' => '/hash-incr2',
243
+ 'type' => 'hash',
244
+ }
245
+
246
+ rules['hash-incremental-deep'] = {
247
+ 'path' => '/hash-incr3',
248
+ 'type' => 'hash',
249
+ }
250
+
251
+ rules['hash-nil'] = {
252
+ 'path' => '/nil',
253
+ 'type' => 'hash',
254
+ }
255
+
256
+ rules['hash-zero'] = {
257
+ 'path' => '/zero',
258
+ 'type' => 'hash',
259
+ }
260
+
261
+ rules['hash-as-string'] = {
262
+ 'path' => '/hash-as-string',
263
+ 'type' => 'hash',
264
+ }
265
+
266
+ rules['hash-array'] = {
267
+ 'path' => '/array',
268
+ 'type' => 'hash',
269
+ }
270
+