hammer_cli_foreman 2.1.2 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/doc/release_notes.md +35 -4
- data/doc/testing.md +13 -0
- data/lib/hammer_cli_foreman.rb +0 -4
- data/lib/hammer_cli_foreman/architecture.rb +5 -5
- data/lib/hammer_cli_foreman/associating_commands.rb +4 -5
- data/lib/hammer_cli_foreman/auth.rb +4 -4
- data/lib/hammer_cli_foreman/bookmark.rb +6 -6
- data/lib/hammer_cli_foreman/command_extensions/ping.rb +10 -1
- data/lib/hammer_cli_foreman/command_extensions/status.rb +1 -1
- data/lib/hammer_cli_foreman/commands.rb +3 -1
- data/lib/hammer_cli_foreman/compute_profile.rb +5 -5
- data/lib/hammer_cli_foreman/compute_resource/ovirt.rb +1 -0
- data/lib/hammer_cli_foreman/config_group.rb +5 -5
- data/lib/hammer_cli_foreman/host.rb +3 -2
- data/lib/hammer_cli_foreman/hosts/common_update_options.rb +17 -10
- data/lib/hammer_cli_foreman/location.rb +2 -0
- data/lib/hammer_cli_foreman/mail_notification.rb +2 -2
- data/lib/hammer_cli_foreman/model.rb +5 -5
- data/lib/hammer_cli_foreman/operating_system.rb +10 -9
- data/lib/hammer_cli_foreman/organization.rb +2 -0
- data/lib/hammer_cli_foreman/output/fields.rb +1 -1
- data/lib/hammer_cli_foreman/output/formatters.rb +1 -1
- data/lib/hammer_cli_foreman/ping.rb +20 -11
- data/lib/hammer_cli_foreman/references.rb +16 -0
- data/lib/hammer_cli_foreman/settings.rb +16 -2
- data/lib/hammer_cli_foreman/testing/api_expectations.rb +10 -0
- data/lib/hammer_cli_foreman/usergroup.rb +5 -5
- data/lib/hammer_cli_foreman/version.rb +1 -1
- data/lib/minitest/coverage_reporter.rb +94 -0
- data/lib/minitest/hammer_coverage_plugin.rb +19 -0
- data/locale/ca/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/test/functional/architecture_test.rb +49 -0
- data/test/functional/audit_test.rb +86 -63
- data/test/functional/bookmark_test.rb +20 -0
- data/test/functional/commands/list_test.rb +11 -11
- data/test/functional/compute_profile_test.rb +47 -2
- data/test/functional/config_group_test.rb +50 -0
- data/test/functional/filter_test.rb +114 -47
- data/test/functional/host_test.rb +105 -19
- data/test/functional/location_test.rb +134 -0
- data/test/functional/mail_notification_test.rb +20 -0
- data/test/functional/media_test.rb +130 -0
- data/test/functional/model_test.rb +50 -0
- data/test/functional/operating_system_test.rb +51 -0
- data/test/functional/organization_test.rb +52 -0
- data/test/functional/realm_test.rb +103 -0
- data/test/functional/role_test.rb +9 -12
- data/test/functional/settings_test.rb +78 -1
- data/test/functional/status_test.rb +79 -13
- data/test/functional/user_test.rb +39 -0
- data/test/functional/usergroup_test.rb +51 -0
- data/test/test_helper.rb +5 -2
- data/test/unit/api/interactive_basic_auth_test.rb +3 -1
- data/test/unit/api/oauth/oauth_authentication_code_grant_test.rb +2 -2
- data/test/unit/api/oauth/oauth_password_grant_test.rb +2 -2
- data/test/unit/api_test.rb +3 -4
- data/test/unit/apipie_resource_mock.rb +25 -4
- data/test/unit/architecture_test.rb +10 -1
- data/test/unit/bookmark_test.rb +99 -0
- data/test/unit/commands_test.rb +19 -19
- data/test/unit/common_parameter_test.rb +1 -1
- data/test/unit/compute_profile_test.rb +87 -0
- data/test/unit/config_group_test.rb +10 -0
- data/test/unit/dependency_resolver_test.rb +4 -4
- data/test/unit/exception_handler_test.rb +13 -13
- data/test/unit/helpers/command.rb +5 -5
- data/test/unit/helpers/resource_disabled.rb +2 -2
- data/test/unit/host_test.rb +1 -24
- data/test/unit/id_resolver_test.rb +23 -23
- data/test/unit/mail_notification_test.rb +53 -0
- data/test/unit/media_test.rb +1 -1
- data/test/unit/model_test.rb +10 -0
- data/test/unit/operating_system_test.rb +14 -1
- data/test/unit/option_builders_test.rb +49 -49
- data/test/unit/option_sources/id_params_test.rb +2 -2
- data/test/unit/option_sources/ids_params_test.rb +2 -2
- data/test/unit/output/formatters_test.rb +21 -21
- data/test/unit/param_filters_test.rb +17 -17
- data/test/unit/partition_table_test.rb +2 -2
- data/test/unit/role_test.rb +2 -2
- data/test/unit/sessions_test.rb +24 -24
- data/test/unit/settings_test.rb +4 -0
- data/test/unit/template_test.rb +1 -1
- data/test/unit/usergroup_test.rb +10 -0
- metadata +26 -7
- data/lib/hammer_cli_foreman/trend.rb +0 -47
- data/test/functional/trend_test.rb +0 -22
|
@@ -33,7 +33,9 @@ module HammerCLIForeman
|
|
|
33
33
|
HammerCLIForeman::References.compute_resources(self)
|
|
34
34
|
HammerCLIForeman::References.media(self)
|
|
35
35
|
HammerCLIForeman::References.provisioning_templates(self)
|
|
36
|
+
HammerCLIForeman::References.partition_tables(self)
|
|
36
37
|
HammerCLIForeman::References.domains(self)
|
|
38
|
+
HammerCLIForeman::References.realms(self)
|
|
37
39
|
HammerCLIForeman::References.environments(self)
|
|
38
40
|
HammerCLIForeman::References.hostgroups(self)
|
|
39
41
|
HammerCLIForeman::References.parameters(self)
|
|
@@ -11,7 +11,7 @@ module HammerCLIForeman
|
|
|
11
11
|
field :name, _("Name")
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
build_options
|
|
14
|
+
build_options expand: { except: %i[organizations locations] }, without: %i[organization_id location_id]
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
class InfoCommand < HammerCLIForeman::InfoCommand
|
|
@@ -22,7 +22,7 @@ module HammerCLIForeman
|
|
|
22
22
|
field :subscription_type, _("Subscription type")
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
build_options
|
|
25
|
+
build_options expand: { except: %i[organizations locations] }, without: %i[organization_id location_id]
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
autoload_subcommands
|
|
@@ -13,7 +13,7 @@ module HammerCLIForeman
|
|
|
13
13
|
field :hardware_model, _("HW model")
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
build_options
|
|
16
|
+
build_options expand: { except: %i[organizations locations] }, without: %i[organization_id location_id]
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
|
|
@@ -23,7 +23,7 @@ module HammerCLIForeman
|
|
|
23
23
|
HammerCLIForeman::References.timestamps(self)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
build_options
|
|
26
|
+
build_options expand: { except: %i[organizations locations] }, without: %i[organization_id location_id]
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
|
|
@@ -31,14 +31,14 @@ module HammerCLIForeman
|
|
|
31
31
|
success_message _("Hardware model created.")
|
|
32
32
|
failure_message _("Could not create the hardware model")
|
|
33
33
|
|
|
34
|
-
build_options
|
|
34
|
+
build_options expand: { except: %i[organizations locations] }, without: %i[organization_id location_id]
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
class DeleteCommand < HammerCLIForeman::DeleteCommand
|
|
38
38
|
success_message _("Hardware model deleted.")
|
|
39
39
|
failure_message _("Could not delete the hardware model")
|
|
40
40
|
|
|
41
|
-
build_options
|
|
41
|
+
build_options expand: { except: %i[organizations locations] }, without: %i[organization_id location_id]
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
|
|
@@ -46,7 +46,7 @@ module HammerCLIForeman
|
|
|
46
46
|
success_message _("Hardware model updated.")
|
|
47
47
|
failure_message _("Could not update the hardware model")
|
|
48
48
|
|
|
49
|
-
build_options
|
|
49
|
+
build_options expand: { except: %i[organizations locations] }, without: %i[organization_id location_id]
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
|
|
@@ -13,7 +13,7 @@ module HammerCLIForeman
|
|
|
13
13
|
field :family, _("Family")
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
build_options
|
|
16
|
+
build_options expand: { except: %i[organizations locations] }, without: %i[organization_id location_id]
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
|
|
@@ -36,7 +36,7 @@ module HammerCLIForeman
|
|
|
36
36
|
HammerCLIForeman::References.parameters(self)
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
build_options
|
|
39
|
+
build_options expand: { except: %i[organizations locations] }, without: %i[organization_id location_id]
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
|
|
@@ -44,7 +44,7 @@ module HammerCLIForeman
|
|
|
44
44
|
success_message _("Operating system created.")
|
|
45
45
|
failure_message _("Could not create the operating system")
|
|
46
46
|
|
|
47
|
-
build_options
|
|
47
|
+
build_options expand: { except: %i[organizations locations] }, without: %i[organization_id location_id]
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
|
|
@@ -52,7 +52,7 @@ module HammerCLIForeman
|
|
|
52
52
|
success_message _("Operating system updated.")
|
|
53
53
|
failure_message _("Could not update the operating system")
|
|
54
54
|
|
|
55
|
-
build_options
|
|
55
|
+
build_options expand: { except: %i[organizations locations] }, without: %i[organization_id location_id]
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
|
|
@@ -60,7 +60,7 @@ module HammerCLIForeman
|
|
|
60
60
|
success_message _("Operating system deleted.")
|
|
61
61
|
failure_message _("Could not delete the operating system")
|
|
62
62
|
|
|
63
|
-
build_options
|
|
63
|
+
build_options expand: { except: %i[organizations locations] }, without: %i[organization_id location_id]
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
|
|
@@ -76,7 +76,7 @@ module HammerCLIForeman
|
|
|
76
76
|
validator.any(:option_operatingsystem_id, :option_operatingsystem_title).required
|
|
77
77
|
end
|
|
78
78
|
|
|
79
|
-
build_options
|
|
79
|
+
build_options expand: { except: %i[organizations locations] }, without: %i[organization_id location_id]
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
|
|
@@ -90,7 +90,7 @@ module HammerCLIForeman
|
|
|
90
90
|
validator.any(:option_operatingsystem_id, :option_operatingsystem_title).required
|
|
91
91
|
end
|
|
92
92
|
|
|
93
|
-
build_options
|
|
93
|
+
build_options expand: { except: %i[organizations locations] }, without: %i[organization_id location_id]
|
|
94
94
|
end
|
|
95
95
|
|
|
96
96
|
|
|
@@ -156,7 +156,8 @@ module HammerCLIForeman
|
|
|
156
156
|
HammerCLI::EX_OK
|
|
157
157
|
end
|
|
158
158
|
|
|
159
|
-
build_options :
|
|
159
|
+
build_options expand: { except: %i[organizations locations] },
|
|
160
|
+
without: %i[organization_id location_id template_kind_id type]
|
|
160
161
|
end
|
|
161
162
|
|
|
162
163
|
|
|
@@ -191,7 +192,7 @@ module HammerCLIForeman
|
|
|
191
192
|
{"operatingsystem_id" => option_id}
|
|
192
193
|
end
|
|
193
194
|
|
|
194
|
-
build_options
|
|
195
|
+
build_options expand: { except: %i[organizations locations] }, without: %i[organization_id location_id]
|
|
195
196
|
end
|
|
196
197
|
|
|
197
198
|
|
|
@@ -33,7 +33,9 @@ module HammerCLIForeman
|
|
|
33
33
|
HammerCLIForeman::References.compute_resources(self)
|
|
34
34
|
HammerCLIForeman::References.media(self)
|
|
35
35
|
HammerCLIForeman::References.provisioning_templates(self)
|
|
36
|
+
HammerCLIForeman::References.partition_tables(self)
|
|
36
37
|
HammerCLIForeman::References.domains(self)
|
|
38
|
+
HammerCLIForeman::References.realms(self)
|
|
37
39
|
HammerCLIForeman::References.environments(self)
|
|
38
40
|
HammerCLIForeman::References.hostgroups(self)
|
|
39
41
|
HammerCLIForeman::References.parameters(self)
|
|
@@ -35,7 +35,7 @@ module HammerCLIForeman::Output
|
|
|
35
35
|
if detail.is_a?(Hash)
|
|
36
36
|
next if detail[:id] && !show_ids
|
|
37
37
|
if detail[:label]
|
|
38
|
-
"#{detail[:label]}: #{get_value(data, detail[:key])}"
|
|
38
|
+
"#{detail[:label][:target]}: #{get_value(data, detail[:key])}"
|
|
39
39
|
else
|
|
40
40
|
get_value(data, detail[:key])
|
|
41
41
|
end
|
|
@@ -1,23 +1,32 @@
|
|
|
1
1
|
module HammerCLIForeman
|
|
2
2
|
class PingCommand < HammerCLIForeman::Command
|
|
3
|
-
|
|
3
|
+
resource :ping
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
class ForemanCommand < HammerCLIForeman::Command
|
|
6
|
+
action :ping
|
|
7
|
+
command_name 'foreman'
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
end
|
|
9
|
+
output do
|
|
10
|
+
from 'foreman' do
|
|
11
|
+
field :database, _('database'), Fields::Label do
|
|
12
|
+
field :active, _('Status')
|
|
13
|
+
field :duration_ms, _('Server Response')
|
|
15
14
|
end
|
|
16
15
|
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def execute
|
|
19
|
+
response = send_request
|
|
20
|
+
print_data(response)
|
|
17
21
|
|
|
18
|
-
|
|
22
|
+
return 1 if HammerCLIForeman::CommandExtensions::Ping.failed?(response)
|
|
23
|
+
|
|
24
|
+
HammerCLI::EX_OK
|
|
19
25
|
end
|
|
20
26
|
|
|
27
|
+
extend_with(HammerCLIForeman::CommandExtensions::Ping.new)
|
|
28
|
+
end
|
|
29
|
+
|
|
21
30
|
self.default_subcommand = 'foreman'
|
|
22
31
|
autoload_subcommands
|
|
23
32
|
end
|
|
@@ -88,6 +88,14 @@ module HammerCLIForeman
|
|
|
88
88
|
end
|
|
89
89
|
end
|
|
90
90
|
|
|
91
|
+
def self.partition_tables(dsl)
|
|
92
|
+
dsl.build do
|
|
93
|
+
collection :ptables, _("Partition Tables"), :numbered => false do
|
|
94
|
+
custom_field Fields::Reference
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
91
99
|
def self.domains(dsl)
|
|
92
100
|
dsl.build do
|
|
93
101
|
collection :domains, _("Domains"), :numbered => false do
|
|
@@ -96,6 +104,14 @@ module HammerCLIForeman
|
|
|
96
104
|
end
|
|
97
105
|
end
|
|
98
106
|
|
|
107
|
+
def self.realms(dsl)
|
|
108
|
+
dsl.build do
|
|
109
|
+
collection :realms, _("Realms"), :numbered => false do
|
|
110
|
+
custom_field Fields::Reference
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
99
115
|
def self.environments(dsl)
|
|
100
116
|
dsl.build do
|
|
101
117
|
collection :environments, _("Environments"), :numbered => false do
|
|
@@ -20,7 +20,7 @@ module HammerCLIForeman
|
|
|
20
20
|
data
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
build_options
|
|
23
|
+
build_options expand: { except: %i[organizations locations] }, without: %i[organization_id location_id]
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
class UpdateCommand < HammerCLIForeman::UpdateCommand
|
|
@@ -29,9 +29,23 @@ module HammerCLIForeman
|
|
|
29
29
|
success_message _("Setting [%{name}] updated to [%{value}].")
|
|
30
30
|
failure_message _("Could not update the setting")
|
|
31
31
|
|
|
32
|
-
build_options
|
|
32
|
+
build_options expand: { except: %i[organizations locations] }, without: %i[organization_id location_id]
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
+
class InfoCommand < HammerCLIForeman::InfoCommand
|
|
36
|
+
output do
|
|
37
|
+
field :id, _("Id")
|
|
38
|
+
field :name, _("Name")
|
|
39
|
+
field :description, _("Description")
|
|
40
|
+
field :category_name, _("Category")
|
|
41
|
+
field :settings_type, _("Settings type")
|
|
42
|
+
field :value, _("Value")
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
build_options expand: { except: %i[organizations locations] }, without: %i[organization_id location_id]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
|
|
35
49
|
autoload_subcommands
|
|
36
50
|
end
|
|
37
51
|
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
module HammerCLIForeman
|
|
2
2
|
module Testing
|
|
3
3
|
module APIExpectations
|
|
4
|
+
|
|
5
|
+
def self.api_calls
|
|
6
|
+
@api_calls ||= []
|
|
7
|
+
end
|
|
8
|
+
|
|
4
9
|
class APICallMatcher < Mocha::ParameterMatchers::Base
|
|
5
10
|
attr_accessor :expected_params, :expected_resource, :expected_action, :block
|
|
6
11
|
|
|
@@ -160,7 +165,12 @@ module HammerCLIForeman
|
|
|
160
165
|
}.merge(options))
|
|
161
166
|
end
|
|
162
167
|
|
|
168
|
+
def api_calls
|
|
169
|
+
HammerCLIForeman::Testing::APIExpectations.api_calls
|
|
170
|
+
end
|
|
171
|
+
|
|
163
172
|
def api_expects(resource=nil, action=nil, note=nil, &block)
|
|
173
|
+
api_calls << [resource, action]
|
|
164
174
|
APIExpectationsDecorator.new.expects_call(resource, action, note, &block)
|
|
165
175
|
end
|
|
166
176
|
|
|
@@ -13,7 +13,7 @@ module HammerCLIForeman
|
|
|
13
13
|
field :admin, _("Admin"), Fields::Boolean
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
build_options
|
|
16
|
+
build_options expand: { except: %i[organizations locations] }, without: %i[organization_id location_id]
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
class InfoCommand < HammerCLIForeman::InfoCommand
|
|
@@ -25,28 +25,28 @@ module HammerCLIForeman
|
|
|
25
25
|
HammerCLIForeman::References.timestamps(self)
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
build_options
|
|
28
|
+
build_options expand: { except: %i[organizations locations] }, without: %i[organization_id location_id]
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
class CreateCommand < HammerCLIForeman::CreateCommand
|
|
32
32
|
success_message _("User group [%<name>s] created.")
|
|
33
33
|
failure_message _("Could not create the user group")
|
|
34
34
|
|
|
35
|
-
build_options
|
|
35
|
+
build_options expand: { except: %i[organizations locations] }, without: %i[organization_id location_id]
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
class UpdateCommand < HammerCLIForeman::UpdateCommand
|
|
39
39
|
success_message _("User group [%<name>s] updated.")
|
|
40
40
|
failure_message _("Could not update the user group")
|
|
41
41
|
|
|
42
|
-
build_options
|
|
42
|
+
build_options expand: { except: %i[organizations locations] }, without: %i[organization_id location_id]
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
class DeleteCommand < HammerCLIForeman::DeleteCommand
|
|
46
46
|
success_message _("User group [%<name>s] deleted.")
|
|
47
47
|
failure_message _("Could not delete the user group")
|
|
48
48
|
|
|
49
|
-
build_options
|
|
49
|
+
build_options expand: { except: %i[organizations locations] }, without: %i[organization_id location_id]
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
HammerCLIForeman::AssociatingCommands::Role.extend_command(self)
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
module Minitest
|
|
4
|
+
class CoverageRunner
|
|
5
|
+
|
|
6
|
+
RESOURCE_BLACK_LIST = ['tasks','home','config_groups','statistics','table_preferences','autosign','puppet_hosts']
|
|
7
|
+
attr_reader :raw_data, :api_endpoints, :covered_resources, :uncovered_resources, :partially_covered_resources
|
|
8
|
+
def initialize(file_path)
|
|
9
|
+
@raw_data = JSON.load(File.open(file_path))
|
|
10
|
+
@api_endpoints = {}
|
|
11
|
+
@covered_resources = []
|
|
12
|
+
@uncovered_resources = []
|
|
13
|
+
@partially_covered_resources = {}
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def filtered_endpoints(covered)
|
|
17
|
+
api_endpoints.select { |_k, v| v == covered }.keys
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def get_endpoints_by_resource(endpoints)
|
|
21
|
+
endpoints_by_resource = {}
|
|
22
|
+
endpoints.each do |url|
|
|
23
|
+
resource,action = url.split("/")
|
|
24
|
+
endpoints_by_resource[resource] ||= []
|
|
25
|
+
endpoints_by_resource[resource] << action
|
|
26
|
+
end
|
|
27
|
+
endpoints_by_resource
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def uncovered_endpoints_by_resource
|
|
31
|
+
get_endpoints_by_resource(filtered_endpoints(false))
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def covered_endpoints_by_resource
|
|
35
|
+
get_endpoints_by_resource(filtered_endpoints(true))
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def get_coverage
|
|
39
|
+
get_endpoints_by_resource(api_endpoints.keys).each do |resource, actions|
|
|
40
|
+
if covered_endpoints_by_resource[resource] == actions
|
|
41
|
+
@covered_resources << resource
|
|
42
|
+
elsif uncovered_endpoints_by_resource[resource] == actions
|
|
43
|
+
@uncovered_resources << resource
|
|
44
|
+
else
|
|
45
|
+
@partially_covered_resources[resource] = uncovered_endpoints_by_resource[resource]
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def endpoints_percentage(endpoints)
|
|
51
|
+
"#{(endpoints.count / api_endpoints.count.to_f * 100 ).to_i}%"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def uncovered_endpoints_percentage
|
|
55
|
+
endpoints_percentage(filtered_endpoints(false))
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def covered_endpoints_percentage
|
|
59
|
+
endpoints_percentage(filtered_endpoints(true))
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def run_tests
|
|
63
|
+
raw_data["docs"]["resources"].each do |resource|
|
|
64
|
+
resource[1]["methods"].each do | method |
|
|
65
|
+
@api_endpoints[method["doc_url"].delete_prefix!("../apidoc/v2/")] = false
|
|
66
|
+
end unless RESOURCE_BLACK_LIST.include? resource[0]
|
|
67
|
+
end
|
|
68
|
+
HammerCLIForeman::Testing::APIExpectations.api_calls.each do |api_call|
|
|
69
|
+
resource, action = api_call
|
|
70
|
+
url = "#{resource}/#{action}"
|
|
71
|
+
@api_endpoints[url] = true
|
|
72
|
+
end
|
|
73
|
+
get_coverage
|
|
74
|
+
output_coverage
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def color(str, code)
|
|
78
|
+
puts "\e[#{code}m#{str}\e[0m"
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def output_coverage
|
|
82
|
+
covered_resources
|
|
83
|
+
color("COVERED RESOURCES" , 32)
|
|
84
|
+
puts covered_resources
|
|
85
|
+
color("NOT COVERED AT ALL", 31)
|
|
86
|
+
puts uncovered_resources
|
|
87
|
+
color("PARTIALLY COVERED RESOURCES", 33)
|
|
88
|
+
partially_covered_resources.each do |resource, endpoints|
|
|
89
|
+
puts "#{resource}: #{endpoints.join(' ')}"
|
|
90
|
+
end
|
|
91
|
+
color("covered endpoints #{covered_endpoints_percentage} uncovered endpoints #{uncovered_endpoints_percentage}", 35)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|