<commit_before># frozen_string_literal: true

require 'spec_helper'

describe 'apt::mark', type: :define do
  let :title do
    'my_source'
  end

  let :facts do
    {
      os: {
        family: 'Debian',
        name: 'Debian',
        release: {
          major: '9',
          full: '9.0',
        },
        distro: {
          codename: 'stretch',
          id: 'Debian',
        },
      },
    }
  end

  context 'with correct seting' do
    let :params do
      {
        'setting' => 'manual',
      }
    end

    it {
      is_expected.to contain_exec('/usr/bin/apt-mark manual my_source')
    }
  end

  describe 'with wrong setting' do
    let :params do
      {
        'setting' => 'foobar',
      }
    end

    it do
      is_expected.to raise_error(Puppet::PreformattedError, %r{expects a match for Enum\['auto', 'hold', 'manual', 'unhold'\], got 'foobar'})
    end
  end
end<commit_msg>Add spec tests for apt-mark<commit_after># frozen_string_literal: true

require 'spec_helper'

describe 'apt::mark', type: :define do
  let :title do
    'my_source'
  end

  let :facts do
    {
      os: {
        family: 'Debian',
        name: 'Debian',
        release: {
          major: '9',
          full: '9.0',
        },
        distro: {
          codename: 'stretch',
          id: 'Debian',
        },
      },
    }
  end

  context 'with correct seting' do
    let :params do
      {
        'setting' => 'manual',
      }
    end

    it {
      is_expected.to contain_exec('apt-mark manual my_source')
    }
  end

  describe 'with wrong setting' do
    let :params do
      {
        'setting' => 'foobar',
      }
    end

    it do
      is_expected.to raise_error(Puppet::PreformattedError, %r{expects a match for Enum\['auto', 'hold', 'manual', 'unhold'\], got 'foobar'})
    end
  end

  [
    'package',
    'package1',
    'package_name',
    'package-name',
  ].each do |value|
    describe 'with a valid resource title' do
      let :title do
        value
      end

      let :params do
        {
          'setting' => 'manual',
        }
      end

      it do
        is_expected.to contain_exec("apt-mark manual #{title}")
      end
    end
  end

  [
    '|| ls -la ||',
    'packakge with space',
    'package<>|',
    '|| touch /tmp/foo.txt ||',
  ].each do |value|
    describe 'with an invalid resource title' do
      let :title do
        value
      end

      let :params do
        {
          'setting' => 'manual',
        }
      end

      it do
        is_expected.to raise_error(Puppet::PreformattedError, %r{Invalid package name: #{title}})
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.12718964204112718, 'fraction_numerical': 0.0026656511805026656, 'mean_word_length': 1.722279792746114, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 10, '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': '4408317', 'n_tokens_mistral': 903, 'n_tokens_neox': 866, 'n_words': 235}