Commit fdfb6262 authored by Matthieu Vachon's avatar Matthieu Vachon

Added new specs for change gitlab user home feature

 * Trying to minize duplication by only checking stuff that changes
   when gitlab user home directory is customized.
parent 139efd72
......@@ -6,7 +6,7 @@ describe "gitlab::clone" do
describe "under ubuntu" do
["12.04", "10.04"].each do |version|
let(:chef_run) do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "ubuntu", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.converge("gitlab::clone", "gitlab::start")
......@@ -22,7 +22,7 @@ describe "gitlab::clone" do
end
describe "in development" do
let(:chef_run) do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "ubuntu", version: version)
runner.node.set['gitlab']['env'] = "development"
runner.converge("gitlab::clone", "gitlab::start")
......@@ -37,12 +37,30 @@ describe "gitlab::clone" do
)
end
end
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::clone", "gitlab::start")
end
it "clones the gitlab repository" do
expect(chef_run).to sync_git('/data/git/gitlab').with(
repository: 'https://github.com/gitlabhq/gitlabhq.git',
revision: '6-7-stable',
user: 'git',
group: 'git'
)
end
end
end
end
describe "under centos" do
["5.8", "6.4"].each do |version|
let(:chef_run) do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "centos", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.converge("gitlab::clone", "gitlab::start")
......@@ -58,7 +76,7 @@ describe "gitlab::clone" do
end
describe "in development" do
let(:chef_run) do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "centos", version: version)
runner.node.set['gitlab']['env'] = "development"
runner.converge("gitlab::clone", "gitlab::start")
......@@ -73,6 +91,24 @@ describe "gitlab::clone" do
)
end
end
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::clone", "gitlab::start")
end
it "clones the gitlab repository" do
expect(chef_run).to sync_git('/data/git/gitlab').with(
repository: 'https://github.com/gitlabhq/gitlabhq.git',
revision: '6-7-stable',
user: 'git',
group: 'git'
)
end
end
end
end
end
......@@ -95,6 +95,60 @@ describe "gitlab::gems" do
end
end
end
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::gems")
end
it 'creates a gemrc from template' do
expect(chef_run).to create_template('/data/git/.gemrc')
end
it 'executes bundle without development and test' do
resource = chef_run.find_resource(:execute, 'bundle install')
expect(resource.cwd).to eq("/data/git/gitlab")
end
describe "when using mysql" do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "ubuntu", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.node.set['gitlab']['database_adapter'] = "mysql"
runner.node.set['gitlab']['database_password'] = "datapass"
runner.node.set['mysql']['server_root_password'] = "rootpass"
runner.node.set['mysql']['server_repl_password'] = "replpass"
runner.node.set['mysql']['server_debian_password'] = "debpass"
runner.node.set['gitlab']['home'] = "/data/git"
runner.converge("gitlab::gems")
end
it 'executes bundle without postgres' do
resource = chef_run.find_resource(:execute, 'bundle install')
expect(resource.cwd).to eq("/data/git/gitlab")
end
end
describe "when using postgres" do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "ubuntu", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.node.set['gitlab']['database_adapter'] = "postgresql"
runner.node.set['gitlab']['database_password'] = "datapass"
runner.node.set['postgresql']['password']['postgres'] = "psqlpass"
runner.node.set['gitlab']['home'] = "/data/git"
runner.converge("gitlab::gems")
end
it 'executes bundle without mysql' do
resource = chef_run.find_resource(:execute, 'bundle install')
expect(resource.cwd).to eq("/data/git/gitlab")
end
end
end
end
end
......@@ -189,6 +243,60 @@ describe "gitlab::gems" do
end
end
end
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::gems")
end
it 'creates a gemrc from template' do
expect(chef_run).to create_template('/data/git/.gemrc')
end
it 'executes bundle without development and test' do
resource = chef_run.find_resource(:execute, 'bundle install')
expect(resource.cwd).to eq("/data/git/gitlab")
end
describe "when using mysql" do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "centos", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.node.set['gitlab']['database_adapter'] = "mysql"
runner.node.set['gitlab']['database_password'] = "datapass"
runner.node.set['mysql']['server_root_password'] = "rootpass"
runner.node.set['mysql']['server_repl_password'] = "replpass"
runner.node.set['mysql']['server_debian_password'] = "debpass"
runner.node.set['gitlab']['home'] = "/data/git"
runner.converge("gitlab::gems")
end
it 'executes bundle without postgres' do
resource = chef_run.find_resource(:execute, 'bundle install')
expect(resource.cwd).to eq("/data/git/gitlab")
end
end
describe "when using postgres" do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "centos", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.node.set['gitlab']['database_adapter'] = "postgresql"
runner.node.set['gitlab']['database_password'] = "datapass"
runner.node.set['postgresql']['password']['postgres'] = "psqlpass"
runner.node.set['gitlab']['home'] = "/data/git"
runner.converge("gitlab::gems")
end
it 'executes bundle without mysql' do
resource = chef_run.find_resource(:execute, 'bundle install')
expect(resource.cwd).to eq("/data/git/gitlab")
end
end
end
end
end
end
......@@ -6,7 +6,7 @@ describe "gitlab::gitlab_shell_clone" do
describe "under ubuntu" do
["12.04", "10.04"].each do |version|
let(:chef_run) do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "ubuntu", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.converge("gitlab::gitlab_shell_clone")
......@@ -22,7 +22,7 @@ describe "gitlab::gitlab_shell_clone" do
end
describe "in development" do
let(:chef_run) do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "ubuntu", version: version)
runner.node.set['gitlab']['env'] = "development"
runner.converge("gitlab::gitlab_shell_clone")
......@@ -37,12 +37,25 @@ describe "gitlab::gitlab_shell_clone" do
)
end
end
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_clone")
end
it "clones the gitlab-shell repository" do
expect(chef_run).to sync_git('/data/git/gitlab-shell')
end
end
end
end
describe "under centos" do
["5.8", "6.4"].each do |version|
let(:chef_run) do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "centos", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.converge("gitlab::gitlab_shell_clone")
......@@ -58,7 +71,7 @@ describe "gitlab::gitlab_shell_clone" do
end
describe "in development" do
let(:chef_run) do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "centos", version: version)
runner.node.set['gitlab']['env'] = "development"
runner.converge("gitlab::gitlab_shell_clone")
......@@ -73,6 +86,19 @@ describe "gitlab::gitlab_shell_clone" do
)
end
end
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_clone")
end
it "clones the gitlab-shell repository" do
expect(chef_run).to sync_git('/data/git/gitlab-shell')
end
end
end
end
end
......@@ -56,6 +56,44 @@ describe "gitlab::gitlab_shell_install" do
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
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",
self_signed_cert: false
}
)
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
end
end
......@@ -111,6 +149,44 @@ describe "gitlab::gitlab_shell_install" do
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
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",
self_signed_cert: false
}
)
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
end
end
end
......@@ -278,6 +278,17 @@ describe "gitlab::install" do
describe "creating gitlab init" do
describe "for production" do
it 'creates gitlab default configuration file' do
expect(chef_run).to create_template('/etc/default/gitlab').with(
source: 'gitlab.default.erb',
mode: 0755,
variables: {
app_user: 'git',
app_root: '/home/git/gitlab'
}
)
end
# TODO Write the test that will check if notification is triggered within the ruby_block
it 'triggers service defaults update' do
expect(chef_run).to run_ruby_block('Copy from example gitlab init config')
......@@ -301,6 +312,105 @@ describe "gitlab::install" do
end
end
end
describe "when customizing gitlab user home" do
# Only test stuff that change when git user home is different
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::start","gitlab::install")
end
it 'creates a gitlab config' do
expect(chef_run).to create_template('/data/git/gitlab/config/database.yml')
end
it 'updates git config' do
resource = chef_run.find_resource(:bash, 'git config')
expect(resource.environment).to eq('HOME' =>"/data/git")
end
it 'creates required directories in the rails root' do
%w{log tmp tmp/pids tmp/sockets public/uploads}.each do |path|
expect(chef_run).to create_directory("/data/git/gitlab/#{path}").with(
user: 'git',
group: 'git',
mode: 0755
)
end
end
it 'creates satellites directory' do
expect(chef_run).to create_directory("/data/git/gitlab-satellites")
end
it 'creates a unicorn config' do
expect(chef_run).to create_template('/data/git/gitlab/config/unicorn.rb')
end
describe "when using mysql" do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "ubuntu", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.node.set['gitlab']['database_adapter'] = "mysql"
runner.node.set['gitlab']['database_password'] = "datapass"
runner.node.set['gitlab']['home'] = "/data/git"
runner.converge("gitlab::start","gitlab::install")
end
it 'creates a database config' do
expect(chef_run).to create_template('/data/git/gitlab/config/database.yml')
end
end
describe "when using postgresql" do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "ubuntu", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.node.set['gitlab']['database_adapter'] = "postgresql"
runner.node.set['gitlab']['database_password'] = "datapass"
runner.node.set['gitlab']['home'] = "/data/git"
runner.converge("gitlab::start","gitlab::install")
end
it 'creates a database config' do
expect(chef_run).to create_template('/data/git/gitlab/config/database.yml')
end
end
describe "running database setup, migrations and seed when production" do
it 'runs db setup' do
resource = chef_run.find_resource(:execute, 'rake db:schema:load')
expect(resource.cwd).to eq("/data/git/gitlab")
end
it 'runs db migrate' do
resource = chef_run.find_resource(:execute, 'rake db:migrate')
expect(resource.cwd).to eq("/data/git/gitlab")
end
it 'runs db seed' do
resource = chef_run.find_resource(:execute, 'rake db:seed_fu')
expect(resource.cwd).to eq("/data/git/gitlab")
end
end
describe "creating gitlab init" do
describe "for production" do
it 'creates gitlab default configuration file' do
expect(chef_run).to create_template('/etc/default/gitlab').with(
source: 'gitlab.default.erb',
mode: 0755,
variables: {
app_user: 'git',
app_root: '/data/git/gitlab'
}
)
end
end
end
end
end
end
......@@ -582,6 +692,17 @@ describe "gitlab::install" do
describe "creating gitlab init" do
describe "for production" do
it 'creates gitlab default configuration file' do
expect(chef_run).to create_template('/etc/default/gitlab').with(
source: 'gitlab.default.erb',
mode: 0755,
variables: {
app_user: 'git',
app_root: '/home/git/gitlab'
}
)
end
# TODO Write the test that will check if notification is triggered within the ruby_block
it 'triggers service defaults update' do
expect(chef_run).to run_ruby_block('Copy from example gitlab init config')
......@@ -605,6 +726,105 @@ describe "gitlab::install" do
end
end
end
describe "when customizing gitlab user home" do
# Only test stuff that change when git user home is different
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::start","gitlab::install")
end
it 'creates a gitlab config' do
expect(chef_run).to create_template('/data/git/gitlab/config/database.yml')
end
it 'updates git config' do
resource = chef_run.find_resource(:bash, 'git config')
expect(resource.environment).to eq('HOME' =>"/data/git")
end
it 'creates required directories in the rails root' do
%w{log tmp tmp/pids tmp/sockets public/uploads}.each do |path|
expect(chef_run).to create_directory("/data/git/gitlab/#{path}").with(
user: 'git',
group: 'git',
mode: 0755
)
end
end
it 'creates satellites directory' do
expect(chef_run).to create_directory("/data/git/gitlab-satellites")
end
it 'creates a unicorn config' do
expect(chef_run).to create_template('/data/git/gitlab/config/unicorn.rb')
end
describe "when using mysql" do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "centos", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.node.set['gitlab']['database_adapter'] = "mysql"
runner.node.set['gitlab']['database_password'] = "datapass"
runner.node.set['gitlab']['home'] = "/data/git"
runner.converge("gitlab::start","gitlab::install")
end
it 'creates a database config' do
expect(chef_run).to create_template('/data/git/gitlab/config/database.yml')
end
end
describe "when using postgresql" do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "centos", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.node.set['gitlab']['database_adapter'] = "postgresql"
runner.node.set['gitlab']['database_password'] = "datapass"
runner.node.set['gitlab']['home'] = "/data/git"
runner.converge("gitlab::start","gitlab::install")
end
it 'creates a database config' do
expect(chef_run).to create_template('/data/git/gitlab/config/database.yml')
end
end
describe "running database setup, migrations and seed when production" do
it 'runs db setup' do
resource = chef_run.find_resource(:execute, 'rake db:schema:load')
expect(resource.cwd).to eq("/data/git/gitlab")
end
it 'runs db migrate' do
resource = chef_run.find_resource(:execute, 'rake db:migrate')
expect(resource.cwd).to eq("/data/git/gitlab")
end
it 'runs db seed' do
resource = chef_run.find_resource(:execute, 'rake db:seed_fu')
expect(resource.cwd).to eq("/data/git/gitlab")
end
end
describe "creating gitlab init" do
describe "for production" do
it 'creates gitlab default configuration file' do
expect(chef_run).to create_template('/etc/default/gitlab').with(
source: 'gitlab.default.erb',
mode: 0755,
variables: {
app_user: 'git',
app_root: '/data/git/gitlab'
}
)
end
end
end
end
end
end
end
......@@ -6,7 +6,7 @@ describe "gitlab::nginx" do
describe "under ubuntu" do
["12.04", "10.04"].each do |version|
let(:chef_run) do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "ubuntu", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.converge("gitlab::nginx")
......@@ -48,12 +48,40 @@ describe "gitlab::nginx" do
it 'restarts nginx service' do
expect(chef_run).to restart_service('nginx')
end
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
end
end
describe "under centos" do
["5.8", "6.4"].each do |version|
let(:chef_run) do
let(:chef_run) do
runner = ChefSpec::Runner.new(platform: "centos", version: version)
runner.node.set['gitlab']['env'] = "production"
runner.converge("gitlab::nginx")
......@@ -91,6 +119,34 @@ describe "gitlab::nginx" do
it 'restarts nginx service' do
expect(chef_run).to restart_service('nginx')
end
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
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment