From cf3cc15fd56f7e7344813a5225ae5199f389adda Mon Sep 17 00:00:00 2001 From: Bernhard Suttner Date: Sun, 5 May 2019 21:44:41 +0200 Subject: [PATCH] Rubocop fix and test pchanges PR #82 (#96) --- app/services/foreman_salt/report_importer.rb | 2 ++ test/unit/highstate_pchanges.json | 18 ++++++++++++++++++ test/unit/report_importer_test.rb | 10 ++++++++++ 3 files changed, 30 insertions(+) create mode 100644 test/unit/highstate_pchanges.json diff --git a/app/services/foreman_salt/report_importer.rb b/app/services/foreman_salt/report_importer.rb index 9cfe856a..456c2537 100644 --- a/app/services/foreman_salt/report_importer.rb +++ b/app/services/foreman_salt/report_importer.rb @@ -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 @@ -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 diff --git a/test/unit/highstate_pchanges.json b/test/unit/highstate_pchanges.json new file mode 100644 index 00000000..601567e6 --- /dev/null +++ b/test/unit/highstate_pchanges.json @@ -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" + } + } +} diff --git a/test/unit/report_importer_test.rb b/test/unit/report_importer_test.rb index 5035353d..5c07ec71 100644 --- a/test/unit/report_importer_test.rb +++ b/test/unit/report_importer_test.rb @@ -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 @@ -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