foreman_remote_execution 14.0.0 → 14.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/foreman_remote_execution/locale/de/foreman_remote_execution.js +77 -77
  3. data/app/assets/javascripts/foreman_remote_execution/locale/en/foreman_remote_execution.js +2 -1667
  4. data/app/assets/javascripts/foreman_remote_execution/locale/en_GB/foreman_remote_execution.js +7 -7
  5. data/app/assets/javascripts/foreman_remote_execution/locale/es/foreman_remote_execution.js +33 -33
  6. data/app/assets/javascripts/foreman_remote_execution/locale/fr/foreman_remote_execution.js +131 -131
  7. data/app/assets/javascripts/foreman_remote_execution/locale/ja/foreman_remote_execution.js +131 -131
  8. data/app/assets/javascripts/foreman_remote_execution/locale/ka/foreman_remote_execution.js +38 -38
  9. data/app/assets/javascripts/foreman_remote_execution/locale/ko/foreman_remote_execution.js +16 -16
  10. data/app/assets/javascripts/foreman_remote_execution/locale/pt_BR/foreman_remote_execution.js +33 -33
  11. data/app/assets/javascripts/foreman_remote_execution/locale/ru/foreman_remote_execution.js +7 -7
  12. data/app/assets/javascripts/foreman_remote_execution/locale/zh_CN/foreman_remote_execution.js +134 -134
  13. data/app/assets/javascripts/foreman_remote_execution/locale/zh_TW/foreman_remote_execution.js +6 -6
  14. data/app/controllers/api/v2/job_invocations_controller.rb +34 -17
  15. data/app/helpers/job_invocations_helper.rb +1 -1
  16. data/app/helpers/remote_execution_helper.rb +2 -2
  17. data/app/lib/actions/remote_execution/proxy_action.rb +10 -5
  18. data/app/lib/actions/remote_execution/run_host_job.rb +1 -1
  19. data/app/lib/actions/remote_execution/template_invocation_progress_logging.rb +2 -3
  20. data/app/models/concerns/foreman_remote_execution/errors_flattener.rb +2 -2
  21. data/app/views/api/v2/job_invocations/hosts.json.rabl +15 -0
  22. data/app/views/template_invocations/show.html.erb +1 -1
  23. data/app/views/templates/script/package_action.erb +1 -1
  24. data/config/routes.rb +1 -0
  25. data/db/migrate/20240312133027_extend_template_invocation_events.rb +19 -0
  26. data/db/migrate/20240522093413_migrate_smart_proxy_ids_to_template_invocations.rb +3 -0
  27. data/lib/foreman_remote_execution/engine.rb +0 -4
  28. data/lib/foreman_remote_execution/version.rb +1 -1
  29. data/locale/Makefile +12 -2
  30. data/locale/de/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  31. data/locale/de/foreman_remote_execution.po +81 -80
  32. data/locale/en/foreman_remote_execution.po +0 -1675
  33. data/locale/en_GB/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  34. data/locale/en_GB/foreman_remote_execution.po +7 -7
  35. data/locale/es/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  36. data/locale/es/foreman_remote_execution.po +33 -33
  37. data/locale/fr/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  38. data/locale/fr/foreman_remote_execution.po +132 -132
  39. data/locale/ja/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  40. data/locale/ja/foreman_remote_execution.po +131 -131
  41. data/locale/ka/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  42. data/locale/ka/foreman_remote_execution.po +38 -38
  43. data/locale/ko/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  44. data/locale/ko/foreman_remote_execution.po +16 -16
  45. data/locale/pt_BR/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  46. data/locale/pt_BR/foreman_remote_execution.po +33 -33
  47. data/locale/ru/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  48. data/locale/ru/foreman_remote_execution.po +7 -7
  49. data/locale/zh_CN/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  50. data/locale/zh_CN/foreman_remote_execution.po +136 -134
  51. data/locale/zh_TW/LC_MESSAGES/foreman_remote_execution.mo +0 -0
  52. data/locale/zh_TW/foreman_remote_execution.po +6 -6
  53. data/webpack/JobInvocationDetail/JobInvocationActions.js +1 -1
  54. data/webpack/JobInvocationDetail/JobInvocationConstants.js +84 -0
  55. data/webpack/JobInvocationDetail/JobInvocationDetail.scss +0 -1
  56. data/webpack/JobInvocationDetail/JobInvocationHostTable.js +210 -0
  57. data/webpack/JobInvocationDetail/JobInvocationSelectors.js +2 -2
  58. data/webpack/JobInvocationDetail/__tests__/MainInformation.test.js +5 -1
  59. data/webpack/JobInvocationDetail/__tests__/fixtures.js +9 -0
  60. data/webpack/JobInvocationDetail/index.js +56 -34
  61. data/webpack/__mocks__/foremanReact/components/HostDetails/DetailsCard/DefaultLoaderEmptyState.js +1 -2
  62. data/webpack/react_app/components/RecentJobsCard/JobStatusIcon.js +38 -7
  63. data/webpack/react_app/components/RecentJobsCard/constants.js +4 -0
  64. data/webpack/react_app/components/TargetingHosts/__tests__/__snapshots__/HostStatus.test.js.snap +1 -1
  65. data/webpack/react_app/components/TargetingHosts/components/HostStatus.js +6 -6
  66. metadata +6 -95
  67. data/.babelrc.js +0 -3
  68. data/.eslintignore +0 -3
  69. data/.eslintrc +0 -13
  70. data/.github/workflows/js_ci.yml +0 -32
  71. data/.github/workflows/release.yml +0 -16
  72. data/.github/workflows/ruby_ci.yml +0 -19
  73. data/.gitignore +0 -18
  74. data/.packit.yaml +0 -45
  75. data/.prettierrc +0 -4
  76. data/.rubocop.yml +0 -105
  77. data/.rubocop_todo.yml +0 -516
  78. data/.tx/config +0 -10
  79. data/Gemfile +0 -5
  80. data/app/mailers/.gitkeep +0 -0
  81. data/app/views/dashboard/.gitkeep +0 -0
  82. data/foreman_remote_execution.gemspec +0 -33
  83. data/jsconfig.json +0 -8
  84. data/locale/action_names.rb +0 -2
  85. data/test/benchmark/run_hosts_job_benchmark.rb +0 -70
  86. data/test/benchmark/targeting_benchmark.rb +0 -31
  87. data/test/factories/foreman_remote_execution_factories.rb +0 -147
  88. data/test/functional/api/v2/foreign_input_sets_controller_test.rb +0 -58
  89. data/test/functional/api/v2/job_invocations_controller_test.rb +0 -446
  90. data/test/functional/api/v2/job_templates_controller_test.rb +0 -110
  91. data/test/functional/api/v2/registration_controller_test.rb +0 -73
  92. data/test/functional/api/v2/remote_execution_features_controller_test.rb +0 -34
  93. data/test/functional/api/v2/template_invocations_controller_test.rb +0 -33
  94. data/test/functional/cockpit_controller_test.rb +0 -16
  95. data/test/functional/job_invocations_controller_test.rb +0 -132
  96. data/test/functional/job_templates_controller_test.rb +0 -31
  97. data/test/functional/ui_job_wizard_controller_test.rb +0 -16
  98. data/test/graphql/mutations/job_invocations/create_test.rb +0 -58
  99. data/test/graphql/queries/job_invocation_query_test.rb +0 -31
  100. data/test/graphql/queries/job_invocations_query_test.rb +0 -35
  101. data/test/helpers/remote_execution_helper_test.rb +0 -46
  102. data/test/support/remote_execution_helper.rb +0 -5
  103. data/test/test_plugin_helper.rb +0 -9
  104. data/test/unit/actions/run_host_job_test.rb +0 -115
  105. data/test/unit/actions/run_hosts_job_test.rb +0 -214
  106. data/test/unit/api_params_test.rb +0 -25
  107. data/test/unit/concerns/foreman_tasks_cleaner_extensions_test.rb +0 -29
  108. data/test/unit/concerns/host_extensions_test.rb +0 -219
  109. data/test/unit/concerns/nic_extensions_test.rb +0 -9
  110. data/test/unit/execution_task_status_mapper_test.rb +0 -92
  111. data/test/unit/input_template_renderer_test.rb +0 -503
  112. data/test/unit/job_invocation_composer_test.rb +0 -974
  113. data/test/unit/job_invocation_report_template_test.rb +0 -60
  114. data/test/unit/job_invocation_test.rb +0 -232
  115. data/test/unit/job_template_effective_user_test.rb +0 -37
  116. data/test/unit/job_template_test.rb +0 -316
  117. data/test/unit/remote_execution_feature_test.rb +0 -86
  118. data/test/unit/remote_execution_provider_test.rb +0 -298
  119. data/test/unit/renderer_scope_input_test.rb +0 -49
  120. data/test/unit/targeting_test.rb +0 -206
  121. data/test/unit/template_invocation_input_value_test.rb +0 -38
@@ -1,110 +0,0 @@
1
- require 'test_plugin_helper'
2
-
3
- module Api
4
- module V2
5
- class JobTemplatesControllerTest < ActionController::TestCase
6
- setup do
7
- @template = FactoryBot.create :job_template
8
- end
9
-
10
- test 'should get index' do
11
- get :index
12
- templates = ActiveSupport::JSON.decode(@response.body)
13
- assert_not templates.empty?, 'Should response with template'
14
- assert_response :success
15
- end
16
-
17
- test 'should get templates of give organization' do
18
- @organization = FactoryBot.create(:organization)
19
- @template.organizations << @organization
20
- @template.save!
21
- get :index, params: { :organization_id => @organization.id }
22
- templates = ActiveSupport::JSON.decode(@response.body)
23
- assert_not templates.empty?, 'Should respond with template'
24
- assert_response :success
25
- end
26
-
27
- test 'should get template detail' do
28
- get :show, params: { :id => @template.to_param }
29
- assert_response :success
30
- template = ActiveSupport::JSON.decode(@response.body)
31
- assert_not template.empty?
32
- assert_equal template['name'], @template.name
33
- assert_not_nil template['created_at']
34
- assert_not_nil template['updated_at']
35
- end
36
-
37
- test 'should create valid' do
38
- JobTemplate.any_instance.stubs(:valid?).returns(true)
39
- valid_attrs = { :template => 'This is a test template', :name => 'RandomName', :provider_type => 'ssh' }
40
- post :create, params: { :job_template => valid_attrs }
41
- template = ActiveSupport::JSON.decode(@response.body)
42
- assert_equal template['name'], 'RandomName'
43
- assert_response :success
44
- end
45
-
46
- test 'should not create invalid' do
47
- post :create
48
- assert_response :unprocessable_entity
49
- end
50
-
51
- test 'should update valid' do
52
- JobTemplate.any_instance.stubs(:valid?).returns(true)
53
- put :update, params: { :id => @template.to_param, :job_template => { :template => 'blah' } }
54
- assert_response :ok
55
- end
56
-
57
- test 'should not update invalid' do
58
- put :update, params: { :id => @template.to_param, :job_template => { :name => '' } }
59
- assert_response :unprocessable_entity
60
- end
61
-
62
- test 'should update effective user' do
63
- template = { name: @template.name, job_category: @template.job_category,
64
- template: @template.template, provider_type: 'SSH',
65
- effective_user_attributes: {
66
- value: 'nobody',
67
- overridable: true,
68
- current_user: false,
69
- } }
70
- put :update, params: { id: @template.to_param, job_template: template }
71
- assert_response :ok
72
- end
73
-
74
- test 'should destroy' do
75
- delete :destroy, params: { :id => @template.to_param }
76
- assert_response :ok
77
- assert_not JobTemplate.exists?(@template.id)
78
- end
79
-
80
- test 'should clone template' do
81
- post :clone, params: { :id => @template.to_param, :job_template => {:name => 'MyClone'} }
82
- assert_response :success
83
- template = ActiveSupport::JSON.decode(@response.body)
84
- assert_equal(template['name'], 'MyClone')
85
- assert_equal(template['template'], @template.template)
86
- end
87
-
88
- test 'clone name should not be blank' do
89
- post :clone, params: { :id => @template.to_param, :job_template => {:name => ''} }
90
- assert_response :unprocessable_entity
91
- end
92
-
93
- test 'should export template' do
94
- get :export, params: { :id => @template.to_param }
95
- User.current = users(:admin)
96
- assert_equal @response.body, @template.to_erb
97
- assert_response :success
98
- end
99
-
100
- test 'should import template' do
101
- new_name = @template.name = "#{@template.name}_renamed"
102
- erb_data = @template.to_erb
103
- post :import, params: { :template => erb_data }
104
- assert_response :success
105
- assert JobTemplate.unscoped.find_by(name: new_name)
106
- end
107
- end
108
-
109
- end
110
- end
@@ -1,73 +0,0 @@
1
- require 'test_plugin_helper'
2
-
3
- module Api
4
- module V2
5
- # Tests for the extra methods to play roles on a Host
6
- class RegistrationControllerTest < ActionController::TestCase
7
- describe 'host registration' do
8
- let(:organization) { FactoryBot.create(:organization) }
9
- let(:tax_location) { FactoryBot.create(:location) }
10
- let(:template) do
11
- FactoryBot.create(
12
- :provisioning_template,
13
- template_kind: template_kinds(:host_init_config),
14
- template: 'template content <%= @host.name %>',
15
- locations: [tax_location],
16
- organizations: [organization]
17
- )
18
- end
19
- let(:os) do
20
- FactoryBot.create(
21
- :operatingsystem,
22
- :with_associations,
23
- family: 'Redhat',
24
- provisioning_templates: [
25
- template,
26
- ]
27
- )
28
- end
29
-
30
- let(:host_params) do
31
- { host: { name: 'centos-test.example.com',
32
- managed: false, build: false,
33
- organization_id: organization.id,
34
- location_id: tax_location.id,
35
- operatingsystem_id: os.id } }
36
- end
37
-
38
- describe 'remote_execution_interface' do
39
- setup do
40
- Setting[:default_host_init_config_template] = template.name
41
- @host = Host.create(host_params[:host])
42
- @interface0 = FactoryBot.create(:nic_managed, host: @host, identifier: 'dummy0', execution: false)
43
- end
44
-
45
- test 'with existing interface' do
46
- params = host_params.merge(remote_execution_interface: @interface0.identifier)
47
-
48
- post :host, params: params, session: set_session_user
49
- assert_response :success
50
- assert @interface0.reload.execution
51
- end
52
-
53
- test 'with not-existing interface' do
54
- params = host_params.merge(remote_execution_interface: 'dummy999')
55
-
56
- post :host, params: params, session: set_session_user
57
- assert_response :not_found
58
- end
59
-
60
- test 'with multiple interfaces' do
61
- interface1 = FactoryBot.create(:nic_managed, host: @host, identifier: 'dummy1', execution: false)
62
- params = host_params.merge(remote_execution_interface: interface1.identifier)
63
-
64
- post :host, params: params, session: set_session_user
65
- assert_response :success
66
- refute @interface0.reload.execution
67
- assert interface1.reload.execution
68
- end
69
- end
70
- end
71
- end
72
- end
73
- end
@@ -1,34 +0,0 @@
1
- require 'test_plugin_helper'
2
-
3
- module Api
4
- module V2
5
- class RemoteExecutionFeaturesControllerTest < ActionController::TestCase
6
- setup do
7
- @remote_execution_feature = RemoteExecutionFeature.register(:my_awesome_feature, 'My awesome feature',
8
- :description => 'You will not believe what it does',
9
- :provided_inputs => ['awesomeness_level'])
10
- @template = FactoryBot.create(:job_template, :with_input)
11
- end
12
-
13
- test 'should get index' do
14
- get :index
15
- remote_execution_features = ActiveSupport::JSON.decode(@response.body)
16
- assert_not remote_execution_features.empty?, 'Should respond with input sets'
17
- assert_response :success
18
- end
19
-
20
- test 'should get input set detail' do
21
- get :show, params: { :id => @remote_execution_feature.to_param }
22
- assert_response :success
23
- remote_execution_feature = ActiveSupport::JSON.decode(@response.body)
24
- assert_not remote_execution_feature.empty?
25
- assert_equal remote_execution_feature['name'], @remote_execution_feature.name
26
- end
27
-
28
- test 'should update valid' do
29
- put :update, params: { :id => @remote_execution_feature.to_param, :job_template_id => @template.id }
30
- assert_response :ok
31
- end
32
- end
33
- end
34
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_plugin_helper'
4
-
5
- module Api
6
- module V2
7
- class TemplateInvocationsControllerTest < ActionController::TestCase
8
- setup do
9
- @job = FactoryBot.create(:job_invocation, :with_template, :with_task)
10
- @template_invocation = @job.template_invocations.first
11
- end
12
-
13
- test 'should get template invocations belonging to job invocation' do
14
- get :template_invocations, params: { :id => @job.id }
15
- invocations = ActiveSupport::JSON.decode(@response.body)
16
- assert_equal @job.template_invocations.count, invocations['results'].count
17
- assert_equal @job.template_invocations.count, invocations['total']
18
-
19
- expected_result = {
20
- 'id' => @template_invocation.id,
21
- 'host_id' => @template_invocation.host_id,
22
- 'host_name' => @template_invocation.host.name,
23
- 'template_id' => @template_invocation.template_id,
24
- 'effective_user' => @template_invocation.effective_user,
25
- 'job_invocation_id' => @job.id,
26
- 'run_host_job_task_id' => @template_invocation.run_host_job_task_id,
27
- }
28
- assert_equal [expected_result], invocations['results']
29
- assert_response :success
30
- end
31
- end
32
- end
33
- end
@@ -1,16 +0,0 @@
1
- require 'test_plugin_helper'
2
-
3
- class CockpitControllerTest < ActionController::TestCase
4
- def setup
5
- as_admin do
6
- @host = FactoryBot.create(:host)
7
- end
8
- end
9
-
10
- test "should get host_ssh_params" do
11
- get :host_ssh_params, params: { id: @host.id }, session: set_session_user
12
- assert_response :success
13
- response = ActiveSupport::JSON.decode(@response.body)
14
- assert response.key?('ssh_user'), 'ssh_params response must include ssh_user'
15
- end
16
- end
@@ -1,132 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_plugin_helper'
4
- require_relative '../support/remote_execution_helper'
5
-
6
- class JobInvocationsControllerTest < ActionController::TestCase
7
- test 'should parse inputs coming from the URL params' do
8
- template = FactoryBot.create(:job_template, :with_input)
9
- feature = FactoryBot.create(:remote_execution_feature,
10
- :job_template => template)
11
- params = {
12
- feature: feature.label,
13
- inputs: { template.template_inputs.first.name => 'foobar' },
14
- }
15
-
16
- get :new, params: params, session: set_session_user
17
- template_invocation_params = [
18
- {
19
- 'input_values' =>
20
- [
21
- {
22
- 'value' => 'foobar',
23
- 'template_input_id' => template.template_inputs.first.id,
24
- },
25
- ],
26
- 'template_id' => template.id,
27
- },
28
- ]
29
- assert_equal(template_invocation_params,
30
- assigns(:composer).params['template_invocations'])
31
- end
32
-
33
- test 'should allow no inputs' do
34
- template = FactoryBot.create(:job_template)
35
- feature = FactoryBot.create(:remote_execution_feature,
36
- :job_template => template)
37
- params = {
38
- feature: feature.label,
39
- }
40
- get :new, params: params, session: set_session_user
41
- template_invocation_params = [
42
- {
43
- 'template_id' => template.id,
44
- 'input_values' => {},
45
- },
46
- ]
47
- assert_equal(template_invocation_params,
48
- assigns(:composer).params['template_invocations'])
49
- end
50
-
51
- test 'new via GET and POST' do
52
- template = FactoryBot.create(:job_template, :with_input)
53
- feature = FactoryBot.create(:remote_execution_feature, job_template: template)
54
- params = { feature: feature.label, inputs: { template.template_inputs.first.name => 'foobar' } }
55
-
56
- get :new, params: params, session: set_session_user
57
- assert_response :success
58
-
59
- post :new, params: params, session: set_session_user
60
- assert_response :success
61
- end
62
-
63
- context 'restricted access' do
64
- setup do
65
- @admin = users(:admin)
66
- @user = FactoryBot.create(:user, mail: 'test23@test.foreman.com', admin: false)
67
- @invocation = FactoryBot.create(:job_invocation, :with_template, :with_task)
68
- @invocation2 = FactoryBot.create(:job_invocation, :with_template, :with_task)
69
-
70
- @invocation.task.update(user: @admin)
71
- @invocation2.task.update(user: @user)
72
-
73
- setup_user 'view', 'hosts', nil, @user
74
- setup_user 'view', 'job_invocations', 'user = current_user', @user
75
- setup_user 'create', 'job_invocations', 'user = current_user', @user
76
- setup_user 'cancel', 'job_invocations', 'user = current_user', @user
77
- end
78
-
79
- context 'without user filter' do
80
- test '#index' do
81
- get :index, session: prepare_user(@admin)
82
- assert_response :success
83
- assert 2, assigns(:job_invocations).size
84
- end
85
-
86
- test '#show' do
87
- get :show, params: { id: @invocation2.id }, session: prepare_user(@admin)
88
- assert_response :success
89
- end
90
-
91
- test '#rerun' do
92
- get :rerun, params: { id: @invocation2.id }, session: prepare_user(@admin)
93
- assert_response :success
94
- end
95
-
96
- test '#cancel' do
97
- ForemanTasks::Task.any_instance.expects(:cancel).returns(true)
98
- post :cancel, params: { id: @invocation2.id }, session: prepare_user(@admin)
99
- assert_response :redirect
100
- end
101
- end
102
-
103
- context 'with user filter' do
104
- test '#index' do
105
- get :index, session: prepare_user(@user)
106
- assert_response :success
107
- assert_equal 1, assigns(:job_invocations).size
108
- assert_equal @invocation2, assigns(:job_invocations)[0]
109
- end
110
-
111
- test '#show' do
112
- get :show, params: { id: @invocation.id }, session: prepare_user(@user)
113
- assert_response :not_found
114
- end
115
-
116
- test '#rerun' do
117
- get :rerun, params: { id: @invocation.id }, session: prepare_user(@user)
118
- assert_response :not_found
119
- end
120
-
121
- test 'cancel' do
122
- post :cancel, params: { id: @invocation.id }, session: prepare_user(@user)
123
- assert_response :not_found
124
- end
125
- end
126
- end
127
-
128
- def prepare_user(user)
129
- User.current = user
130
- set_session_user(user)
131
- end
132
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_plugin_helper'
4
-
5
- class JobTemplatesControllerTest < ActionController::TestCase
6
- context '#preview' do
7
- let(:template) { FactoryBot.create(:job_template) }
8
- let(:host) { FactoryBot.create(:host, :managed) }
9
-
10
- test 'should render a preview version of a template' do
11
- post :preview, params: { job_template: template.to_param, template: 'uptime' }, session: set_session_user
12
- assert_response :success
13
- end
14
-
15
- test 'should render a preview version of a template for a specific host' do
16
- post :preview, params: {
17
- job_template: template.to_param,
18
- template: '<%= @host.name %>',
19
- preview_host_id: host.id,
20
- }, session: set_session_user
21
- assert_response :success
22
- assert_equal host.name, @response.body
23
- end
24
-
25
- test 'should render a error message when template has errors' do
26
- InputTemplateRenderer.any_instance.stubs(:render).returns(false)
27
- post :preview, params: { job_template: template.to_param }, session: set_session_user
28
- assert_response :not_acceptable
29
- end
30
- end
31
- end
@@ -1,16 +0,0 @@
1
- require 'test_plugin_helper'
2
-
3
- class UIJobWizardControllerTest < ActionController::TestCase
4
- def setup
5
- FactoryBot.create(:job_template, :job_category => 'cat1')
6
- FactoryBot.create(:job_template, :job_category => 'cat2')
7
- FactoryBot.create(:job_template, :job_category => 'cat2')
8
- end
9
-
10
- test 'should respond with categories' do
11
- get :categories, :params => {}, :session => set_session_user
12
- assert_response :success
13
- res = JSON.parse @response.body
14
- assert_equal ['cat1','cat2'], res['job_categories']
15
- end
16
- end
@@ -1,58 +0,0 @@
1
- require 'test_plugin_helper'
2
-
3
- module Mutations
4
- module JobInvocations
5
- class CreateMutationTest < ActiveSupport::TestCase
6
- let(:host) { FactoryBot.create(:host) }
7
- let(:job_template) { FactoryBot.create(:job_template, :with_input) }
8
- let(:cron_line) { '5 * * * *' }
9
- let(:purpose) { 'test' }
10
- let(:variables) do
11
- {
12
- jobInvocation: {
13
- hostIds: [host.id],
14
- jobTemplateId: job_template.id,
15
- targetingType: 'static_query',
16
- inputs: { job_template.template_inputs.first.name => "bar" },
17
- recurrence: {
18
- cronLine: cron_line,
19
- purpose: purpose,
20
- },
21
- },
22
- }
23
- end
24
-
25
- let(:query) do
26
- <<-GRAPHQL
27
- mutation CreateJobInvocation($jobInvocation: JobInvocationInput!) {
28
- createJobInvocation(input: { jobInvocation: $jobInvocation }) {
29
- jobInvocation {
30
- id
31
- description
32
- recurringLogic {
33
- cronLine
34
- purpose
35
- }
36
- }
37
- }
38
- }
39
- GRAPHQL
40
- end
41
-
42
- context 'with admin user' do
43
- let(:user) { FactoryBot.create(:user, :admin) }
44
- let(:context) { { current_user: user } }
45
-
46
- test 'create a job invocation' do
47
- assert_difference('JobInvocation.count', +1) do
48
- result = ForemanGraphqlSchema.execute(query, variables: variables, context: context)
49
- assert_empty result['errors']
50
- assert_empty result['data']['createJobInvocation']['jobInvocation']['errors']
51
- assert_equal cron_line, result['data']['createJobInvocation']['jobInvocation']['recurringLogic']['cronLine']
52
- assert_equal purpose, result['data']['createJobInvocation']['jobInvocation']['recurringLogic']['purpose']
53
- end
54
- end
55
- end
56
- end
57
- end
58
- end
@@ -1,31 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Queries
4
- class JobInvocationQueryTest < GraphQLQueryTestCase
5
- let(:query) do
6
- <<-GRAPHQL
7
- query (
8
- $id: String!
9
- ) {
10
- jobInvocation(id: $id) {
11
- id
12
- jobCategory
13
- }
14
- }
15
- GRAPHQL
16
- end
17
-
18
- let(:job_invocation) { FactoryBot.create(:job_invocation) }
19
-
20
- let(:global_id) { Foreman::GlobalId.for(job_invocation) }
21
- let(:variables) { { id: global_id } }
22
- let(:data) { result['data']['jobInvocation'] }
23
-
24
- test 'fetching job invocation attributes' do
25
- assert_empty result['errors']
26
-
27
- assert_equal global_id, data['id']
28
- assert_equal job_invocation.job_category, data['jobCategory']
29
- end
30
- end
31
- end
@@ -1,35 +0,0 @@
1
- require 'test_plugin_helper'
2
-
3
- module Queries
4
- class JobInvocationsQueryTest < GraphQLQueryTestCase
5
- let(:query) do
6
- <<-GRAPHQL
7
- query {
8
- jobInvocations {
9
- totalCount
10
- nodes {
11
- id
12
- jobCategory
13
- }
14
- }
15
- }
16
- GRAPHQL
17
- end
18
-
19
- let(:data) { result['data']['jobInvocations'] }
20
-
21
- setup do
22
- FactoryBot.create_list(:job_invocation, 2)
23
- end
24
-
25
- test 'should fetch job invocations' do
26
- assert_empty result['errors']
27
-
28
- expected_count = JobInvocation.count
29
-
30
- assert_not_equal 0, expected_count
31
- assert_equal expected_count, data['totalCount']
32
- assert_equal expected_count, data['nodes'].count
33
- end
34
- end
35
- end
@@ -1,46 +0,0 @@
1
- require 'test_plugin_helper'
2
-
3
- class RemoteExecutionHelperTest < ActionView::TestCase
4
- describe '#normalize_line_sets' do
5
- let :line_sets do
6
- [{"output_type"=>"stdout", "output"=>"one", "timestamp"=>1},
7
- {"output_type"=>"stdout", "output"=>"\r\ntwo\r\n", "timestamp"=>2},
8
- {"output_type"=>"stdout", "output"=>"\r\nthr", "timestamp"=>3},
9
- {"output_type"=>"stdout", "output"=>"ee\r\nfour\r\n", "timestamp"=>4},
10
- {"output_type"=>"stdout", "output"=>"\r\n\r\n", "timestamp"=>5},
11
- {"output_type"=>"stdout", "output"=>"five\r\n", "timestamp"=>6},
12
- {"output_type"=>"stdout", "output"=>"Exit status: 0", "timestamp"=>7}]
13
- end
14
-
15
- it 'ensures the line sets end with new line' do
16
- new_line_sets = normalize_line_sets(line_sets)
17
- expected_output = ["one\r\n",
18
- "two\r\n",
19
- "\r\nthree\r\n",
20
- "four\r\n",
21
- "\r\n\r\n",
22
- "five\r\n",
23
- "Exit status: 0"]
24
- assert_equal(expected_output, new_line_sets.map { |s| s['output'] })
25
- end
26
- end
27
-
28
- describe 'test correct setting' do
29
- it 'should found correct template from setting' do
30
- template_name = 'Job Invocation Report Template'
31
- setting_key = 'remote_execution_job_invocation_report_template'
32
- template = FactoryBot.create(:report_template, name: template_name)
33
- input = FactoryBot.create(:template_input, name: 'job_id', input_type: 'user')
34
- template.template_inputs << input
35
- Setting.expects(:[]).with(setting_key).returns(template_name)
36
-
37
- found_template = job_report_template
38
-
39
- assert_equal template.id, found_template.id
40
- end
41
-
42
- it 'should not crash if the template cannot be found' do
43
- assert_nil job_report_template
44
- end
45
- end
46
- end
@@ -1,5 +0,0 @@
1
- module RemoteExecutionHelper
2
- def job_invocation_task_buttons(task)
3
- return []
4
- end
5
- end
@@ -1,9 +0,0 @@
1
- # This calls the main test_helper in Foreman-core
2
- require 'test_helper'
3
- require 'dynflow/testing'
4
-
5
- # Add plugin to FactoryBot's paths
6
- FactoryBot.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
7
- # Add foreman tasks factories too
8
- FactoryBot.definition_file_paths << "#{ForemanTasks::Engine.root}/test/factories"
9
- FactoryBot.reload