Skip to content

Commit cf3cc15

Browse files
authored
Rubocop fix and test pchanges PR #82 (#96)
1 parent 07c09a5 commit cf3cc15

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

app/services/foreman_salt/report_importer.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def import_log_messages
8989
end
9090
end
9191

92+
# rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/AbcSize,Metrics/MethodLength
9293
def calculate_metrics
9394
success = 0
9495
failed = 0
@@ -142,6 +143,7 @@ def calculate_metrics
142143

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

146148
def process_normal
147149
metrics = calculate_metrics

test/unit/highstate_pchanges.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"saltclient713.example.com": {
3+
"file_|-/etc/motd_|-/etc/motd_|-managed": {
4+
"comment": "The file /etc/motd is set to be changed",
5+
"pchanges": {
6+
"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"
7+
},
8+
"name": "/etc/motd",
9+
"start_time": "19:15:44.510229",
10+
"result": null,
11+
"duration": 175.936,
12+
"__run_num__": 0,
13+
"__sls__": "motd",
14+
"changes": {},
15+
"__id__": "/etc/motd"
16+
}
17+
}
18+
}

test/unit/report_importer_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class ReportImporterTest < ActiveSupport::TestCase
77
Setting[:create_new_host_when_facts_are_uploaded] = true
88

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

1112
@host = 'saltclient713.example.com'
1213
end
@@ -37,5 +38,14 @@ class ReportImporterTest < ActiveSupport::TestCase
3738
assert_equal 'pkg_|-postfix_|-postfix_|-installed', report.logs.first.source.value
3839
assert_equal 'Package postfix is already installed.', report.logs.first.message.value
3940
end
41+
42+
test 'report with pchanges has salt origin and expected content' do
43+
ForemanSalt::ReportImporter.import(@report_pchanges)
44+
report = Host.find_by_name(@host).reports.last
45+
status = report.status
46+
assert_equal 'Salt', report.origin
47+
assert_equal 'file_|-/etc/motd_|-/etc/motd_|-managed', report.logs.first.source.value
48+
assert_equal status['pending'], 1
49+
end
4050
end
4151
end

0 commit comments

Comments
 (0)