gitlab_shell_install_spec.rb 6.5 KB
Newer Older
Marin Jankovski's avatar
Marin Jankovski committed
1 2
require 'spec_helper'

3 4
describe "gitlab::gitlab_shell_install" do
  let(:chef_run) { ChefSpec::Runner.new.converge("gitlab::gitlab_shell_install") }
Marin Jankovski's avatar
Marin Jankovski committed
5 6 7 8 9 10 11


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

      it 'creates a gitlab shell config' do
        expect(chef_run).to create_template('/home/git/gitlab-shell/config.yml').with(
          source: 'gitlab_shell.yml.erb',
          variables: {
            user: "git",
            home: "/home/git",
Marin Jankovski's avatar
Marin Jankovski committed
21
            url: "http://localhost:80/",
Marin Jankovski's avatar
Marin Jankovski committed
22 23 24 25
            repos_path: "/home/git/repositories",
            redis_path: "/usr/local/bin/redis-cli",
            redis_host: "127.0.0.1",
            redis_port: "6379",
26
            namespace: "resque:gitlab",
27 28
            self_signed_cert: false,
            max_size: "5242880"
Marin Jankovski's avatar
Marin Jankovski committed
29 30 31 32
          }
        )
      end

33 34 35 36 37 38 39
      it 'creates repository directory in the gitlab user home directory' do
        expect(chef_run).to create_directory("/home/git/repositories").with(
          user: 'git',
          group: 'git',
          mode: 02770
        )
      end
Marin Jankovski's avatar
Marin Jankovski committed
40

41 42 43 44 45 46 47
      it 'creates .ssh directory in the gitlab user home directory' do
        expect(chef_run).to create_directory("/home/git/.ssh").with(
          user: 'git',
          group: 'git',
          mode: 0700
        )
      end
Marin Jankovski's avatar
Marin Jankovski committed
48

49 50 51 52 53 54
      it 'creates authorized hosts file in .ssh directory' do
        expect(chef_run).to create_file_if_missing("/home/git/.ssh/authorized_keys").with(
          user: 'git',
          group: 'git',
          mode: 0600
        )
Marin Jankovski's avatar
Marin Jankovski committed
55 56 57 58 59
      end

      it 'does not run a execute to install gitlab shell on its own' do
        expect(chef_run).to_not run_execute('gitlab-shell install')
      end
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80

      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::gitlab_shell_install")
        end

        it 'creates a gitlab shell config' do
          expect(chef_run).to create_template('/data/git/gitlab-shell/config.yml').with(
            source: 'gitlab_shell.yml.erb',
            variables: {
              user: "git",
              home: "/data/git",
              url: "http://localhost:80/",
              repos_path: "/data/git/repositories",
              redis_path: "/usr/local/bin/redis-cli",
              redis_host: "127.0.0.1",
              redis_port: "6379",
              namespace: "resque:gitlab",
81 82
              self_signed_cert: false,
              max_size: "5242880"
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
            }
          )
        end

        it 'creates repository directory in the gitlab user home directory' do
          expect(chef_run).to create_directory("/data/git/repositories")
        end

        it 'creates .ssh directory in the gitlab user home directory' do
          expect(chef_run).to create_directory("/data/git/.ssh")
        end

        it 'creates authorized hosts file in .ssh directory' do
          expect(chef_run).to create_file_if_missing("/data/git/.ssh/authorized_keys")
        end
      end
Marin Jankovski's avatar
Marin Jankovski committed
99 100 101 102 103 104 105 106
    end
  end

  describe "under centos" do
    ["5.8", "6.4"].each do |version|
      let(:chef_run) do 
        runner = ChefSpec::Runner.new(platform: "centos", version: version)
        runner.node.set['gitlab']['env'] = "production"
107
        runner.converge("gitlab::gitlab_shell_install")
Marin Jankovski's avatar
Marin Jankovski committed
108 109 110 111 112 113 114 115
      end

      it 'creates a gitlab shell config' do
        expect(chef_run).to create_template('/home/git/gitlab-shell/config.yml').with(
          source: 'gitlab_shell.yml.erb',
          variables: {
            user: "git",
            home: "/home/git",
Marin Jankovski's avatar
Marin Jankovski committed
116
            url: "http://localhost:80/",
Marin Jankovski's avatar
Marin Jankovski committed
117 118 119 120
            repos_path: "/home/git/repositories",
            redis_path: "/usr/local/bin/redis-cli",
            redis_host: "127.0.0.1",
            redis_port: "6379",
121
            namespace: "resque:gitlab",
122 123
            self_signed_cert: false,
            max_size: "5242880"
Marin Jankovski's avatar
Marin Jankovski committed
124 125 126 127
          }
        )
      end

128 129 130 131 132 133 134
      it 'creates repository directory in the gitlab user home directory' do
        expect(chef_run).to create_directory("/home/git/repositories").with(
          user: 'git',
          group: 'git',
          mode: 02770
        )
      end
Marin Jankovski's avatar
Marin Jankovski committed
135

136 137 138 139 140 141 142
      it 'creates .ssh directory in the gitlab user home directory' do
        expect(chef_run).to create_directory("/home/git/.ssh").with(
          user: 'git',
          group: 'git',
          mode: 0700
        )
      end
Marin Jankovski's avatar
Marin Jankovski committed
143

144 145 146 147 148 149
      it 'creates authorized hosts file in .ssh directory' do
        expect(chef_run).to create_file_if_missing("/home/git/.ssh/authorized_keys").with(
          user: 'git',
          group: 'git',
          mode: 0600
        )
Marin Jankovski's avatar
Marin Jankovski committed
150 151 152 153 154
      end

      it 'does not run a execute to install gitlab shell on its own' do
        expect(chef_run).to_not run_execute('gitlab-shell install')
      end
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175

      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::gitlab_shell_install")
        end

        it 'creates a gitlab shell config' do
          expect(chef_run).to create_template('/data/git/gitlab-shell/config.yml').with(
            source: 'gitlab_shell.yml.erb',
            variables: {
              user: "git",
              home: "/data/git",
              url: "http://localhost:80/",
              repos_path: "/data/git/repositories",
              redis_path: "/usr/local/bin/redis-cli",
              redis_host: "127.0.0.1",
              redis_port: "6379",
              namespace: "resque:gitlab",
176 177
              self_signed_cert: false,
              max_size: "5242880"
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
            }
          )
        end

        it 'creates repository directory in the gitlab user home directory' do
          expect(chef_run).to create_directory("/data/git/repositories")
        end

        it 'creates .ssh directory in the gitlab user home directory' do
          expect(chef_run).to create_directory("/data/git/.ssh")
        end

        it 'creates authorized hosts file in .ssh directory' do
          expect(chef_run).to create_file_if_missing("/data/git/.ssh/authorized_keys")
        end
      end
Marin Jankovski's avatar
Marin Jankovski committed
194 195 196
    end
  end
end