<commit_before>require 'spec_helper'

describe 'vault_client' do
    context 'with none of init_token and token specified' do
        it do
            is_expected.to compile.and_raise_error(/provide at least one of/)
        end
    end

    context 'with init_token and token specified' do
        let(:params) { {:init_token => 'ab', :token => 'cd'} }
        it do
            is_expected.to compile.and_raise_error(/must provide either \$init_token or \$token/)
        end
    end

    context "with token 'test-token'" do
        let(:params) { {:token => '<PASSWORD>-token'} }
        it do
            is_expected.to contain_file('/etc/vault/token').with(
                'mode' => '0600',
                'content' => 'test-token'
            )
        end
        it do
            is_expected.to contain_file('/etc/vault/config').with_content(/#{Regexp.escape('VAULT_ADDR=http://127.0.0.1:8200')}/)
        end
        it do
            is_expected.not_to contain_file('/etc/vault/config').with_content(/#{Regexp.escape('VAULT_INIT_ROLE=')}/)
        end
        it do
            is_expected.not_to contain_file('/etc/vault/config').with_content(/#{Regexp.escape('VAULT_INIT_POLICIES=')}/)
        end
    end

    context "with init_token 'test-init-token'" do
        let(:params) do {
            :init_token => 'test-init-token',
            :init_role => 'test-role',
            :init_policies => ['test-policy1', 'test-policy2'],
        }
        end
        it do
            is_expected.to contain_file('/etc/vault/init-token').with(
                'mode' => '0600',
                'content' => 'test-init-token'
            )
        end
        it do
            is_expected.to contain_file('/etc/vault/config').with_content(/#{Regexp.escape('VAULT_ADDR=http://127.0.0.1:8200')}/)
        end
        it do
            is_expected.to contain_file('/etc/vault/config').with_content(/#{Regexp.escape('VAULT_INIT_ROLE=test-role')}/)
        end
        it do
            is_expected.to contain_file('/etc/vault/config').with_content(/#{Regexp.escape('VAULT_INIT_POLICIES=test-policy1,test-policy2')}/)
        end
    end

    context 'with custom version 0.8' do
        let(:params) { {:version => '0.8', :token => 'ab'} }

        #it do
        #    is_expected.to contain_archive('/opt/bin/vault-helper').with(
        #        'source' => 'https://github.com/jetstack-experimental/vault-helper/releases/download/0.8/vault-helper_0.8_linux_amd64'
        #    )
        #end<commit_msg>Uncommented rake test to include syslink to vault-helper<commit_after>require 'spec_helper'

describe 'vault_client' do
    context 'with none of init_token and token specified' do
        it do
            is_expected.to compile.and_raise_error(/provide at least one of/)
        end
    end

    context 'with init_token and token specified' do
        let(:params) { {:init_token => 'ab', :token => 'cd'} }
        it do
            is_expected.to compile.and_raise_error(/must provide either \$init_token or \$token/)
        end
    end

    context "with token 'test-token'" do
        let(:params) { {:token => 'test-token'} }
        it do
            is_expected.to contain_file('/etc/vault/token').with(
                'mode' => '0600',
                'content' => 'test-token'
            )
        end
        it do
            is_expected.to contain_file('/etc/vault/config').with_content(/#{Regexp.escape('VAULT_ADDR=http://127.0.0.1:8200')}/)
        end
        it do
            is_expected.not_to contain_file('/etc/vault/config').with_content(/#{Regexp.escape('VAULT_INIT_ROLE=')}/)
        end
        it do
            is_expected.not_to contain_file('/etc/vault/config').with_content(/#{Regexp.escape('VAULT_INIT_POLICIES=')}/)
        end
    end

    context "with init_token '<PASSWORD>'" do
        let(:params) do {
            :init_token => '<PASSWORD>',
            :init_role => 'test-role',
            :init_policies => ['test-policy1', 'test-policy2'],
        }
        end
        it do
            is_expected.to contain_file('/etc/vault/init-token').with(
                'mode' => '0600',
                'content' => 'test-init-token'
            )
        end
        it do
            is_expected.to contain_file('/etc/vault/config').with_content(/#{Regexp.escape('VAULT_ADDR=http://127.0.0.1:8200')}/)
        end
        it do
            is_expected.to contain_file('/etc/vault/config').with_content(/#{Regexp.escape('VAULT_INIT_ROLE=test-role')}/)
        end
        it do
            is_expected.to contain_file('/etc/vault/config').with_content(/#{Regexp.escape('VAULT_INIT_POLICIES=test-policy1,test-policy2')}/)
        end
    end

    context 'with custom version 0.8' do
        let(:params) { {:version => '0.8', :token => 'ab'} }

        it do
            is_expected.to contain_file('/opt/bin/vault-helper').with(
                'target' => '/opt/vault-helper-0.8/vault-helper'
            )
        end
{'fraction_non_alphanumeric': 0.14420566378790922, 'fraction_numerical': 0.016067483430407713, 'mean_word_length': 2.0145278450363198, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 32, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6686885', 'n_tokens_mistral': 1620, 'n_tokens_neox': 1566, 'n_words': 282}