nginx_spec.rb 5.51 KB
Newer Older
Marin Jankovski's avatar
Marin Jankovski committed
1 2 3 4 5 6 7 8
require 'spec_helper'

describe "gitlab::nginx" do
  let(:chef_run) { ChefSpec::Runner.new.converge("gitlab::nginx") }


  describe "under ubuntu" do
    ["12.04", "10.04"].each do |version|
9
      let(:chef_run) do
Marin Jankovski's avatar
Marin Jankovski committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
        runner = ChefSpec::Runner.new(platform: "ubuntu", version: version)
        runner.node.set['gitlab']['env'] = "production"
        runner.converge("gitlab::nginx")
      end

      it "installs nginx" do
        expect(chef_run).to install_package('nginx')
      end

      it 'creates a nginx template with attributes' do
        expect(chef_run).to create_template('/etc/nginx/sites-available/gitlab').with(
          source: 'nginx.erb',
          mode: 0644,
          variables: {
            path: "/home/git/gitlab",
            host: "localhost",
Marin Jankovski's avatar
Marin Jankovski committed
26 27 28 29
            port: "80",
            url: "http://localhost:80/",
            ssl_certificate_path: "/etc/ssl",
            ssl_certificate_key_path: "/etc/ssl"
Marin Jankovski's avatar
Marin Jankovski committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
          }
        )
      end

      it 'does not create a directory' do
        expect(chef_run).to_not create_directory('/home/git').with(
          mode: 0755
        )
      end

      it 'creates a link with attributes' do
        expect(chef_run).to create_link('/etc/nginx/sites-enabled/gitlab').with(to: '/etc/nginx/sites-available/gitlab')
      end

      it 'deletes a default nginx page' do
        expect(chef_run).to delete_file('/etc/nginx/sites-enabled/default')
      end

      it 'restarts nginx service' do
        expect(chef_run).to restart_service('nginx')
      end
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78

      describe "when customizing gitlab user home" do
        let(:chef_run) do
          runner = ChefSpec::Runner.new(platform: "ubuntu", version: version)
          runner.node.set['gitlab']['env'] = "production"
          runner.node.set['gitlab']['home'] = "/data/git"
          runner.converge("gitlab::nginx")
        end

        it 'creates a nginx template with attributes' do
          expect(chef_run).to create_template('/etc/nginx/sites-available/gitlab').with(
            source: 'nginx.erb',
            mode: 0644,
            variables: {
              path: "/data/git/gitlab",
              host: "localhost",
              port: "80",
              url: "http://localhost:80/",
              ssl_certificate_path: "/etc/ssl",
              ssl_certificate_key_path: "/etc/ssl"
            }
          )
        end

        it 'does not create a directory' do
          expect(chef_run).to_not create_directory('/data/git')
        end
      end
79 80 81 82 83 84 85 86 87 88 89 90 91

      describe "when customizing install_nginx" do
        let(:chef_run) do
          runner = ChefSpec::Runner.new(platform: "ubuntu", version: version)
          runner.node.set['gitlab']['env'] = "production"
          runner.node.set['gitlab']['install_nginx'] = false
          runner.converge("gitlab::nginx")
        end

        it 'does not install nginx' do
          expect(chef_run).to_not install_package('nginx')
        end
      end
Marin Jankovski's avatar
Marin Jankovski committed
92 93 94 95 96
    end
  end

    describe "under centos" do
    ["5.8", "6.4"].each do |version|
97
      let(:chef_run) do
Marin Jankovski's avatar
Marin Jankovski committed
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
        runner = ChefSpec::Runner.new(platform: "centos", version: version)
        runner.node.set['gitlab']['env'] = "production"
        runner.converge("gitlab::nginx")
      end

      it "installs nginx" do
        expect(chef_run).to install_package('nginx')
      end

      it 'creates a nginx template with attributes' do
        expect(chef_run).to create_template('/etc/nginx/conf.d/gitlab.conf').with(
          source: 'nginx.erb',
          mode: 0644,
          variables: {
            path: "/home/git/gitlab",
            host: "localhost",
Marin Jankovski's avatar
Marin Jankovski committed
114 115 116 117
            port: "80",
            url: "http://localhost:80/",
            ssl_certificate_path: "/etc/ssl",
            ssl_certificate_key_path: "/etc/ssl"
Marin Jankovski's avatar
Marin Jankovski committed
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
          }
        )
      end

      it 'creates a directory' do
        expect(chef_run).to create_directory('/home/git').with(
          mode: 0755
        )
      end

      it 'does not create a link' do
        expect(chef_run).to_not create_link('/etc/nginx/sites-enabled/gitlab').with(to: '/etc/nginx/sites-available/gitlab')
      end

      it 'restarts nginx service' do
        expect(chef_run).to restart_service('nginx')
      end
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162

      describe "when customizing gitlab user home" do
        let(:chef_run) do
          runner = ChefSpec::Runner.new(platform: "centos", version: version)
          runner.node.set['gitlab']['env'] = "production"
          runner.node.set['gitlab']['home'] = "/data/git"
          runner.converge("gitlab::nginx")
        end

        it 'creates a nginx template with attributes' do
          expect(chef_run).to create_template('/etc/nginx/conf.d/gitlab.conf').with(
            source: 'nginx.erb',
            mode: 0644,
            variables: {
              path: "/data/git/gitlab",
              host: "localhost",
              port: "80",
              url: "http://localhost:80/",
              ssl_certificate_path: "/etc/ssl",
              ssl_certificate_key_path: "/etc/ssl"
            }
          )
        end

        it 'creates a directory' do
          expect(chef_run).to create_directory('/data/git')
        end
      end
163 164 165 166 167 168 169 170 171 172 173 174 175

      describe "when customizing install_nginx" do
        let(:chef_run) do
          runner = ChefSpec::Runner.new(platform: "centos", version: version)
          runner.node.set['gitlab']['env'] = "production"
          runner.node.set['gitlab']['install_nginx'] = false
          runner.converge("gitlab::nginx")
        end

        it 'does not install nginx' do
          expect(chef_run).to_not install_package('nginx')
        end
      end
Marin Jankovski's avatar
Marin Jankovski committed
176 177
    end
  end
Marin Jankovski's avatar
Marin Jankovski committed
178
end