Sha256: 2c478d1a1f6aeb831a4be8a3b98100ab949aed56b51728b522d4cd6865093e2a

Contents?: true

Size: 1.33 KB

Versions: 4

Compression:

Stored size: 1.33 KB

Contents

require 'test_plugin_helper'

class SaltVariablesTest < ActiveSupport::TestCase
  setup do
    User.current = users :admin
    @state = FactoryBot.create :salt_module
  end

  test 'salt variable has a salt module' do
    salt_variable = ForemanSalt::SaltVariable.new(key: 'awesome_key', salt_module_id: @state.id)

    assert_valid salt_variable
    assert_predicate salt_variable, :salt?
    assert_equal @state.id, salt_variable.salt_module.id
  end

  test 'salt variable is referencing a LookupValue' do
    salt_variable = ForemanSalt::SaltVariable.new(key: 'awesome_key', salt_module_id: @state.id)

    assert_predicate salt_variable.lookup_values.count, :zero?
    LookupValue.create(value: '[1.2.3.4,2.3.4.5]', match: 'domain =  mydomain.net', lookup_key: salt_variable)

    assert_equal(1, salt_variable.lookup_values.count)
  end

  test 'should cast default_value to hash' do
    salt_variable = ForemanSalt::SaltVariable.new(key: 'awesome_key',
                                                  salt_module_id: @state.id,
                                                  key_type: 'hash',
                                                  default_value: "{\r\n  \"bat\": \"man\"\r\n}\r\n",
                                                  override: true)
    salt_variable.save

    assert salt_variable.default_value.is_a?(Hash)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
foreman_salt-17.0.0 test/unit/salt_variables_test.rb
foreman_salt-16.0.3 test/unit/salt_variables_test.rb
foreman_salt-16.0.2 test/unit/salt_variables_test.rb
foreman_salt-16.0.1 test/unit/salt_variables_test.rb