Sha256: 021b3adddacc1b1e57edc3d6e062c56cfbff7982782e1ce87efd1442169c5229

Contents?: true

Size: 1.54 KB

Versions: 18

Compression:

Stored size: 1.54 KB

Contents

require 'test_plugin_helper'
require 'dynflow/testing'

module Api
  module V2
    # Tests for the extra methods to play roles on Hostgroup
    class HostgroupsControllerTest < ActionController::TestCase
      setup do
        @host1 = FactoryBot.create(:host, :with_hostgroup)
        @host2 = FactoryBot.create(:host, :with_hostgroup)
      end

      test 'should return an not_found due to non-existent host_id' do
        post :play_roles, :params => { :id => 'non-existent' }
        response = JSON.parse(@response.body)
        refute_empty response
        assert_response :not_found
      end

      test 'should trigger task on host group' do
        load File.join(ForemanAnsible::Engine.root,
                       '/db/seeds.d/75_job_templates.rb')
        ::JobInvocationComposer.any_instance.expects(:trigger!).returns(true)
        target = @host1
        post :play_roles, :params => { :id => target.hostgroup.id }
        response = JSON.parse(@response.body)
        assert_job_invocation_is_ok(response, target.id)
      end

      test 'should trigger two host group tasks' do
        load File.join(ForemanAnsible::Engine.root,
                       '/db/seeds.d/75_job_templates.rb')
        ::JobInvocationComposer.any_instance.expects(:trigger!).returns(true)
        target = [@host1, @host2]
        post :multiple_play_roles, :params => {
          :hostgroup_ids => target.map(&:hostgroup_id)
        }
        response = JSON.parse(@response.body)
        assert_job_invocation_is_ok(response, target.map(&:id))
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
foreman_ansible-2.2.9 test/functional/api/v2/hostgroups_controller_test.rb
foreman_ansible-2.2.8 test/functional/api/v2/hostgroups_controller_test.rb
foreman_ansible-2.2.7 test/functional/api/v2/hostgroups_controller_test.rb
foreman_ansible-2.2.6 test/functional/api/v2/hostgroups_controller_test.rb
foreman_ansible-2.2.5 test/functional/api/v2/hostgroups_controller_test.rb
foreman_ansible-2.2.4 test/functional/api/v2/hostgroups_controller_test.rb
foreman_ansible-2.2.3 test/functional/api/v2/hostgroups_controller_test.rb
foreman_ansible-2.2.2 test/functional/api/v2/hostgroups_controller_test.rb
foreman_ansible-2.2.1 test/functional/api/v2/hostgroups_controller_test.rb
foreman_ansible-2.2.0 test/functional/api/v2/hostgroups_controller_test.rb
foreman_ansible-2.1.2 test/functional/api/v2/hostgroups_controller_test.rb
foreman_ansible-2.1.1 test/functional/api/v2/hostgroups_controller_test.rb
foreman_ansible-2.0.4 test/functional/api/v2/hostgroups_controller_test.rb
foreman_ansible-2.0.3 test/functional/api/v2/hostgroups_controller_test.rb
foreman_ansible-2.0.2 test/functional/api/v2/hostgroups_controller_test.rb
foreman_ansible-2.1.0 test/functional/api/v2/hostgroups_controller_test.rb
foreman_ansible-2.0.1 test/functional/api/v2/hostgroups_controller_test.rb
foreman_ansible-2.0.0 test/functional/api/v2/hostgroups_controller_test.rb