<commit_before>require 'spec_helper'

# Tests for the env script management based on parameters
describe 'aem::osgi::config::file', type: :defines do

  let(:facts) do
    {
      kernel: 'Linux'
    }
  end

  let(:title) do
    'aem'
  end

  let(:default_params) do
    {
      ensure: 'present',
      group: 'aem',
      home: '/opt/aem',
      pid: :undef,
      properties: {
        'boolean'                 => false,
        'long'                    => 123_456_789,
        'string'                  => 'string',
        'array'                   => ['an', 'array', 'of', 'values'],
        'simple_string_literal'   => 'T"simple string"',
        'integer_literal'         => 'I"10"',
        'long_literal'            => 'L"99"',
        'float_literal'           => 'F"3.14"',
        'double_literal'          => 'D"9.99"',
        'byte_literal'            => 'X"Y"',
        'short_literal'           => 'S"100"',
        'character_literal'       => 'C"X"',
        'boolean_literal'         => 'B"false"',
        'unknown_type_literal'    => 'A"foo"',
        'wrong_format_literal'    => 'T"false" ',
      },
      user: 'aem'
    }
  end

  describe 'creates the file' do

    let(:params) do
      default_params
    end

    context 'mode' do
      it { is_expected.to contain_file('/opt/aem/crx-quickstart/install/aem.config').with_mode('0664') }
    end

    context 'group' do
      context 'default' do
        it { is_expected.to contain_file('/opt/aem/crx-quickstart/install/aem.config').with_group('aem') }
      end

      context 'specified group' do
        let(:params) do
          default_params.merge(group: 'vagrant')
        end
        it { is_expected.to contain_file('/opt/aem/crx-quickstart/install/aem.config').with_group('vagrant') }
      end
    end

    context 'user' do
      context 'default' do
        it { is_expected.to contain_file('/opt/aem/crx-quickstart/install/aem.config').with_owner('aem') }
      end

      context 'specified owner' do
        let(:params) do
          default_params.merge(user: 'vagrant')
        end
        it { is_expected.to contain_file('/opt/aem/crx-quickstart/install/aem.config').with_owner('vagrant') }
      end
    end

    context 'service pid' do
      it do
        is_expected.to contain_file(
          '/opt/aem/crx-quickstart/install/aem.config'
        ).with_content(
          /service.pid="aem"\s/
        )
      end
    end

    context 'boolean property' do
      it do
        is_expected.to contain_file(
          '/opt/aem/crx-quickstart/install/aem.config'
        ).with_content(
          /boolean=B"false"\s/
        )
      end
    end

    context 'long property' do

      it do
        is_expected.to contain_file(
          '/opt/aem/crx-quickstart/install/aem.config'
        ).with_content(
          /long=L"123456789"\s/
        )
      end
    end

    context 'string property' do

      it do
        is_expected.to contain_file(
          '/opt/aem/crx-quickstart/install/aem.config'
        ).with_content(
          /string="string"\s/
        )
      end
    end

    context 'array property' do

      it do
        is_expected.to contain_file(
          '/opt/aem/crx-quickstart/install/aem.config'
        ).with_content(
          /array=\["an","array","of","values"\]/
        )
      end
    end
    
    context 'simple string literal' do

      it do
        is_expected.to contain_file(
          '/opt/aem/crx-quickstart/install/aem.config'
        ).with_content(
           /simple_string_literal=L"simple string"\s/
        )
      end
    end

    context 'integer literal' do

      it do
        is_expected.to contain_file(
          '/opt/aem/crx-quickstart/install/aem.config'
        ).with_content(
          /integer_literal=I"10"\s/
        )
      end
    end<commit_msg>Small error in expected value of simple_string_literal.<commit_after>require 'spec_helper'

# Tests for the env script management based on parameters
describe 'aem::osgi::config::file', type: :defines do

  let(:facts) do
    {
      kernel: 'Linux'
    }
  end

  let(:title) do
    'aem'
  end

  let(:default_params) do
    {
      ensure: 'present',
      group: 'aem',
      home: '/opt/aem',
      pid: :undef,
      properties: {
        'boolean'                 => false,
        'long'                    => 123_456_789,
        'string'                  => 'string',
        'array'                   => ['an', 'array', 'of', 'values'],
        'simple_string_literal'   => 'T"simple string"',
        'integer_literal'         => 'I"10"',
        'long_literal'            => 'L"99"',
        'float_literal'           => 'F"3.14"',
        'double_literal'          => 'D"9.99"',
        'byte_literal'            => 'X"Y"',
        'short_literal'           => 'S"100"',
        'character_literal'       => 'C"X"',
        'boolean_literal'         => 'B"false"',
        'unknown_type_literal'    => 'A"foo"',
        'wrong_format_literal'    => 'T"false" ',
      },
      user: 'aem'
    }
  end

  describe 'creates the file' do

    let(:params) do
      default_params
    end

    context 'mode' do
      it { is_expected.to contain_file('/opt/aem/crx-quickstart/install/aem.config').with_mode('0664') }
    end

    context 'group' do
      context 'default' do
        it { is_expected.to contain_file('/opt/aem/crx-quickstart/install/aem.config').with_group('aem') }
      end

      context 'specified group' do
        let(:params) do
          default_params.merge(group: 'vagrant')
        end
        it { is_expected.to contain_file('/opt/aem/crx-quickstart/install/aem.config').with_group('vagrant') }
      end
    end

    context 'user' do
      context 'default' do
        it { is_expected.to contain_file('/opt/aem/crx-quickstart/install/aem.config').with_owner('aem') }
      end

      context 'specified owner' do
        let(:params) do
          default_params.merge(user: 'vagrant')
        end
        it { is_expected.to contain_file('/opt/aem/crx-quickstart/install/aem.config').with_owner('vagrant') }
      end
    end

    context 'service pid' do
      it do
        is_expected.to contain_file(
          '/opt/aem/crx-quickstart/install/aem.config'
        ).with_content(
          /service.pid="aem"\s/
        )
      end
    end

    context 'boolean property' do
      it do
        is_expected.to contain_file(
          '/opt/aem/crx-quickstart/install/aem.config'
        ).with_content(
          /boolean=B"false"\s/
        )
      end
    end

    context 'long property' do

      it do
        is_expected.to contain_file(
          '/opt/aem/crx-quickstart/install/aem.config'
        ).with_content(
          /long=L"123456789"\s/
        )
      end
    end

    context 'string property' do

      it do
        is_expected.to contain_file(
          '/opt/aem/crx-quickstart/install/aem.config'
        ).with_content(
          /string="string"\s/
        )
      end
    end

    context 'array property' do

      it do
        is_expected.to contain_file(
          '/opt/aem/crx-quickstart/install/aem.config'
        ).with_content(
          /array=\["an","array","of","values"\]/
        )
      end
    end
    
    context 'simple string literal' do

      it do
        is_expected.to contain_file(
          '/opt/aem/crx-quickstart/install/aem.config'
        ).with_content(
           /simple_string_literal=T"simple string"\s/
        )
      end
    end

    context 'integer literal' do

      it do
        is_expected.to contain_file(
          '/opt/aem/crx-quickstart/install/aem.config'
        ).with_content(
          /integer_literal=I"10"\s/
        )
      end
    end
{'fraction_non_alphanumeric': 0.13025974025974027, 'fraction_numerical': 0.00961038961038961, 'mean_word_length': 1.721201413427562, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3208347', 'n_tokens_mistral': 2581, 'n_tokens_neox': 2484, 'n_words': 465}