Sha256: 28a513cf337573b23afbfaf3c609bf923b62367ac1e3bcb6e183dbf07ec70dc3

Contents?: true

Size: 1.95 KB

Versions: 5

Compression:

Stored size: 1.95 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
        @ansible_role1 = FactoryBot.create(:ansible_role)
        @host1 = FactoryBot.create(:host, :with_hostgroup)
        @host2 = FactoryBot.create(:host, :with_hostgroup)
        @host3 = 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

      test 'should list ansible roles for a host group' do
        @host3.hostgroup.ansible_roles = [@ansible_role1]
        get :ansible_roles, :params => { :id => @host3.hostgroup.id }
        response = JSON.parse(@response.body)
        assert_equal @ansible_role1.id, response.first['id']
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
foreman_ansible-2.2.14 test/functional/api/v2/hostgroups_controller_test.rb
foreman_ansible-2.2.13 test/functional/api/v2/hostgroups_controller_test.rb
foreman_ansible-2.2.12 test/functional/api/v2/hostgroups_controller_test.rb
foreman_ansible-2.2.11 test/functional/api/v2/hostgroups_controller_test.rb
foreman_ansible-2.2.10 test/functional/api/v2/hostgroups_controller_test.rb