Skip to content

Commit

Permalink
Add rspec tests (#18)
Browse files Browse the repository at this point in the history
* Add data from compliance_markup rspec tests
* Add rspec tests that validate the test data
* Clarify error messages in `check_settings`
* Add rubocop and related gems
* Update rubocop config
* Add rubocop to GitHub Actions
* Clean up for rubocop

Fixes #10
  • Loading branch information
silug authored Oct 7, 2022
1 parent df962c1 commit 9623f62
Show file tree
Hide file tree
Showing 69 changed files with 990 additions and 27 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,26 @@ on:

jobs:

syntax:
runs-on: ubuntu-latest
strategy:
matrix:
ruby:
- '2.6'
- '2.7'
- '3.0'
- '3.1'
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{matrix.ruby}}
bundler-cache: true
- run: bundle exec rubocop

spec:
needs:
- syntax
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down
141 changes: 141 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require:
- rubocop-performance
- rubocop-rspec
- rubocop-rake
AllCops:
DisplayCopNames: true
TargetRubyVersion: '2.7'
Expand Down Expand Up @@ -519,3 +520,143 @@ Style/RedundantArgument:
Enabled: false
Style/SwapValues:
Enabled: false
Gemspec/DeprecatedAttributeAssignment:
Enabled: false
Gemspec/RequireMFA:
Enabled: false
Layout/LineContinuationLeadingSpace:
Enabled: false
Layout/LineContinuationSpacing:
Enabled: false
Layout/LineEndStringConcatenationIndentation:
Enabled: false
Layout/SpaceBeforeBrackets:
Enabled: false
Lint/AmbiguousAssignment:
Enabled: true
Lint/AmbiguousOperatorPrecedence:
Enabled: true
Lint/AmbiguousRange:
Enabled: true
Lint/ConstantOverwrittenInRescue:
Enabled: true
Lint/DeprecatedConstants:
Enabled: true
Lint/EmptyInPattern:
Enabled: true
Lint/IncompatibleIoSelectWithFiberScheduler:
Enabled: true
Lint/LambdaWithoutLiteralBlock:
Enabled: true
Lint/NonAtomicFileOperation:
Enabled: true
Lint/NumberedParameterAssignment:
Enabled: true
Lint/OrAssignmentToConstant:
Enabled: true
Lint/RedundantDirGlobSort:
Enabled: true
Lint/RefinementImportMethods:
Enabled: true
Lint/RequireRangeParentheses:
Enabled: true
Lint/RequireRelativeSelfPath:
Enabled: true
Lint/SymbolConversion:
Enabled: true
Lint/TripleQuotes:
Enabled: true
Lint/UselessRuby2Keywords:
Enabled: true
Naming/BlockForwarding:
Enabled: true
Security/CompoundHash:
Enabled: true
Security/IoMethods:
Enabled: true
Style/EmptyHeredoc:
Enabled: true
Style/EndlessMethod:
Enabled: true
Style/EnvHome:
Enabled: true
Style/FetchEnvVar:
Enabled: true
Style/FileRead:
Enabled: true
Style/FileWrite:
Enabled: true
Style/HashConversion:
Enabled: true
Style/HashExcept:
Enabled: true
Style/IfWithBooleanLiteralBranches:
Enabled: true
Style/InPatternThen:
Enabled: true
Style/MagicCommentFormat:
Enabled: true
Style/MapCompactWithConditionalBlock:
Enabled: true
Style/MapToHash:
Enabled: true
Style/MultilineInPatternThen:
Enabled: true
Style/NestedFileDirname:
Enabled: true
Style/NumberedParameters:
Enabled: true
Style/NumberedParametersLimit:
Enabled: true
Style/ObjectThen:
Enabled: true
Style/OpenStructUse:
Enabled: true
Style/QuotedSymbols:
Enabled: true
Style/RedundantInitialize:
Enabled: true
Style/RedundantSelfAssignmentBranch:
Enabled: true
Style/SelectByRegexp:
Enabled: true
Style/StringChars:
Enabled: true
Performance/ConcurrentMonotonicTime:
Enabled: true
Performance/MapCompact:
Enabled: true
Performance/RedundantEqualityComparisonBlock:
Enabled: true
Performance/RedundantSplitRegexpArgument:
Enabled: true
Performance/StringIdentifierArgument:
Enabled: true
RSpec/BeEq:
Enabled: true
RSpec/BeNil:
Enabled: true
RSpec/ChangeByZero:
Enabled: true
RSpec/ClassCheck:
Enabled: true
RSpec/ExcessiveDocstringSpacing:
Enabled: true
RSpec/IdenticalEqualityAssertion:
Enabled: true
RSpec/NoExpectationExample:
Enabled: true
RSpec/SubjectDeclaration:
Enabled: true
RSpec/VerifiedDoubleReference:
Enabled: true
RSpec/Capybara/SpecificFinders:
Enabled: false
RSpec/Capybara/SpecificMatcher:
Enabled: false
RSpec/FactoryBot/SyntaxMethods:
Enabled: false
RSpec/Rails/AvoidSetupHook:
Enabled: false
RSpec/Rails/HaveHttpStatus:
Enabled: false
9 changes: 8 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,11 @@ source 'https://rubygems.org'
gemspec

gem 'rake', '~> 13.0'
gem 'rspec', '~> 3.11'

group :tests do
gem 'rspec', '~> 3.11'
gem 'rubocop', '~> 1.36'
gem 'rubocop-performance', '~> 1.15'
gem 'rubocop-rspec', '~> 2.13'
gem 'rubocop-rake', '~> 0.6.0'
end
47 changes: 24 additions & 23 deletions exe/scelint
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,29 @@ count = lint.files.count

if count.zero?
warn 'No SCE data found.'
exit 0
end

lint.errors.each do |error|
warn error
end

lint.warnings.each do |warning|
warn warning
end

message = "Checked #{count} files."
if lint.errors.count == 0
message += ' No errors.'
exit_code = 0
else
lint.errors.each do |error|
warn error
end

lint.warnings.each do |warning|
warn warning
end

message = "Checked #{count} files."
if lint.errors.count == 0
message += ' No errors.'
exit_code = 0
else
message += " #{lint.errors.count} errors."
exit_code = 1
end

if lint.warnings.count > 0
message += " #{lint.warnings.count} warnings."
end

puts message
exit exit_code
message += " #{lint.errors.count} errors."
exit_code = 1
end

if lint.warnings.count > 0
message += " #{lint.warnings.count} warnings."
end

puts message
exit exit_code
4 changes: 2 additions & 2 deletions lib/scelint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,13 @@ def check_settings(file, check, data)
if data.key?('parameter')
check_parameter(file, check, data['parameter'])
else
@errors << "#{file} (check '#{check}'): missing parameter"
@errors << "#{file} (check '#{check}'): missing key 'parameter'"
end

if data.key?('value')
check_value(file, check, data['value'])
else
@errors << "#{file} (check '#{check}'): missing parameter"
@errors << "#{file} (check '#{check}'): missing key 'value'"
end

data.each_key do |key|
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
version: 2.0.0
ce:
00_ce1:
controls:
00_control1: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
version: 2.0.0
checks:
00_check1:
type: puppet-class-parameter
settings:
parameter: test_module_00::test_param
value: a string
ces:
- 00_ce1
00_check2:
type: puppet-class-parameter
settings:
parameter: test_module_00::test_param2
value: another string
ces:
- 00_ce1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
version: 2.0.0
profiles:
00_profile_test:
controls:
00_control1: true
00_profile_with_check_reference:
checks:
00_check2: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
version: 2.0.0
ce:
01_ce1:
controls:
01_control1: true
01_ce2:
controls:
01_os_control: true
01_ce3:
controls:
01_control1: true
confine:
module_name: simp-compliance_markup
module_version: "< 3.1.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
version: 2.0.0
checks:
01_el_check:
type: puppet-class-parameter
settings:
parameter: test_module_01::is_el
value: true
ces:
- 01_ce2
confine:
os.family: RedHat
01_el7_check:
type: puppet-class-parameter
settings:
parameter: test_module_01::el_version
value: '7'
ces:
- 01_ce2
confine:
os.name:
- RedHat
- CentOS
os.release.major: '7'
01_confine_in_ces:
type: puppet-class-parameter
settings:
parameter: test_module_01::fixed_confines
value: false
ces:
- 01_ce3
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
version: 2.0.0
profiles:
01_profile_test:
controls:
01_control1: true
01_os_control: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
version: 2.0.0
ce:
02_ce1:
controls:
02_control1: true
Loading

0 comments on commit 9623f62

Please sign in to comment.