Sha256: 4b7cf7b0481d86ed894829db51cae5514b893703dd769ec601aede2b1d1b107e

Contents?: true

Size: 1.81 KB

Versions: 12

Compression:

Stored size: 1.81 KB

Contents

require 'test_plugin_helper'

class SaltKeysTest < ActiveSupport::TestCase
  setup do
    User.current = users :admin

    # Fix for 1.8.7 OpenStruct http://stackoverflow.com/questions/9079441/populate-select-tag-ruby-rails
    OpenStruct.__send__(:define_method, :id) { @table[:id] }

    @proxy = OpenStruct.new(id: 1, url: 'http://dummy.example.com:9090')

    ProxyAPI::Salt.any_instance.stubs(:key_list).returns(
      'saltstack.example.com' => { 'state' => 'accepted', 'fingerprint' => '98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c0' },
      'saltclient01.example.com' => { 'state' => 'unaccepted', 'fingerprint' => '98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c1' },
      'saltclient02.example.com' => { 'state' => 'unaccepted', 'fingerprint' => '98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c2' },
      'saltclient03.example.com' => { 'state' => 'rejected', 'fingerprint' => '98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c3' }
    )
  end

  test 'key has a name' do
    assert_not_empty ForemanSalt::SmartProxies::SaltKeys.all(@proxy).first.name
  end

  test 'key has a state' do
    assert_not_empty ForemanSalt::SmartProxies::SaltKeys.all(@proxy).first.state
  end

  test 'key has a fingerprint' do
    assert_not_empty ForemanSalt::SmartProxies::SaltKeys.all(@proxy).first.fingerprint
  end

  test 'key has a smart proxy id' do
    assert_equal 1, ForemanSalt::SmartProxies::SaltKeys.all(@proxy).first.smart_proxy_id
  end

  test 'returns all keys' do
    assert_equal 4, ForemanSalt::SmartProxies::SaltKeys.all(@proxy).count
  end

  test 'finds a key by name' do
    assert_equal('saltstack.example.com', ForemanSalt::SmartProxies::SaltKeys.find(@proxy, 'saltstack.example.com').name)
  end

  test 'find keys by state' do
    assert_equal 2, ForemanSalt::SmartProxies::SaltKeys.find_by_state(@proxy, 'unaccepted').count
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
foreman_salt-17.0.0 test/unit/salt_keys_test.rb
foreman_salt-16.0.3 test/unit/salt_keys_test.rb
foreman_salt-16.0.2 test/unit/salt_keys_test.rb
foreman_salt-16.0.1 test/unit/salt_keys_test.rb
foreman_salt-16.0.0 test/unit/salt_keys_test.rb
foreman_salt-15.2.3 test/unit/salt_keys_test.rb
foreman_salt-15.2.2 test/unit/salt_keys_test.rb
foreman_salt-15.2.1 test/unit/salt_keys_test.rb
foreman_salt-15.2.0 test/unit/salt_keys_test.rb
foreman_salt-15.1.0 test/unit/salt_keys_test.rb
foreman_salt-15.0.0 test/unit/salt_keys_test.rb
foreman_salt-14.1.0 test/unit/salt_keys_test.rb