Skip to content
Permalink
Browse files

Add more tests and start logic to detect an existing repo in the config

  • Loading branch information...
wingrunr21 committed Jul 15, 2011
1 parent 142c2e4 commit 5d8e4cd7a589658a76066349dc328862ad754c8f
Showing with 144 additions and 8 deletions.
  1. +6 −0 lib/gitolite/gitolite_admin.rb
  2. +1 −1 lib/gitolite/version.rb
  3. +114 −4 spec/config_spec.rb
  4. +14 −0 spec/repo_spec.rb
  5. +9 −3 spec/ssh_key_spec.rb
@@ -121,5 +121,11 @@ def list_keys(path)
keys
end
end

#Checks to see if the given path is a gitolite-admin repository
#A valid repository contains a conf folder, keydir folder,
#and a configuration file within the conf folder
def detect_gitolite_repository(dir)
end
end
end
@@ -1,3 +1,3 @@
module Gitolite
VERSION = "0.0.2.alpha"
VERSION = "0.0.3.alpha"
end
@@ -71,32 +71,142 @@
describe "#init" do
it 'should create a valid, blank Gitolite::Config' do
c = Gitolite::Config.init

c.should be_an_instance_of Gitolite::Config
c.repos.should_not be nil
c.repos.length.should be 0
c.groups.should_not be nil
c.groups.length.should be 0
c.filename.should == "gitolite.conf"
end

it 'should create a valid, blank Gitolite::Config with the given filename' do
filename = "test.conf"
c = Gitolite::Config.init(filename)

c.should be_an_instance_of Gitolite::Config
c.repos.should_not be nil
c.repos.length.should be 0
c.groups.should_not be nil
c.groups.length.should be 0
c.filename.should == filename
end
end

describe "repo management" do
before :each do
@config = Gitolite::Config.new(File.join(conf_dir, 'complicated.conf'))
end

describe "#get_repo" do
it 'should fetch a repo by a string containing the name' do
@config.get_repo('gitolite').should be_an_instance_of Gitolite::Config::Repo
end

it 'should fetch a repo via a symbol representing the name' do
@config.get_repo(:gitolite).should be_an_instance_of Gitolite::Config::Repo
end

it 'should return nil for a repo that does not exist' do
@config.get_repo(:glite).should be nil
end
end

describe "#has_repo?" do
it 'should return false for a repo that does not exist' do
@config.has_repo?(:glite).should be false
end

it 'should check for the existance of a repo given a repo object' do
r = @config.repos["gitolite"]
@config.has_repo?(r).should be true
end

it 'should check for the existance of a repo given a string containing the name' do
@config.has_repo?('gitolite').should be true
end

it 'should check for the existance of a repo given a symbol representing the name' do
@config.has_repo?(:gitolite).should be true
end
end

describe "#add_repo" do
it 'should throw an ArgumentError for non-Gitolite::Config::Repo objects passed in' do
lambda{ @config.add_repo("not-a-repo") }.should raise_error(ArgumentError)
end

it 'should add a given repo to the list of repos' do
r = Gitolite::Config::Repo.new('cool_repo')
nrepos = @config.repos.size
@config.add_repo(r)

@config.repos.size.should == nrepos + 1
@config.has_repo?(:cool_repo).should be true
end

it 'should merge a given repo with an existing repo' do
end

it 'should overwrite an existing repo when overwrite = true' do
end
end

describe "#rm_repo" do
it 'should remove a repo for the Gitolite::Config::Repo object given' do
r = @config.get_repo(:gitolite)
r2 = @config.rm_repo(r)
r2.name.should == r.name
r2.permissions.length.should == r.permissions.length
r2.owner.should == r.owner
r2.description.should == r.description
end

it 'should remove a repo given a string containing the name' do
r = @config.get_repo(:gitolite)
r2 = @config.rm_repo('gitolite')
r2.name.should == r.name
r2.permissions.length.should == r.permissions.length
r2.owner.should == r.owner
r2.description.should == r.description
end

it 'should remove a repo given a symbol representing the name' do
r = @config.get_repo(:gitolite)
r2 = @config.rm_repo(:gitolite)
r2.name.should == r.name
r2.permissions.length.should == r.permissions.length
r2.owner.should == r.owner
r2.description.should == r.description
end
end
end

describe "#to_file" do
end
it 'should create a file at the given path with the config\'s file name' do
c = Gitolite::Config.init
file = c.to_file('/tmp')
File.file?(File.join('/tmp', c.filename)).should be true
File.unlink(file)
end

describe "deny rules" do
it 'should maintain the order of rules within a config file' do
it 'should create a file at the given path when a different filename is specified' do
filename = "test.conf"
c = Gitolite::Config.init
c.filename = filename
file = c.to_file('/tmp')
File.file?(File.join('/tmp', filename)).should be true
File.unlink(file)
end

it 'should raise an ArgumentError when an invalid path is specified' do
c = Gitolite::Config.init
lambda { c.to_file('/does/not/exist') }.should raise_error(ArgumentError)
end

it 'should raise an ArgumentError when a filename is specified in the path' do
c = Gitolite::Config.init
lambda{ c.to_file('/home/test.rb') }.should raise_error(ArgumentError)
end
end

@@ -135,4 +245,4 @@
@config.instance_eval { cleanup_config_line(s) }.should == "bob = joe"
end
end
end
end
@@ -11,6 +11,20 @@
end
end

describe "deny rules" do
it 'should maintain the order of rules for a repository' do
@repo.add_permission("RW+", "", "bob", "joe", "sam")
@repo.add_permission("R", "", "sue", "jen", "greg")
@repo.add_permission("-", "refs/tags/test[0-9]", "@students", "jessica")
@repo.add_permission("RW", "refs/tags/test[0-9]", "@teachers", "bill", "todd")
@repo.add_permission("R", "refs/tags/test[0-9]", "@profs")

@repo.permissions.length.should == 2
@repo.permissions[0].size.should == 2
@repo.permissions[1].size.should == 3
end
end

describe '#add_permission' do
it 'should allow adding a permission to the permissions list' do
@repo.add_permission("RW+")
@@ -24,10 +24,16 @@
s.owner.should == 'bob@zilla.com'
end

it "owner should be bob-ins@zilla-site.com for bob-ins@zilla-site.com@desktop.pub" do
key = File.join(key_dir, 'bob-ins@zilla-site.com@desktop.pub')
it "owner should be joe-bob@god-zilla.com for joe-bob@god-zilla.com@desktop.pub" do
key = File.join(key_dir, 'joe-bob@god-zilla.com@desktop.pub')
s = SSHKey.from_file(key)
s.owner.should == 'bob-ins@zilla-site.com'
s.owner.should == 'joe-bob@god-zilla.com'
end

it "owner should be bob.joe@test.zilla.com for bob.joe@test.zilla.com@desktop.pub" do
key = File.join(key_dir, 'bob.joe@test.zilla.com@desktop.pub')
s = SSHKey.from_file(key)
s.owner.should == 'bob.joe@test.zilla.com'
end

it 'owner should be bob@zilla.com for bob@zilla.com@desktop.pub' do

0 comments on commit 5d8e4cd

Please sign in to comment.
You can’t perform that action at this time.