Sha256: 2da4b999b8ba9f04b1c2eb10e7114db75391552522de86a3f7c47560d56793c0

Contents?: true

Size: 1.95 KB

Versions: 38

Compression:

Stored size: 1.95 KB

Contents

require 'test_plugin_helper'

module Queries
  class HostAnsibleRolesQueryTest < GraphQLQueryTestCase
    let(:role1) { FactoryBot.create(:ansible_role) }
    let(:role2) { FactoryBot.create(:ansible_role) }
    let(:hostgroup) { FactoryBot.create(:hostgroup, ansible_roles: [role1]) }
    let(:host) { FactoryBot.create(:host, hostgroup: hostgroup, ansible_roles: [role2]) }
    let(:variables) { { id: Foreman::GlobalId.for(host) } }
    let(:query) do
      <<-GRAPHQL
      query ($id: String!) {
        host(id: $id) {
          id
          allAnsibleRoles {
            totalCount
            nodes {
              id
              name
              inherited
              ansibleVariables {
                totalCount
                nodes {
                  key
                  override
                }
              }
            }
          }
        }
      }
      GRAPHQL
    end

    context 'with admin permissions' do
      let(:context_user) { FactoryBot.create(:user, :admin) }
      let(:data) { result['data']['host']['allAnsibleRoles'] }

      it 'allows to fetch inherited roles' do
        assert_equal 2, data['totalCount']

        r1_data = data['nodes'].first
        r2_data = data['nodes'].second

        assert_equal role1.name, r1_data['name']
        assert r1_data['inherited']
        assert_equal role2.name, r2_data['name']
        assert_not r2_data['inherited']
      end

      it 'allow fetching variables' do
        var1 = FactoryBot.create(:ansible_variable, ansible_role: role1, override: true)
        FactoryBot.create(:ansible_variable, ansible_role: role1)
        FactoryBot.create(:ansible_variable, ansible_role: role2, override: true)
        r1_vars = data['nodes'].first['ansibleVariables']
        r2_vars = data['nodes'].second['ansibleVariables']

        assert_equal 2, r1_vars['totalCount']
        assert_equal 1, r2_vars['totalCount']
        assert_equal var1.key, r1_vars['nodes'].first['key']
      end
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
foreman_ansible-15.0.2 test/graphql/queries/host_ansible_roles_query_test.rb
foreman_ansible-15.0.1 test/graphql/queries/host_ansible_roles_query_test.rb
foreman_ansible-15.0.0 test/graphql/queries/host_ansible_roles_query_test.rb
foreman_ansible-14.2.2 test/graphql/queries/host_ansible_roles_query_test.rb
foreman_ansible-14.2.1 test/graphql/queries/host_ansible_roles_query_test.rb
foreman_ansible-13.0.7 test/graphql/queries/host_ansible_roles_query_test.rb
foreman_ansible-14.2.0 test/graphql/queries/host_ansible_roles_query_test.rb
foreman_ansible-14.1.1 test/graphql/queries/host_ansible_roles_query_test.rb
foreman_ansible-14.1.0 test/graphql/queries/host_ansible_roles_query_test.rb
foreman_ansible-13.0.5 test/graphql/queries/host_ansible_roles_query_test.rb
foreman_ansible-14.0.0 test/graphql/queries/host_ansible_roles_query_test.rb
foreman_ansible-13.0.4 test/graphql/queries/host_ansible_roles_query_test.rb
foreman_ansible-13.0.3 test/graphql/queries/host_ansible_roles_query_test.rb
foreman_ansible-13.0.2 test/graphql/queries/host_ansible_roles_query_test.rb
foreman_ansible-13.0.1 test/graphql/queries/host_ansible_roles_query_test.rb
foreman_ansible-13.0.0 test/graphql/queries/host_ansible_roles_query_test.rb
foreman_ansible-12.0.7 test/graphql/queries/host_ansible_roles_query_test.rb
foreman_ansible-10.4.4 test/graphql/queries/host_ansible_roles_query_test.rb
foreman_ansible-12.0.6 test/graphql/queries/host_ansible_roles_query_test.rb
foreman_ansible-12.0.5 test/graphql/queries/host_ansible_roles_query_test.rb