<commit_before>require 'chef_helper'

describe 'registry recipe' do
  let(:chef_run) { ChefSpec::SoloRunner.converge('gitlab::default') }

  before { allow(Gitlab).to receive(:[]).and_call_original }

  context 'when registry is enabled' do
    before { stub_gitlab_rb(registry_external_url: 'https://registry.example.com') }

    it 'creates default set of directories' do
      expect(chef_run.node['gitlab']['registry']['dir'])
        .to eql('/var/opt/gitlab/registry')
      expect(chef_run.node['gitlab']['registry']['log_directory'])
        .to eql('/var/log/gitlab/registry')
      expect(chef_run.node['gitlab']['gitlab-rails']['registry_path'])
        .to eql('/var/opt/gitlab/gitlab-rails/shared/registry')

      expect(chef_run).to create_directory('/var/opt/gitlab/registry')
      expect(chef_run).to create_directory('/var/log/gitlab/registry').with(
        owner: 'registry',
        group: nil,
        mode: '0700'
      )
      expect(chef_run).to create_directory('/var/opt/gitlab/gitlab-rails/shared/registry').with(
        owner: 'registry',
        group: 'git',
        mode: '0750'
      )
    end

    it 'creates default user and group' do
      expect(chef_run.node['gitlab']['registry']['username'])
        .to eql('registry')
      expect(chef_run.node['gitlab']['registry']['group'])
        .to eql('registry')

      expect(chef_run).to create_group('registry').with(
        gid: nil,
        system: true
      )

      expect(chef_run).to create_user('registry').with(
        uid: nil,
        gid: 'registry',
        home: '/var/opt/gitlab/registry',
        system: true
      )
    end

    it 'creates default self signed key-certificate pair' do
      expect(chef_run).to create_file('/var/opt/gitlab/registry/gitlab-registry.crt').with(
        user: 'registry',
        group: 'registry'
      )
      expect(chef_run).to create_file('/var/opt/gitlab/gitlab-rails/etc/gitlab-registry.key').with(
        user: 'git',
        group: 'git'
      )

      expect(chef_run).to render_file('/var/opt/gitlab/registry/gitlab-registry.crt')
        .with_content(/-----BEGIN CERTIFICATE-----/)
      expect(chef_run).to render_file('/var/opt/gitlab/gitlab-rails/etc/gitlab-registry.key')
        .with_content(/-----BEGIN RSA PRIVATE KEY-----/)
    end

    it 'creates registry config.yml template' do
      expect(chef_run).to create_template('/var/opt/gitlab/registry/config.yml').with(
        owner: 'registry',
        group: nil,
        mode: '0644'
      )
      expect(chef_run).to render_file('/var/opt/gitlab/registry/config.yml')
        .with_content(/version: 0.1/)
      expect(chef_run).to render_file('/var/opt/gitlab/registry/config.yml')
        .with_content(/realm: \/jwt\/auth/)
      expect(chef_run).to render_file('/var/opt/gitlab/registry/config.yml')
        .with_content(/addr: localhost:5000/)
    end

    it 'creates a default VERSION file' do
      expect(chef_run).to create_file('/var/opt/gitlab/registry/VERSION').with(
        user: nil,
        group: nil
      )
    end

    it 'creates gitlab-rails config with default values' do
      expect(chef_run).to render_file('/var/opt/gitlab/gitlab-rails/etc/gitlab.yml')
        .with_content(/api_url: http:\/\/localhost:5000/)
    end

  end
  context 'when registry port is specified' do
    before { stub_gitlab_rb(registry_external_url: 'https://registry.example.com', registry: { registry_http_addr: 'localhost:5001' }) }
    it 'creates registry and rails configs with specified value' do
      expect(chef_run).to render_file('/var/opt/gitlab/registry/config.yml')
        .with_content(/addr: localhost:5001/)
      expect(chef_run).to render_file('/var/opt/gitlab/gitlab-rails/etc/gitlab.yml')
        .with_content(/api_url: http:\/\/localhost:5001/)
    end
  end
end
<commit_msg>Add the missing test from an earlier merge request that added the debug_addr for the registry<commit_after>require 'chef_helper'

describe 'registry recipe' do
  let(:chef_run) { ChefSpec::SoloRunner.converge('gitlab::default') }

  before { allow(Gitlab).to receive(:[]).and_call_original }

  context 'when registry is enabled' do
    before { stub_gitlab_rb(registry_external_url: 'https://registry.example.com') }

    it 'creates default set of directories' do
      expect(chef_run.node['gitlab']['registry']['dir'])
        .to eql('/var/opt/gitlab/registry')
      expect(chef_run.node['gitlab']['registry']['log_directory'])
        .to eql('/var/log/gitlab/registry')
      expect(chef_run.node['gitlab']['gitlab-rails']['registry_path'])
        .to eql('/var/opt/gitlab/gitlab-rails/shared/registry')

      expect(chef_run).to create_directory('/var/opt/gitlab/registry')
      expect(chef_run).to create_directory('/var/log/gitlab/registry').with(
        owner: 'registry',
        group: nil,
        mode: '0700'
      )
      expect(chef_run).to create_directory('/var/opt/gitlab/gitlab-rails/shared/registry').with(
        owner: 'registry',
        group: 'git',
        mode: '0750'
      )
    end

    it 'creates default user and group' do
      expect(chef_run.node['gitlab']['registry']['username'])
        .to eql('registry')
      expect(chef_run.node['gitlab']['registry']['group'])
        .to eql('registry')

      expect(chef_run).to create_group('registry').with(
        gid: nil,
        system: true
      )

      expect(chef_run).to create_user('registry').with(
        uid: nil,
        gid: 'registry',
        home: '/var/opt/gitlab/registry',
        system: true
      )
    end

    it 'creates default self signed key-certificate pair' do
      expect(chef_run).to create_file('/var/opt/gitlab/registry/gitlab-registry.crt').with(
        user: 'registry',
        group: 'registry'
      )
      expect(chef_run).to create_file('/var/opt/gitlab/gitlab-rails/etc/gitlab-registry.key').with(
        user: 'git',
        group: 'git'
      )

      expect(chef_run).to render_file('/var/opt/gitlab/registry/gitlab-registry.crt')
        .with_content(/-----BEGIN CERTIFICATE-----/)
      expect(chef_run).to render_file('/var/opt/gitlab/gitlab-rails/etc/gitlab-registry.key')
        .with_content(/-----BEGIN RSA PRIVATE KEY-----/)
    end

    it 'creates registry config.yml template' do
      expect(chef_run).to create_template('/var/opt/gitlab/registry/config.yml').with(
        owner: 'registry',
        group: nil,
        mode: '0644'
      )
      expect(chef_run).to render_file('/var/opt/gitlab/registry/config.yml')
        .with_content(/version: 0.1/)
      expect(chef_run).to render_file('/var/opt/gitlab/registry/config.yml')
        .with_content(/realm: \/jwt\/auth/)
      expect(chef_run).to render_file('/var/opt/gitlab/registry/config.yml')
        .with_content(/addr: localhost:5000/)
    end

    it 'creates a default VERSION file' do
      expect(chef_run).to create_file('/var/opt/gitlab/registry/VERSION').with(
        user: nil,
        group: nil
      )
    end

    it 'creates gitlab-rails config with default values' do
      expect(chef_run).to render_file('/var/opt/gitlab/gitlab-rails/etc/gitlab.yml')
        .with_content(/api_url: http:\/\/localhost:5000/)
    end
  end

  context 'when registry port is specified' do
    before { stub_gitlab_rb(registry_external_url: 'https://registry.example.com', registry: { registry_http_addr: 'localhost:5001' }) }
    it 'creates registry and rails configs with specified value' do
      expect(chef_run).to render_file('/var/opt/gitlab/registry/config.yml')
        .with_content(/addr: localhost:5001/)
      expect(chef_run).to render_file('/var/opt/gitlab/gitlab-rails/etc/gitlab.yml')
        .with_content(/api_url: http:\/\/localhost:5001/)
    end
  end

  context 'when a debug addr is specified' do
    before { stub_gitlab_rb(registry_external_url: 'https://registry.example.com', registry: { debug_addr: 'localhost:5005' }) }

    it 'creates the registry config with the specified debug value' do
      expect(chef_run).to render_file('/var/opt/gitlab/registry/config.yml')
        .with_content(/debug:\n\s*addr: localhost:5005/)
    end
  end
end

{'fraction_non_alphanumeric': 0.15147783251231528, 'fraction_numerical': 0.00935960591133005, 'mean_word_length': 2.9099662975445355, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 5, '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': '5609872', 'n_tokens_mistral': 2748, 'n_tokens_neox': 2615, 'n_words': 456}