Commit ea6ea902 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

More tests

parent 8d374284
source "http://rubygems.org" source "http://rubygems.org"
gem 'rspec' group :development do
gem 'rspec'
gem 'guard'
gem 'guard-rspec'
end
GEM GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
specs: specs:
coderay (1.0.8)
diff-lcs (1.1.3) diff-lcs (1.1.3)
guard (1.5.4)
listen (>= 0.4.2)
lumberjack (>= 1.0.2)
pry (>= 0.9.10)
thor (>= 0.14.6)
guard-rspec (2.1.2)
guard (>= 1.1)
rspec (~> 2.11)
listen (0.5.3)
lumberjack (1.0.2)
method_source (0.8.1)
pry (0.9.10)
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.3.1)
rspec (2.12.0) rspec (2.12.0)
rspec-core (~> 2.12.0) rspec-core (~> 2.12.0)
rspec-expectations (~> 2.12.0) rspec-expectations (~> 2.12.0)
...@@ -10,9 +26,13 @@ GEM ...@@ -10,9 +26,13 @@ GEM
rspec-expectations (2.12.1) rspec-expectations (2.12.1)
diff-lcs (~> 1.1.3) diff-lcs (~> 1.1.3)
rspec-mocks (2.12.2) rspec-mocks (2.12.2)
slop (3.3.3)
thor (0.16.0)
PLATFORMS PLATFORMS
ruby ruby
DEPENDENCIES DEPENDENCIES
guard
guard-rspec
rspec rspec
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
guard 'rspec' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
# Capybara features specs
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end
...@@ -15,7 +15,6 @@ class GitlabKeys ...@@ -15,7 +15,6 @@ class GitlabKeys
case @command case @command
when 'add-key'; add_key when 'add-key'; add_key
when 'rm-key'; rm_key when 'rm-key'; rm_key
when 'rm-user'; rm_user
else else
puts 'not allowed' puts 'not allowed'
end end
...@@ -33,9 +32,4 @@ class GitlabKeys ...@@ -33,9 +32,4 @@ class GitlabKeys
cmd = "sed '/#{@key}/d' #{auth_file}" cmd = "sed '/#{@key}/d' #{auth_file}"
system(cmd) system(cmd)
end end
def rm_user
cmd = "sed -i '/gitlab-shell #{@username},/d' #{auth_file}"
system(cmd)
end
end end
...@@ -4,7 +4,7 @@ require 'net/http' ...@@ -4,7 +4,7 @@ require 'net/http'
require_relative 'gitlab_config' require_relative 'gitlab_config'
class GitlabShell class GitlabShell
attr_accessor :username, :repo_name, :git_cmd, :repos_path attr_accessor :username, :repo_name, :git_cmd, :repos_path, :repo_name
def initialize def initialize
@username = ARGV.shift @username = ARGV.shift
......
...@@ -5,7 +5,7 @@ describe GitlabShell do ...@@ -5,7 +5,7 @@ describe GitlabShell do
describe :initialize do describe :initialize do
before do before do
ENV['SSH_ORIGINAL_COMMAND'] = 'git-receive-pack' ssh_cmd 'git-receive-pack'
ARGV[0] = 'dzaporozhets' ARGV[0] = 'dzaporozhets'
@shell = GitlabShell.new @shell = GitlabShell.new
end end
...@@ -13,4 +13,59 @@ describe GitlabShell do ...@@ -13,4 +13,59 @@ describe GitlabShell do
it { @shell.username.should == 'dzaporozhets' } it { @shell.username.should == 'dzaporozhets' }
it { @shell.repos_path.should == "/home/git/repositories" } it { @shell.repos_path.should == "/home/git/repositories" }
end end
describe :parse_cmd do
context 'w/o namespace' do
before do
ssh_cmd 'git-upload-pack gitlab-ci.git'
@shell = GitlabShell.new
@shell.send :parse_cmd
end
it { @shell.repo_name.should == 'gitlab-ci.git' }
it { @shell.git_cmd.should == 'git-upload-pack' }
end
context 'namespace' do
before do
ssh_cmd 'git-upload-pack dmitriy.zaporozhets/gitlab-ci.git'
@shell = GitlabShell.new
@shell.send :parse_cmd
end
it { @shell.repo_name.should == 'dmitriy.zaporozhets/gitlab-ci.git' }
it { @shell.git_cmd.should == 'git-upload-pack' }
end
end
describe :exec do
context 'git-upload-pack' do
before do
ssh_cmd 'git-upload-pack gitlab-ci.git'
stubbed_shell
end
it { @shell.exec.should be_true }
end
context 'git-receive-pack' do
before do
ssh_cmd 'git-receive-pack gitlab-ci.git'
stubbed_shell
end
it { @shell.exec.should be_true }
end
end
def ssh_cmd(cmd)
ENV['SSH_ORIGINAL_COMMAND'] = cmd
end
def stubbed_shell
ARGV[0] = 'dzaporozhets'
@shell = GitlabShell.new
@shell.stub(validate_access: true)
@shell.stub(process_cmd: true)
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