<commit_before>require 'spec_helper'

describe Bosh::Deployer::Specification do
  subject(:spec) do
    Bosh::Deployer::Specification.new(spec_hash, config)
  end
  let(:spec_hash) { YAML.load_file(spec_asset('apply_spec.yml')) }

  let(:agent_properties) { {} }
  let(:spec_properties) { {} }

  let(:config) do
    instance_double(
      'Bosh::Deployer::Configuration',
      name: nil,
      agent_properties: agent_properties,
      spec_properties: spec_properties,
    )
  end

  describe '.load_from_stemcell' do
    let(:spec) { Bosh::Deployer::Specification.load_from_stemcell(spec_dir, config) }
    let(:spec_dir) { File.dirname(spec_asset('apply_spec.yml')) }

    it 'loads from file' do
      expect(spec.director_port).to eq 25555
    end
  end

  context 'when the agent services are included in the apply_spec' do
    let(:services) { %w{blobstore nats} }

    before do
      spec_hash['properties']['agent'] ||= {}
      services.each do |service|
        spec_hash['properties']['agent'][service] ||= {}
      end
    end

    it 'updates the agent service addresses' do
      spec.update('1.1.1.1', '2.2.2.2')
      services.each do |service|
        expect(spec.properties['agent'][service]['address']).to eq '1.1.1.1'
      end
    end
  end

  context 'when the agent services are not included in the apply_spec' do
    let(:services) { %w{blobstore nats} }

    before do
      spec_hash['properties']['agent'] ||= {}
      services.each do |service|
        spec_hash['properties']['agent'].delete(service)
      end
    end

    it 'updates the agent service addresses' do
      spec.update('1.1.1.1', '2.2.2.2')
      services.each do |service|
        expect(spec.properties['agent'][service]['address']).to eq '1.1.1.1'
      end
    end
  end

  context 'when the services are included in the apply_spec' do
    let(:agent_services) { %w{registry dns} }
    let(:internal_services) { %w{director blobstore nats} }

    before do
      (agent_services + internal_services).each do |service|
        spec_hash['properties'][service] ||= {}
      end
    end

    it 'updates the service addresses to the internal services ip' do
      spec.update('1.1.1.1', '2.2.2.2')

      agent_services.each do |service|
        expect(spec.properties[service]['address']).to eq '1.1.1.1'
      end
      internal_services.each do |service|
        puts service
        expect(spec.properties[service]['address']).to eq '2.2.2.2'
      end
    end
  end

  context 'when there are services not included in the apply_spec' do
    let(:services) { %w{director blobstore nats registry dns} }

    before do
      services.each do |service|
        spec_hash['properties'].delete(service)
      end
    end

    it 'does not update service addresses for services not included in apply_spec.yml' do
      spec.update('1.1.1.1', '2.2.2.2')

      services.each do |service|
        expect(spec.properties).to_not have_key(service)
      end
    end
  end

  describe 'agent override' do
    let(:agent_properties) { { 'blobstore' => { 'address' => '3.3.3.3' } } }
    let(:spec_properties) { { 'ntp' => %w[1.2.3.4] } }

    it 'updates blobstore address with agent_properties override' do
      spec.update('1.1.1.1', '2.2.2.2')
      expect(spec.properties['agent']['blobstore']['address']).to eq '3.3.3.3'
    end<commit_msg>Debug logging removal<commit_after>require 'spec_helper'

describe Bosh::Deployer::Specification do
  subject(:spec) do
    Bosh::Deployer::Specification.new(spec_hash, config)
  end
  let(:spec_hash) { YAML.load_file(spec_asset('apply_spec.yml')) }

  let(:agent_properties) { {} }
  let(:spec_properties) { {} }

  let(:config) do
    instance_double(
      'Bosh::Deployer::Configuration',
      name: nil,
      agent_properties: agent_properties,
      spec_properties: spec_properties,
    )
  end

  describe '.load_from_stemcell' do
    let(:spec) { Bosh::Deployer::Specification.load_from_stemcell(spec_dir, config) }
    let(:spec_dir) { File.dirname(spec_asset('apply_spec.yml')) }

    it 'loads from file' do
      expect(spec.director_port).to eq 25555
    end
  end

  context 'when the agent services are included in the apply_spec' do
    let(:services) { %w{blobstore nats} }

    before do
      spec_hash['properties']['agent'] ||= {}
      services.each do |service|
        spec_hash['properties']['agent'][service] ||= {}
      end
    end

    it 'updates the agent service addresses' do
      spec.update('1.1.1.1', '2.2.2.2')
      services.each do |service|
        expect(spec.properties['agent'][service]['address']).to eq '1.1.1.1'
      end
    end
  end

  context 'when the agent services are not included in the apply_spec' do
    let(:services) { %w{blobstore nats} }

    before do
      spec_hash['properties']['agent'] ||= {}
      services.each do |service|
        spec_hash['properties']['agent'].delete(service)
      end
    end

    it 'updates the agent service addresses' do
      spec.update('1.1.1.1', '2.2.2.2')
      services.each do |service|
        expect(spec.properties['agent'][service]['address']).to eq '1.1.1.1'
      end
    end
  end

  context 'when the services are included in the apply_spec' do
    let(:agent_services) { %w{registry dns} }
    let(:internal_services) { %w{director blobstore nats} }

    before do
      (agent_services + internal_services).each do |service|
        spec_hash['properties'][service] ||= {}
      end
    end

    it 'updates the service addresses to the internal services ip' do
      spec.update('1.1.1.1', '2.2.2.2')

      agent_services.each do |service|
        expect(spec.properties[service]['address']).to eq '1.1.1.1'
      end
      internal_services.each do |service|
        expect(spec.properties[service]['address']).to eq '2.2.2.2'
      end
    end
  end

  context 'when there are services not included in the apply_spec' do
    let(:services) { %w{director blobstore nats registry dns} }

    before do
      services.each do |service|
        spec_hash['properties'].delete(service)
      end
    end

    it 'does not update service addresses for services not included in apply_spec.yml' do
      spec.update('1.1.1.1', '2.2.2.2')

      services.each do |service|
        expect(spec.properties).to_not have_key(service)
      end
    end
  end

  describe 'agent override' do
    let(:agent_properties) { { 'blobstore' => { 'address' => '3.3.3.3' } } }
    let(:spec_properties) { { 'ntp' => %w[1.2.3.4] } }

    it 'updates blobstore address with agent_properties override' do
      spec.update('1.1.1.1', '2.2.2.2')
      expect(spec.properties['agent']['blobstore']['address']).to eq '3.3.3.3'
    end
{'fraction_non_alphanumeric': 0.13953488372093023, 'fraction_numerical': 0.021905476369092274, 'mean_word_length': 2.9844590555887627, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 34, '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': '7660577', 'n_tokens_mistral': 2221, 'n_tokens_neox': 2163, 'n_words': 511}