Skip to content

Commit

Permalink
Rubocop fix and test pchanges PR #82 (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernhard authored May 5, 2019
1 parent 07c09a5 commit cf3cc15
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/services/foreman_salt/report_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def import_log_messages
end
end

# rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/AbcSize,Metrics/MethodLength
def calculate_metrics
success = 0
failed = 0
Expand Down Expand Up @@ -142,6 +143,7 @@ def calculate_metrics

{ :events => events, :resources => resources, :changes => changes, :time => time }
end
# rubocop:enable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/AbcSize,Metrics/MethodLength

def process_normal
metrics = calculate_metrics
Expand Down
18 changes: 18 additions & 0 deletions test/unit/highstate_pchanges.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"saltclient713.example.com": {
"file_|-/etc/motd_|-/etc/motd_|-managed": {
"comment": "The file /etc/motd is set to be changed",
"pchanges": {
"diff": "--- \n+++ \n@@ -8,7 +8,7 @@\n Kernel: 4.12.14-23-default\n Memory: 1986 MB\n \n-The server is managed using a configuration management system (saltstack.org).\n+This server is managed using a configuration management system (saltstack.org).\n Changes made to this box directly will likely be over-written by SALT. Instead\n modify server configuration via the configuration management git repository.\n ------------------------------------------------------------------------------\n"
},
"name": "/etc/motd",
"start_time": "19:15:44.510229",
"result": null,
"duration": 175.936,
"__run_num__": 0,
"__sls__": "motd",
"changes": {},
"__id__": "/etc/motd"
}
}
}
10 changes: 10 additions & 0 deletions test/unit/report_importer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class ReportImporterTest < ActiveSupport::TestCase
Setting[:create_new_host_when_facts_are_uploaded] = true

@report = JSON.parse(File.read(File.join(Engine.root, 'test', 'unit', 'highstate.json')))
@report_pchanges = JSON.parse(File.read(File.join(Engine.root, 'test', 'unit', 'highstate_pchanges.json')))

@host = 'saltclient713.example.com'
end
Expand Down Expand Up @@ -37,5 +38,14 @@ class ReportImporterTest < ActiveSupport::TestCase
assert_equal 'pkg_|-postfix_|-postfix_|-installed', report.logs.first.source.value
assert_equal 'Package postfix is already installed.', report.logs.first.message.value
end

test 'report with pchanges has salt origin and expected content' do
ForemanSalt::ReportImporter.import(@report_pchanges)
report = Host.find_by_name(@host).reports.last
status = report.status
assert_equal 'Salt', report.origin
assert_equal 'file_|-/etc/motd_|-/etc/motd_|-managed', report.logs.first.source.value
assert_equal status['pending'], 1
end
end
end

0 comments on commit cf3cc15

Please sign in to comment.