puppet-lint-manifest_whitespace-check 0.2.8 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,76 +5,102 @@ require 'spec_helper'
5
5
  describe 'manifest_whitespace_opening_brace_before' do
6
6
  let(:opening_brace_msg) { 'there should be a single space before an opening brace' }
7
7
 
8
+ context 'parameters without space' do
9
+ let(:code) do
10
+ <<~CODE
11
+ $foo = lookup('foo::bar',Hash,'first',{})
12
+ CODE
13
+ end
14
+
15
+ it 'detects a problem' do
16
+ expect(problems).not_to be_empty
17
+ end
18
+ end
19
+
8
20
  context 'with comment only' do
9
21
  let(:code) do
10
- <<~EOF
22
+ <<~CODE
11
23
  $value7 = {
12
24
  # nothing
13
25
  }
14
- EOF
26
+ CODE
27
+ end
28
+
29
+ it 'detects no problems' do
30
+ expect(problems).to be_empty
31
+ end
32
+ end
33
+
34
+ context 'with an iterator' do
35
+ let(:code) do
36
+ <<~CODE
37
+ $slave_ifnames = $bonds.reduce({}) |$l, $i| {
38
+ $l + split($i['attached_devices'], /,/).reduce({}) |$sl, $d| { $sl + { $d => $i['identifier'] } }
39
+ }
40
+ CODE
15
41
  end
16
42
 
17
- it 'should detect no problems' do
43
+ it 'detects no problems' do
18
44
  expect(problems).to be_empty
19
45
  end
20
46
  end
21
47
 
22
48
  context 'inside, inline with function' do
23
49
  let(:code) do
24
- <<~EOF
50
+ <<~CODE
25
51
  $sssd_config = {
26
- 'sssd' => merge($config, {
27
- ▏ ▏ ▏ 'domains' => $domains,
28
- ▏ ▏ ▏ 'services' => 'nss,pam',
29
- }),
52
+ 'sssd' => merge($config, {
53
+ 'domains' => $domains,
54
+ 'services' => 'nss,pam',
55
+ }),
30
56
  }
31
- EOF
57
+ CODE
32
58
  end
33
59
 
34
- it 'should detect no problems' do
60
+ it 'detects no problems' do
35
61
  expect(problems).to be_empty
36
62
  end
37
63
  end
38
64
 
39
65
  context 'inside interpolation' do
40
66
  let(:code) do
41
- <<~EOF
67
+ <<~CODE
42
68
  my_define { "foo-${myvar}": }
43
- EOF
69
+ CODE
44
70
  end
45
71
 
46
- it 'should detect no problems' do
72
+ it 'detects no problems' do
47
73
  expect(problems).to be_empty
48
74
  end
49
75
  end
50
76
 
51
77
  context 'inline with a function before' do
52
78
  let(:code) do
53
- <<~EOF
79
+ <<~CODE
54
80
  Hash( { $key => $return_value })
55
- EOF
81
+ CODE
56
82
  end
57
83
 
58
- it 'should detect 1 problem' do
84
+ it 'detects 1 problem' do
59
85
  expect(problems).to have(1).problem
60
86
  end
61
87
  end
62
88
 
63
89
  context 'inline with a function' do
64
90
  let(:code) do
65
- <<~EOF
91
+ <<~CODE
66
92
  Hash({ $key => $return_value })
67
- EOF
93
+ CODE
68
94
  end
69
95
 
70
- it 'should detect no problems' do
96
+ it 'detects no problems' do
71
97
  expect(problems).to be_empty
72
98
  end
73
99
  end
74
100
 
75
101
  context 'inside a function' do
76
102
  let(:code) do
77
- <<~EOF
103
+ <<~CODE
78
104
  $my_var = lookup(
79
105
  {
80
106
  'name' => 'my_module::my_var',
@@ -83,44 +109,44 @@ describe 'manifest_whitespace_opening_brace_before' do
83
109
  'default_value' => [],
84
110
  }
85
111
  )
86
- EOF
112
+ CODE
87
113
  end
88
114
 
89
- it 'should detect no problems' do
115
+ it 'detects no problems' do
90
116
  expect(problems).to be_empty
91
117
  end
92
118
  end
93
119
 
94
120
  context 'with cases' do
95
121
  let(:code) do
96
- <<~EOF
122
+ <<~CODE
97
123
  case $facts['kernel'] {
98
124
  'OpenBSD': { $has_wordexp = false }
99
125
  default: { $has_wordexp = true }
100
126
  }
101
- EOF
127
+ CODE
102
128
  end
103
129
 
104
- it 'should detect no problems' do
130
+ it 'detects no problems' do
105
131
  expect(problems).to be_empty
106
132
  end
107
133
  end
108
134
 
109
135
  context 'with class no spaces' do
110
136
  let(:code) do
111
- <<~EOF
137
+ <<~CODE
112
138
  class example{
113
139
  # some generic comment
114
140
  }
115
- EOF
141
+ CODE
116
142
  end
117
143
 
118
144
  context 'with fix disabled' do
119
- it 'should detect a problem' do
145
+ it 'detects a problem' do
120
146
  expect(problems).to have(1).problem
121
147
  end
122
148
 
123
- it 'should create a error' do
149
+ it 'creates a error' do
124
150
  expect(problems).to contain_error(opening_brace_msg).on_line(1).in_column(14)
125
151
  end
126
152
  end
@@ -134,13 +160,13 @@ describe 'manifest_whitespace_opening_brace_before' do
134
160
  PuppetLint.configuration.fix = false
135
161
  end
136
162
 
137
- it 'should add a space' do
163
+ it 'adds a space' do
138
164
  expect(manifest).to eq(
139
- <<~EOF,
165
+ <<~CODE,
140
166
  class example {
141
167
  # some generic comment
142
168
  }
143
- EOF
169
+ CODE
144
170
  )
145
171
  end
146
172
  end
@@ -148,7 +174,7 @@ describe 'manifest_whitespace_opening_brace_before' do
148
174
 
149
175
  context 'with no spaces' do
150
176
  let(:code) do
151
- <<~EOF
177
+ <<~CODE
152
178
  # example
153
179
  #
154
180
  # Main class, includes all other classes.
@@ -181,15 +207,15 @@ describe 'manifest_whitespace_opening_brace_before' do
181
207
  }
182
208
  }
183
209
  }
184
- EOF
210
+ CODE
185
211
  end
186
212
 
187
213
  context 'with fix disabled' do
188
- it 'should detect three problems' do
214
+ it 'detects three problems' do
189
215
  expect(problems).to have(3).problem
190
216
  end
191
217
 
192
- it 'should create a error' do
218
+ it 'creates a error' do
193
219
  expect(problems).to contain_error(opening_brace_msg).on_line(8).in_column(2)
194
220
  end
195
221
  end
@@ -203,17 +229,17 @@ describe 'manifest_whitespace_opening_brace_before' do
203
229
  PuppetLint.configuration.fix = false
204
230
  end
205
231
 
206
- it 'should detect three problems' do
232
+ it 'detects three problems' do
207
233
  expect(problems).to have(3).problem
208
234
  end
209
235
 
210
- it 'should create a error' do
236
+ it 'creates a error' do
211
237
  expect(problems).to contain_fixed(opening_brace_msg)
212
238
  end
213
239
 
214
- it 'should add spaces' do
240
+ it 'adds spaces' do
215
241
  expect(manifest).to eq(
216
- <<~EOF,
242
+ <<~CODE,
217
243
  # example
218
244
  #
219
245
  # Main class, includes all other classes.
@@ -246,7 +272,7 @@ describe 'manifest_whitespace_opening_brace_before' do
246
272
  }
247
273
  }
248
274
  }
249
- EOF
275
+ CODE
250
276
  )
251
277
  end
252
278
  end
@@ -254,7 +280,7 @@ describe 'manifest_whitespace_opening_brace_before' do
254
280
 
255
281
  context 'with two spaces' do
256
282
  let(:code) do
257
- <<~EOF
283
+ <<~CODE
258
284
  # example
259
285
  #
260
286
  # Main class, includes all other classes.
@@ -281,15 +307,15 @@ describe 'manifest_whitespace_opening_brace_before' do
281
307
  }
282
308
  }
283
309
  }
284
- EOF
310
+ CODE
285
311
  end
286
312
 
287
313
  context 'with fix disabled' do
288
- it 'should detect a single problem' do
314
+ it 'detects a single problem' do
289
315
  expect(problems).to have(3).problem
290
316
  end
291
317
 
292
- it 'should create a error' do
318
+ it 'creates a error' do
293
319
  expect(problems).to contain_error(opening_brace_msg).on_line(8).in_column(4)
294
320
  end
295
321
  end
@@ -303,17 +329,17 @@ describe 'manifest_whitespace_opening_brace_before' do
303
329
  PuppetLint.configuration.fix = false
304
330
  end
305
331
 
306
- it 'should detect a single problem' do
332
+ it 'detects a single problem' do
307
333
  expect(problems).to have(3).problem
308
334
  end
309
335
 
310
- it 'should create a error' do
336
+ it 'creates a error' do
311
337
  expect(problems).to contain_fixed(opening_brace_msg)
312
338
  end
313
339
 
314
- it 'should remove a space' do
340
+ it 'removes a space' do
315
341
  expect(manifest).to eq(
316
- <<~EOF,
342
+ <<~CODE,
317
343
  # example
318
344
  #
319
345
  # Main class, includes all other classes.
@@ -340,7 +366,7 @@ describe 'manifest_whitespace_opening_brace_before' do
340
366
  }
341
367
  }
342
368
  }
343
- EOF
369
+ CODE
344
370
  )
345
371
  end
346
372
  end
@@ -348,7 +374,7 @@ describe 'manifest_whitespace_opening_brace_before' do
348
374
 
349
375
  context 'with newline' do
350
376
  let(:code) do
351
- <<~EOF
377
+ <<~CODE
352
378
  # example
353
379
  #
354
380
  # Main class, includes all other classes.
@@ -378,15 +404,15 @@ describe 'manifest_whitespace_opening_brace_before' do
378
404
  }
379
405
  }
380
406
  }
381
- EOF
407
+ CODE
382
408
  end
383
409
 
384
410
  context 'with fix disabled' do
385
- it 'should detect a single problem' do
411
+ it 'detects a single problem' do
386
412
  expect(problems).to have(3).problem
387
413
  end
388
414
 
389
- it 'should create a error' do
415
+ it 'creates a error' do
390
416
  expect(problems).to contain_error(opening_brace_msg).on_line(9).in_column(1)
391
417
  end
392
418
  end
@@ -400,17 +426,17 @@ describe 'manifest_whitespace_opening_brace_before' do
400
426
  PuppetLint.configuration.fix = false
401
427
  end
402
428
 
403
- it 'should detect a single problem' do
429
+ it 'detects a single problem' do
404
430
  expect(problems).to have(3).problem
405
431
  end
406
432
 
407
- it 'should create a error' do
433
+ it 'creates a error' do
408
434
  expect(problems).to contain_fixed(opening_brace_msg)
409
435
  end
410
436
 
411
- it 'should fix the newline' do
437
+ it 'fixes the newline' do
412
438
  expect(manifest).to eq(
413
- <<~EOF,
439
+ <<~CODE,
414
440
  # example
415
441
  #
416
442
  # Main class, includes all other classes.
@@ -437,7 +463,7 @@ describe 'manifest_whitespace_opening_brace_before' do
437
463
  }
438
464
  }
439
465
  }
440
- EOF
466
+ CODE
441
467
  )
442
468
  end
443
469
  end
@@ -445,7 +471,7 @@ describe 'manifest_whitespace_opening_brace_before' do
445
471
 
446
472
  context 'with comment' do
447
473
  let(:code) do
448
- <<~EOF
474
+ <<~CODE
449
475
  # example
450
476
  #
451
477
  # Main class, includes all other classes.
@@ -474,11 +500,11 @@ describe 'manifest_whitespace_opening_brace_before' do
474
500
  }
475
501
  }
476
502
  }
477
- EOF
503
+ CODE
478
504
  end
479
505
 
480
506
  context 'with fix disabled' do
481
- it 'should detect a single problem' do
507
+ it 'detects a single problem' do
482
508
  expect(problems).to be_empty
483
509
  end
484
510
  end
@@ -486,7 +512,7 @@ describe 'manifest_whitespace_opening_brace_before' do
486
512
 
487
513
  context 'with good inherits' do
488
514
  let(:code) do
489
- <<~EOF
515
+ <<~CODE
490
516
  # example
491
517
  #
492
518
  # Main class, includes all other classes.
@@ -513,11 +539,11 @@ describe 'manifest_whitespace_opening_brace_before' do
513
539
  }
514
540
  }
515
541
  }
516
- EOF
542
+ CODE
517
543
  end
518
544
 
519
545
  context 'with fix disabled' do
520
- it 'should detect no problem' do
546
+ it 'detects no problem' do
521
547
  expect(problems).to be_empty
522
548
  end
523
549
  end
@@ -525,7 +551,7 @@ describe 'manifest_whitespace_opening_brace_before' do
525
551
 
526
552
  context 'with bad inherits' do
527
553
  let(:code) do
528
- <<~EOF
554
+ <<~CODE
529
555
  # example
530
556
  #
531
557
  # Main class, includes all other classes.
@@ -552,15 +578,15 @@ describe 'manifest_whitespace_opening_brace_before' do
552
578
  }
553
579
  }
554
580
  }
555
- EOF
581
+ CODE
556
582
  end
557
583
 
558
584
  context 'with fix disabled' do
559
- it 'should detect a single problem' do
585
+ it 'detects a single problem' do
560
586
  expect(problems).to have(1).problem
561
587
  end
562
588
 
563
- it 'should create a error' do
589
+ it 'creates a error' do
564
590
  expect(problems).to contain_error(opening_brace_msg).on_line(8).in_column(22)
565
591
  end
566
592
  end
@@ -574,13 +600,13 @@ describe 'manifest_whitespace_opening_brace_before' do
574
600
  PuppetLint.configuration.fix = false
575
601
  end
576
602
 
577
- it 'should detect a missing space' do
603
+ it 'detects a missing space' do
578
604
  expect(problems).to have(1).problem
579
605
  end
580
606
 
581
- it 'should add the space' do
607
+ it 'adds the space' do
582
608
  expect(manifest).to eq(
583
- <<~EOF,
609
+ <<~CODE,
584
610
  # example
585
611
  #
586
612
  # Main class, includes all other classes.
@@ -607,7 +633,7 @@ describe 'manifest_whitespace_opening_brace_before' do
607
633
  }
608
634
  }
609
635
  }
610
- EOF
636
+ CODE
611
637
  )
612
638
  end
613
639
  end
@@ -619,7 +645,7 @@ describe 'manifest_whitespace_opening_brace_after' do
619
645
 
620
646
  context 'with two spaces' do
621
647
  let(:code) do
622
- <<~EOF
648
+ <<~CODE
623
649
  # example
624
650
  #
625
651
  # Main class, includes all other classes.
@@ -652,15 +678,15 @@ describe 'manifest_whitespace_opening_brace_after' do
652
678
  }
653
679
  }
654
680
  }
655
- EOF
681
+ CODE
656
682
  end
657
683
 
658
684
  context 'with fix disabled' do
659
- it 'should detect 2 problems' do
685
+ it 'detects 2 problems' do
660
686
  expect(problems).to have(2).problem
661
687
  end
662
688
 
663
- it 'should create a error' do
689
+ it 'creates a error' do
664
690
  expect(problems).to contain_error(opening_brace_msg).on_line(9).in_column(14)
665
691
  end
666
692
  end
@@ -674,17 +700,17 @@ describe 'manifest_whitespace_opening_brace_after' do
674
700
  PuppetLint.configuration.fix = false
675
701
  end
676
702
 
677
- it 'should detect 2 problems' do
703
+ it 'detects 2 problems' do
678
704
  expect(problems).to have(2).problem
679
705
  end
680
706
 
681
- it 'should create a error' do
707
+ it 'creates a error' do
682
708
  expect(problems).to contain_fixed(opening_brace_msg)
683
709
  end
684
710
 
685
- it 'should add spaces' do
711
+ it 'adds spaces' do
686
712
  expect(manifest).to eq(
687
- <<~EOF,
713
+ <<~CODE,
688
714
  # example
689
715
  #
690
716
  # Main class, includes all other classes.
@@ -717,7 +743,7 @@ describe 'manifest_whitespace_opening_brace_after' do
717
743
  }
718
744
  }
719
745
  }
720
- EOF
746
+ CODE
721
747
  )
722
748
  end
723
749
  end
@@ -725,7 +751,7 @@ describe 'manifest_whitespace_opening_brace_after' do
725
751
 
726
752
  context 'with no spaces' do
727
753
  let(:code) do
728
- <<~EOF
754
+ <<~CODE
729
755
  # example
730
756
  #
731
757
  # Main class, includes all other classes.
@@ -752,15 +778,15 @@ describe 'manifest_whitespace_opening_brace_after' do
752
778
  }
753
779
  }
754
780
  }
755
- EOF
781
+ CODE
756
782
  end
757
783
 
758
784
  context 'with fix disabled' do
759
- it 'should detect 2 problems' do
785
+ it 'detects 2 problems' do
760
786
  expect(problems).to have(2).problem
761
787
  end
762
788
 
763
- it 'should create a error' do
789
+ it 'creates a error' do
764
790
  expect(problems).to contain_error(opening_brace_msg).on_line(9).in_column(14)
765
791
  end
766
792
  end
@@ -774,17 +800,17 @@ describe 'manifest_whitespace_opening_brace_after' do
774
800
  PuppetLint.configuration.fix = false
775
801
  end
776
802
 
777
- it 'should detect 2 problems' do
803
+ it 'detects 2 problems' do
778
804
  expect(problems).to have(2).problem
779
805
  end
780
806
 
781
- it 'should create a error' do
807
+ it 'creates a error' do
782
808
  expect(problems).to contain_fixed(opening_brace_msg)
783
809
  end
784
810
 
785
- it 'should add spaces' do
811
+ it 'adds spaces' do
786
812
  expect(manifest).to eq(
787
- <<~EOF,
813
+ <<~CODE,
788
814
  # example
789
815
  #
790
816
  # Main class, includes all other classes.
@@ -811,7 +837,7 @@ describe 'manifest_whitespace_opening_brace_after' do
811
837
  }
812
838
  }
813
839
  }
814
- EOF
840
+ CODE
815
841
  )
816
842
  end
817
843
  end
@@ -819,7 +845,7 @@ describe 'manifest_whitespace_opening_brace_after' do
819
845
 
820
846
  context 'with two newlines' do
821
847
  let(:code) do
822
- <<~EOF
848
+ <<~CODE
823
849
  # example
824
850
  #
825
851
  # Main class, includes all other classes.
@@ -851,15 +877,15 @@ describe 'manifest_whitespace_opening_brace_after' do
851
877
  }
852
878
  }
853
879
  }
854
- EOF
880
+ CODE
855
881
  end
856
882
 
857
883
  context 'with fix disabled' do
858
- it 'should detect 4 problems' do
884
+ it 'detects 4 problems' do
859
885
  expect(problems).to have(4).problem
860
886
  end
861
887
 
862
- it 'should create a error' do
888
+ it 'creates a error' do
863
889
  expect(problems).to contain_error(opening_brace_msg).on_line(9).in_column(1)
864
890
  end
865
891
  end
@@ -873,17 +899,17 @@ describe 'manifest_whitespace_opening_brace_after' do
873
899
  PuppetLint.configuration.fix = false
874
900
  end
875
901
 
876
- it 'should detect 4 problems' do
902
+ it 'detects 4 problems' do
877
903
  expect(problems).to have(4).problem
878
904
  end
879
905
 
880
- it 'should create a error' do
906
+ it 'creates a error' do
881
907
  expect(problems).to contain_fixed(opening_brace_msg)
882
908
  end
883
909
 
884
- it 'should add spaces' do
910
+ it 'adds spaces' do
885
911
  expect(manifest).to eq(
886
- <<~EOF,
912
+ <<~CODE,
887
913
  # example
888
914
  #
889
915
  # Main class, includes all other classes.
@@ -911,7 +937,7 @@ describe 'manifest_whitespace_opening_brace_after' do
911
937
  }
912
938
  }
913
939
  }
914
- EOF
940
+ CODE
915
941
  )
916
942
  end
917
943
  end