<commit_before>#
# Cookbook Name:: pacifica
# Spec:: pacifica_archiveinterface
#
# Copyright (c) 2016 The Authors, All Rights Reserved.

require 'spec_helper'

describe 'test::pacifica_base' do
  base_resource = {
    pacifica_archiveinterface: 'archiveinterface',
    pacifica_cartfrontend: 'cartwsgi',
    pacifica_cartbackend: 'cartd',
    pacifica_metadata: 'metadata',
    pacifica_policy: 'policy',
    pacifica_uniqueid: 'uniqueid',
    pacifica_ingestbackend: 'ingestd',
    pacifica_ingestfrontend: 'ingestwsgi',
    pacifica_uploaderbackend: 'uploaderd',
    pacifica_uploaderfrontend: 'uploaderwsgi',
  }
  before do
    allow_any_instance_of(Chef::Recipe).to receive(:include_recipe).and_call_original
    allow(File).to receive(:exist?).and_call_original
    base_resource.each_value do |resource_value|
      allow(File).to receive(:exist?).with(
        "/opt/#{resource_value}/source/setup.py"
      ).and_return(true)
      stub_command("setup.py install --prefix /opt/#{resource_value}/virtualenv").and_return(true)
    end
    stub_command(%r{/ls \/.*\/config.php/}).and_return(false)
    stub_command('/usr/sbin/apache2 -t').and_return(true)
    stub_command('/usr/sbin/httpd -t').and_return(true)
  end
  supported_platforms.each do |platform, versions|
    versions.each do |version|
      context "on an #{platform.capitalize}-#{version} box" do
        cached(:chef_run) do
          ChefSpec::ServerRunner.new(
            platform: platform, version: version, step_into: base_resource.keys
          ) do |node, server|
            server.create_data_bag('pacifica',
              {
                'uploader' => {
                  id: 'uploader',
                  config: 'this is the config'
                }
              }
            )
          end.converge(described_recipe)
        end

        base_resource.each do |resource_key, resource_value|
          it "#{resource_key}:  Installs the #{resource_value} packages" do
            expect(chef_run).to install_package("#{resource_value}_packages")
          end

          it "#{resource_key}:  Converges successfully for #{resource_value}" do
            expect { chef_run }.to_not raise_error
          end

          it "#{resource_key}:  Installs git client" do
            expect(chef_run).to install_git_client(resource_value)<commit_msg>cookstyle fixes<commit_after>#
# Cookbook Name:: pacifica
# Spec:: pacifica_archiveinterface
#
# Copyright (c) 2016 The Authors, All Rights Reserved.

require 'spec_helper'

describe 'test::pacifica_base' do
  base_resource = {
    pacifica_archiveinterface: 'archiveinterface',
    pacifica_cartfrontend: 'cartwsgi',
    pacifica_cartbackend: 'cartd',
    pacifica_metadata: 'metadata',
    pacifica_policy: 'policy',
    pacifica_uniqueid: 'uniqueid',
    pacifica_ingestbackend: 'ingestd',
    pacifica_ingestfrontend: 'ingestwsgi',
    pacifica_uploaderbackend: 'uploaderd',
    pacifica_uploaderfrontend: 'uploaderwsgi',
  }
  before do
    allow_any_instance_of(Chef::Recipe).to receive(:include_recipe).and_call_original
    allow(File).to receive(:exist?).and_call_original
    base_resource.each_value do |resource_value|
      allow(File).to receive(:exist?).with(
        "/opt/#{resource_value}/source/setup.py"
      ).and_return(true)
      stub_command("setup.py install --prefix /opt/#{resource_value}/virtualenv").and_return(true)
    end
    stub_command(%r{/ls \/.*\/config.php/}).and_return(false)
    stub_command('/usr/sbin/apache2 -t').and_return(true)
    stub_command('/usr/sbin/httpd -t').and_return(true)
  end
  supported_platforms.each do |platform, versions|
    versions.each do |version|
      context "on an #{platform.capitalize}-#{version} box" do
        cached(:chef_run) do
          ChefSpec::ServerRunner.new(
            platform: platform, version: version, step_into: base_resource.keys
          ) do |_node, server|
            server.create_data_bag(
              'pacifica',
              'uploader' => {
                id: 'uploader',
                config: 'this is the config',
              }
            )
          end.converge(described_recipe)
        end

        base_resource.each do |resource_key, resource_value|
          it "#{resource_key}:  Installs the #{resource_value} packages" do
            expect(chef_run).to install_package("#{resource_value}_packages")
          end

          it "#{resource_key}:  Converges successfully for #{resource_value}" do
            expect { chef_run }.to_not raise_error
          end

          it "#{resource_key}:  Installs git client" do
            expect(chef_run).to install_git_client(resource_value)
{'fraction_non_alphanumeric': 0.11464831146483115, 'fraction_numerical': 0.0021510002151000217, 'mean_word_length': 2.97775876817793, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4925119', 'n_tokens_mistral': 1444, 'n_tokens_neox': 1439, 'n_words': 271}