Skip to content

Commit

Permalink
Fix Minitest/EmptyLineBeforeAssertionMethods cop
Browse files Browse the repository at this point in the history
  • Loading branch information
archanaserver committed Jan 9, 2024
1 parent 345cca0 commit d1ec4fd
Show file tree
Hide file tree
Showing 20 changed files with 104 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ Metrics/BlockLength:
- 'config/*routes.rb'
- 'lib/foreman_salt/plugin.rb'
- 'test/**/*.rb'

Minitest/EmptyLineBeforeAssertionMethods:
Enabled: true
3 changes: 3 additions & 0 deletions test/functional/api/v2/salt_autosign_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@ class SaltAutosignControllerTest < ActionController::TestCase

test 'should get index' do
get :index, params: { smart_proxy_id: @proxy.id }

assert_response :success
end

test 'should create autosign' do
ProxyAPI::Salt.any_instance.expects(:autosign_create).once.returns(true)
post :create, params: { smart_proxy_id: @proxy.id, record: 'unicorn.example.com' }

assert_response :success
end

test 'should delete autosign' do
ProxyAPI::Salt.any_instance.expects(:autosign_remove).once.returns(true)
delete :destroy, params: { smart_proxy_id: @proxy.id, record: 'unicorn.example.com' }

assert_response :success
end
end
Expand Down
3 changes: 3 additions & 0 deletions test/functional/api/v2/salt_environments_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@ module V2
class SaltEnvironmentsControllerTest < ActionController::TestCase
test 'should get index' do
get :index

assert_response :success
assert_template 'api/v2/salt_environments/index'
end

test 'should show environment' do
environment = ForemanSalt::SaltEnvironment.create(name: 'foo')
get :show, params: { id: environment.id }

assert_response :success
assert_template 'api/v2/salt_environments/show'
end

test 'should create environment' do
post :create, params: { environment: { name: 'unicorn' } }

assert_response :success
assert ForemanSalt::SaltEnvironment.find_by(name: 'unicorn')
assert_template 'api/v2/salt_environments/create'
Expand Down
3 changes: 3 additions & 0 deletions test/functional/api/v2/salt_keys_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@ class SaltKeysControllerTest < ActionController::TestCase

test 'should get index' do
get :index, params: { smart_proxy_id: @proxy.id }

assert_response :success
end

test 'should update keys' do
ProxyAPI::Salt.any_instance.expects(:key_accept).once.returns(true)
put :update, params: { smart_proxy_id: @proxy.id, name: 'saltstack.example.com', state: 'accepted' }

assert_response :success
end

test 'should delete keys' do
ProxyAPI::Salt.any_instance.expects(:key_delete).once.returns(true)
delete :destroy, params: { smart_proxy_id: @proxy.id, name: 'saltstack.example.com' }

assert_response :success
end
end
Expand Down
8 changes: 8 additions & 0 deletions test/functional/api/v2/salt_states_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@ module V2
class SaltStatesControllerTest < ActionController::TestCase
test 'should get index' do
get :index

assert_response :success
assert_template 'api/v2/salt_states/index'
end

test 'should show state' do
state = ForemanSalt::SaltModule.create(name: 'foo.bar.baz')
get :show, params: { id: state.id }

assert_response :success
assert_template 'api/v2/salt_states/show'
end

test 'should create state' do
post :create, params: { state: { name: 'unicorn' } }

assert_response :success
assert ForemanSalt::SaltModule.find_by(name: 'unicorn')
assert_template 'api/v2/salt_states/create'
Expand Down Expand Up @@ -48,12 +51,14 @@ class SaltStatesControllerTest < ActionController::TestCase

@states.each do |env, states|
environment = ::ForemanSalt::SaltEnvironment.find_by(name: env)

assert_empty environment.salt_modules.map(&:name) - states
end
end

test 'should import only from a given environment' do
post :import, params: { smart_proxy_id: @proxy.id, salt_environments: ['env2'] }

assert_response :success
assert_not ::ForemanSalt::SaltEnvironment.where(name: 'env1').first
assert ::ForemanSalt::SaltEnvironment.where(name: 'env2').first
Expand All @@ -64,6 +69,7 @@ class SaltStatesControllerTest < ActionController::TestCase
state = FactoryBot.create :salt_module, salt_environments: [env]

post :import, params: { smart_proxy_id: @proxy.id, actions: ['add'] }

assert_response :success
assert ::ForemanSalt::SaltModule.where(id: state).first
assert ::ForemanSalt::SaltModule.where(name: 'state1').first
Expand All @@ -72,13 +78,15 @@ class SaltStatesControllerTest < ActionController::TestCase
test 'should limit actions to remove' do
state = FactoryBot.create :salt_module
post :import, params: { smart_proxy_id: @proxy.id, actions: ['remove'] }

assert_response :success
assert_not ::ForemanSalt::SaltModule.where(id: state).first
assert_not ::ForemanSalt::SaltModule.where(name: 'state1').first
end

test 'dryrun should do nothing' do
post :import, params: { smart_proxy_id: @proxy.id, dryrun: true }

assert_response :success
assert_not ::ForemanSalt::SaltModule.all.any?
assert_not ::ForemanSalt::SaltEnvironment.all.any?
Expand Down
3 changes: 3 additions & 0 deletions test/functional/api/v2/salt_variables_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,22 @@ class SaltVariablesControllerTest < ActionController::TestCase
test 'should get index' do
get :index, session: set_session_user
response = JSON.parse(@response.body)

assert_not_empty response['results']
assert_response :success
end

test 'should destroy' do
delete :destroy, params: { id: @variable.id }, session: set_session_user

assert_response :ok
assert_not SaltVariable.exists?(@variable.id)
end

test 'should create' do
params = { key: 'test name', salt_state_id: FactoryBot.create(:salt_module).id }
post :create, params: params, session: set_session_user

assert_response :success
end
end
Expand Down
2 changes: 2 additions & 0 deletions test/functional/hosts_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class HostsControllerExtensionsTest < ActionController::TestCase

post :update_multiple_salt_master, params: params,
session: set_session_user.merge(user: users(:one).id)

assert_response :forbidden
end

Expand Down Expand Up @@ -79,6 +80,7 @@ class HostsControllerExtensionsTest < ActionController::TestCase

post :update_multiple_salt_environment, params: params,
session: set_session_user.merge(user: users(:one).id)

assert_response :forbidden
end

Expand Down
14 changes: 14 additions & 0 deletions test/functional/minions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,23 @@ class MinionsControllerTest < ActionController::TestCase

test 'salt smart proxy should get salt external node' do
get :node, params: { id: @host, format: 'yml' }

assert_response :success

res = YAML.safe_load(@response.body)

assert_equal('different', res['parameters']['parameter1'])
end

test 'setting salt_namespace_pillars is considered' do
Setting['salt_namespace_pillars'] = true

get :node, params: { id: @host, format: 'yml' }

assert_response :success

res = YAML.safe_load(@response.body)

assert_equal('different', res['parameters']['foreman']['parameter1'])
end

Expand All @@ -40,9 +44,11 @@ class MinionsControllerTest < ActionController::TestCase
@host.salt_modules << var.salt_module

get :node, params: { id: @host, format: 'yml' }

assert_response :success

res = YAML.safe_load(@response.body)

assert_equal res['parameters'][var.key], var.value
end

Expand All @@ -52,9 +58,11 @@ class MinionsControllerTest < ActionController::TestCase
@host.salt_modules << var.salt_module

get :node, params: { id: @host, format: 'yml' }

assert_response :success

res = YAML.safe_load(@response.body)

assert_equal res['parameters']['parameter1'], var.value
end

Expand All @@ -70,9 +78,11 @@ class MinionsControllerTest < ActionController::TestCase
@host.salt_modules << var.salt_module

get :node, params: { id: @host, format: 'yml' }

assert_response :success

res = YAML.safe_load(@response.body)

assert_equal res['parameters']['parameter1'], value2.value
end

Expand All @@ -87,9 +97,11 @@ class MinionsControllerTest < ActionController::TestCase
@host2.salt_modules << var.salt_module

get :node, params: { id: @host2, format: 'yml' }

assert_response :success

res = YAML.safe_load(@response.body)

assert_equal res['parameters']['parameter1'], value2.value
end

Expand All @@ -104,9 +116,11 @@ class MinionsControllerTest < ActionController::TestCase
var.salt_module.salt_environments << @host2.salt_environment
@host2.salt_modules << var.salt_module
get :node, params: { id: @host2, format: 'yml' }

assert_response :success

res = YAML.safe_load(@response.body)

assert_equal res['parameters']['parameter1'], var.value
end
end
Expand Down
6 changes: 6 additions & 0 deletions test/integration/hosts_js_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ def multiple_actions_div
# Dropdown visible?
assert multiple_actions_div.find('.dropdown-toggle').visible?
multiple_actions_div.find('.dropdown-toggle').click

assert multiple_actions_div.find('ul').visible?

# Hosts are added to cookie
host_ids_on_cookie = JSON.parse(CGI.unescape(get_me_the_cookie('_ForemanSelectedhosts')&.fetch(:value)))

assert_includes(host_ids_on_cookie, @host.id)

within('#submit_multiple') do
Expand All @@ -46,6 +48,7 @@ def multiple_actions_div

# remove hosts cookie on submit
index_modal.find('.btn-primary').click

assert_current_path hosts_path
assert_empty(get_me_the_cookie('_ForemanSelectedhosts'))
end
Expand All @@ -60,10 +63,12 @@ def multiple_actions_div
# Dropdown visible?
assert multiple_actions_div.find('.dropdown-toggle').visible?
multiple_actions_div.find('.dropdown-toggle').click

assert multiple_actions_div.find('ul').visible?

# Hosts are added to cookie
host_ids_on_cookie = JSON.parse(CGI.unescape(get_me_the_cookie('_ForemanSelectedhosts')&.fetch(:value)))

assert_includes(host_ids_on_cookie, @host.id)

within('#submit_multiple') do
Expand All @@ -75,6 +80,7 @@ def multiple_actions_div

# remove hosts cookie on submit
index_modal.find('.btn-primary').click

assert_current_path hosts_path
assert_empty(get_me_the_cookie('_ForemanSelectedhosts'))
end
Expand Down
4 changes: 4 additions & 0 deletions test/integration/salt_autosign_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,23 @@ class SaltKeysTest < ActionDispatch::IntegrationTest

test 'smart proxy details has autosign link' do
visit smart_proxy_path(@proxy)

assert page.has_link? 'Salt Autosign'
click_link 'Salt Autosign'

assert page.has_title?("Autosign entries for #{@proxy.hostname}"), 'Page title does not appear'
end

test 'index page' do
visit smart_proxy_salt_autosign_index_path(smart_proxy_id: @proxy.id)

assert find_link('Keys').visible?, 'Keys is not visible'
assert has_title?("Autosign entries for #{@proxy.hostname}"), 'Page title does not appear'
end

test 'has list of autosign' do
visit smart_proxy_salt_autosign_index_path(smart_proxy_id: @proxy.id)

assert has_content?('foo.example.com'), 'Missing autosign entry on index page'
end
end
Expand Down
3 changes: 3 additions & 0 deletions test/integration/salt_environment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ module ForemanSalt
class SaltEnvironmentTest < IntegrationTestWithJavascript
test 'index page' do
FactoryBot.create_list :salt_environment, 5

assert_index_page(salt_environments_path, 'Salt Environment', 'New Salt Environment')
end

test 'create new page' do
assert_new_button(salt_environments_path, 'New Salt Environment', new_salt_environment_path)
fill_in 'foreman_salt_salt_environment_name', with: 'common'

assert_submit_button(salt_environments_path)
assert page.has_link? 'common'
end
Expand All @@ -20,6 +22,7 @@ class SaltEnvironmentTest < IntegrationTestWithJavascript
visit salt_environments_path
click_link salt_environment.name
fill_in 'foreman_salt_salt_environment_name', with: 'some_other_name'

assert_submit_button(salt_environments_path)
assert page.has_link? 'some_other_name'
end
Expand Down
6 changes: 6 additions & 0 deletions test/integration/salt_keys_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,35 @@ class SaltKeysTest < ActionDispatch::IntegrationTest

test 'smart proxy details has keys link' do
visit smart_proxy_path(@proxy)

assert page.has_link? 'Salt Keys'
click_link 'Salt Keys'

assert page.has_title?("Salt Keys on #{@proxy}"), 'Page title does not appear'
end

test 'index page' do
visit smart_proxy_salt_keys_path(smart_proxy_id: @proxy.id)

assert has_title?("Salt Keys on #{@proxy}"), 'Page title does not appear'
end

test 'has list of keys' do
visit smart_proxy_salt_keys_path(smart_proxy_id: @proxy.id)

assert has_content?('saltclient01.example.com'), 'Missing key on index page'
assert has_content?('98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c1'), 'Missing fingerprint on index page'
end

test 'has accept link' do
ProxyAPI::Salt.any_instance.stubs(:key_accept).returns(true)

assert_row_button(smart_proxy_salt_keys_path(smart_proxy_id: @proxy.id), 'saltclient01.example.com', 'Accept', dropdown: true)
end

test 'has reject link' do
ProxyAPI::Salt.any_instance.stubs(:key_reject).returns(true)

assert_row_button(smart_proxy_salt_keys_path(smart_proxy_id: @proxy.id), 'saltclient01.example.com', 'Reject', dropdown: true)
end
end
Expand Down
Loading

0 comments on commit d1ec4fd

Please sign in to comment.