mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-11 07:55:55 +01:00
(refs #115)Use regex to create git command
And add GitCommandFactory Unit Test Spec
This commit is contained in:
39
src/test/scala/ssh/GitCommandSpec.scala
Normal file
39
src/test/scala/ssh/GitCommandSpec.scala
Normal file
@@ -0,0 +1,39 @@
|
||||
package ssh
|
||||
|
||||
import org.specs2.mutable._
|
||||
import org.apache.sshd.server.command.UnknownCommand
|
||||
|
||||
|
||||
class GitCommandFactorySpec extends Specification {
|
||||
|
||||
val factory = new GitCommandFactory
|
||||
|
||||
"createCommand" should {
|
||||
"returns GitRecievePack when command is git-receive-pack" in {
|
||||
factory.createCommand("git-receive-pack '/owner/repo.git'").isInstanceOf[GitReceivePack] must beTrue
|
||||
factory.createCommand("git-receive-pack '/owner/repo.wiki.git'").isInstanceOf[GitReceivePack] must beTrue
|
||||
|
||||
}
|
||||
"returns GitUploadPack when command is git-upload-pack" in {
|
||||
factory.createCommand("git-upload-pack '/owner/repo.git'").isInstanceOf[GitUploadPack] must beTrue
|
||||
factory.createCommand("git-upload-pack '/owner/repo.wiki.git'").isInstanceOf[GitUploadPack] must beTrue
|
||||
|
||||
}
|
||||
"returns UnknownCommand when command is not git-(upload|receive)-pack" in {
|
||||
factory.createCommand("git- '/owner/repo.git'").isInstanceOf[UnknownCommand] must beTrue
|
||||
factory.createCommand("git-pack '/owner/repo.git'").isInstanceOf[UnknownCommand] must beTrue
|
||||
factory.createCommand("git-a-pack '/owner/repo.git'").isInstanceOf[UnknownCommand] must beTrue
|
||||
factory.createCommand("git-up-pack '/owner/repo.git'").isInstanceOf[UnknownCommand] must beTrue
|
||||
factory.createCommand("\ngit-upload-pack '/owner/repo.git'").isInstanceOf[UnknownCommand] must beTrue
|
||||
}
|
||||
"returns UnknownCommand when git command has no valid arguments" in {
|
||||
// must be: git-upload-pack '/owner/repository_name.git'
|
||||
factory.createCommand("git-upload-pack").isInstanceOf[UnknownCommand] must beTrue
|
||||
factory.createCommand("git-upload-pack /owner/repo.git").isInstanceOf[UnknownCommand] must beTrue
|
||||
factory.createCommand("git-upload-pack 'owner/repo.git'").isInstanceOf[UnknownCommand] must beTrue
|
||||
factory.createCommand("git-upload-pack '/ownerrepo.git'").isInstanceOf[UnknownCommand] must beTrue
|
||||
factory.createCommand("git-upload-pack '/owner/repo.wiki'").isInstanceOf[UnknownCommand] must beTrue
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user