mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-03 12:05:59 +01:00
@@ -3,7 +3,7 @@ project.git = true
|
||||
maxColumn = 120
|
||||
docstrings = JavaDoc
|
||||
|
||||
align = true
|
||||
align.tokens = ["%", "%%", {code = "=>", owner = "Case"}]
|
||||
align.openParenCallSite = false
|
||||
align.openParenDefnSite = false
|
||||
continuationIndent.callSite = 2
|
||||
|
||||
@@ -3,7 +3,7 @@ sudo: true
|
||||
jdk:
|
||||
- oraclejdk8
|
||||
script:
|
||||
- sbt test
|
||||
- sbt scalafmtSbtCheck scalafmtCheck test:scalafmtCheck test
|
||||
before_script:
|
||||
- sudo /etc/init.d/mysql stop
|
||||
- sudo /etc/init.d/postgresql stop
|
||||
|
||||
46
build.sbt
46
build.sbt
@@ -7,9 +7,10 @@ val GitBucketVersion = "4.23.0"
|
||||
val ScalatraVersion = "2.6.1"
|
||||
val JettyVersion = "9.4.7.v20170914"
|
||||
|
||||
lazy val root = (project in file(".")).enablePlugins(SbtTwirl, ScalatraPlugin, JRebelPlugin).settings(
|
||||
|
||||
)
|
||||
lazy val root = (project in file("."))
|
||||
.enablePlugins(SbtTwirl, ScalatraPlugin, JRebelPlugin)
|
||||
.settings(
|
||||
)
|
||||
|
||||
sourcesInBase := false
|
||||
organization := Organization
|
||||
@@ -41,7 +42,7 @@ libraryDependencies ++= Seq(
|
||||
"org.apache.commons" % "commons-compress" % "1.15",
|
||||
"org.apache.commons" % "commons-email" % "1.5",
|
||||
"org.apache.httpcomponents" % "httpclient" % "4.5.4",
|
||||
"org.apache.sshd" % "apache-sshd" % "1.6.0" exclude("org.slf4j","slf4j-jdk14"),
|
||||
"org.apache.sshd" % "apache-sshd" % "1.6.0" exclude ("org.slf4j", "slf4j-jdk14"),
|
||||
"org.apache.tika" % "tika-core" % "1.17",
|
||||
"com.github.takezoe" %% "blocking-slick-32" % "0.0.10",
|
||||
"com.novell.ldap" % "jldap" % "2009-10-07",
|
||||
@@ -55,7 +56,7 @@ libraryDependencies ++= Seq(
|
||||
"fr.brouillard.oss.security.xhub" % "xhub4j-core" % "1.0.0",
|
||||
"com.github.bkromhout" % "java-diff-utils" % "2.1.1",
|
||||
"org.cache2k" % "cache2k-all" % "1.0.1.Final",
|
||||
"com.enragedginger" %% "akka-quartz-scheduler" % "1.6.1-akka-2.5.x" exclude("c3p0","c3p0"),
|
||||
"com.enragedginger" %% "akka-quartz-scheduler" % "1.6.1-akka-2.5.x" exclude ("c3p0", "c3p0"),
|
||||
"net.coobird" % "thumbnailator" % "0.4.8",
|
||||
"com.github.zafarkhaja" % "java-semver" % "0.9.0",
|
||||
"com.nimbusds" % "oauth2-oidc-sdk" % "5.45",
|
||||
@@ -78,7 +79,7 @@ javaOptions in Jetty += "-Dlogback.configurationFile=/logback-dev.xml"
|
||||
// Test settings
|
||||
//testOptions in Test += Tests.Argument("-l", "ExternalDBTest")
|
||||
javaOptions in Test += "-Dgitbucket.home=target/gitbucket_home_for_test"
|
||||
testOptions in Test += Tests.Setup( () => new java.io.File("target/gitbucket_home_for_test").mkdir() )
|
||||
testOptions in Test += Tests.Setup(() => new java.io.File("target/gitbucket_home_for_test").mkdir())
|
||||
fork in Test := true
|
||||
|
||||
// Packaging options
|
||||
@@ -88,7 +89,7 @@ packageOptions += Package.MainClass("JettyLauncher")
|
||||
test in assembly := {}
|
||||
assemblyMergeStrategy in assembly := {
|
||||
case PathList("META-INF", xs @ _*) =>
|
||||
(xs map {_.toLowerCase}) match {
|
||||
(xs map { _.toLowerCase }) match {
|
||||
case ("manifest.mf" :: Nil) => MergeStrategy.discard
|
||||
case _ => MergeStrategy.discard
|
||||
}
|
||||
@@ -112,7 +113,9 @@ javaOptions in Jetty ++= Option(System.getenv().get("JREBEL")).toSeq.flatMap { p
|
||||
|
||||
// Exclude a war file from published artifacts
|
||||
signedArtifacts := {
|
||||
signedArtifacts.value.filterNot { case (_, file) => file.getName.endsWith(".war") || file.getName.endsWith(".war.asc") }
|
||||
signedArtifacts.value.filterNot {
|
||||
case (_, file) => file.getName.endsWith(".war") || file.getName.endsWith(".war.asc")
|
||||
}
|
||||
}
|
||||
|
||||
// Create executable war file
|
||||
@@ -148,10 +151,9 @@ executableKey := {
|
||||
// include jetty classes
|
||||
val jettyJars = Keys.update.value select configurationFilter(name = ExecutableConfig.name)
|
||||
jettyJars foreach { jar =>
|
||||
IO unzip (jar, temp, (name:String) =>
|
||||
IO unzip (jar, temp, (name: String) =>
|
||||
(name startsWith "javax/") ||
|
||||
(name startsWith "org/")
|
||||
)
|
||||
(name startsWith "org/"))
|
||||
}
|
||||
|
||||
// include original war file
|
||||
@@ -160,7 +162,7 @@ executableKey := {
|
||||
|
||||
// include launcher classes
|
||||
val classDir = (Keys.classDirectory in Compile).value
|
||||
val launchClasses = Seq("JettyLauncher.class" /*, "HttpsSupportConnector.class" */)
|
||||
val launchClasses = Seq("JettyLauncher.class" /*, "HttpsSupportConnector.class" */ )
|
||||
launchClasses foreach { name =>
|
||||
IO copyFile (classDir / name, temp / name)
|
||||
}
|
||||
@@ -168,30 +170,32 @@ executableKey := {
|
||||
// include plugins
|
||||
val pluginsDir = temp / "WEB-INF" / "classes" / "plugins"
|
||||
IO createDirectory (pluginsDir)
|
||||
IO copyFile(Keys.baseDirectory.value / "plugins.json", pluginsDir / "plugins.json")
|
||||
IO copyFile (Keys.baseDirectory.value / "plugins.json", pluginsDir / "plugins.json")
|
||||
|
||||
val json = IO read(Keys.baseDirectory.value / "plugins.json")
|
||||
val json = IO read (Keys.baseDirectory.value / "plugins.json")
|
||||
PluginsJson.getUrls(json).foreach { url =>
|
||||
log info s"Download: ${url}"
|
||||
IO transfer(new java.net.URL(url).openStream, pluginsDir / url.substring(url.lastIndexOf("/") + 1))
|
||||
IO transfer (new java.net.URL(url).openStream, pluginsDir / url.substring(url.lastIndexOf("/") + 1))
|
||||
}
|
||||
|
||||
// zip it up
|
||||
IO delete (temp / "META-INF" / "MANIFEST.MF")
|
||||
val contentMappings = (temp.allPaths --- PathFinder(temp)).get pair { file => IO.relativizeFile(temp, file) }
|
||||
val contentMappings = (temp.allPaths --- PathFinder(temp)).get pair { file =>
|
||||
IO.relativizeFile(temp, file)
|
||||
}
|
||||
val manifest = new JarManifest
|
||||
manifest.getMainAttributes put (AttrName.MANIFEST_VERSION, "1.0")
|
||||
manifest.getMainAttributes put (AttrName.MAIN_CLASS, "JettyLauncher")
|
||||
val outputFile = workDir / warName
|
||||
IO jar (contentMappings.map { case (file, path) => (file, path.toString) } , outputFile, manifest)
|
||||
IO jar (contentMappings.map { case (file, path) => (file, path.toString) }, outputFile, manifest)
|
||||
|
||||
// generate checksums
|
||||
Seq(
|
||||
"md5" -> "MD5",
|
||||
"sha1" -> "SHA-1",
|
||||
"sha256" -> "SHA-256"
|
||||
)
|
||||
.foreach { case (extension, algorithm) =>
|
||||
).foreach {
|
||||
case (extension, algorithm) =>
|
||||
val checksumFile = workDir / (warName + "." + extension)
|
||||
Checksums generate (outputFile, checksumFile, algorithm)
|
||||
}
|
||||
@@ -206,7 +210,9 @@ publishTo := {
|
||||
else Some("releases" at nexus + "service/local/staging/deploy/maven2")
|
||||
}
|
||||
publishMavenStyle := true
|
||||
pomIncludeRepository := { _ => false }
|
||||
pomIncludeRepository := { _ =>
|
||||
false
|
||||
}
|
||||
pomExtra := (
|
||||
<url>https://github.com/gitbucket/gitbucket</url>
|
||||
<licenses>
|
||||
|
||||
@@ -6,13 +6,13 @@ import io._
|
||||
object Checksums {
|
||||
private val bufferSize = 2048
|
||||
|
||||
def generate(source:File, target:File, algorithm:String):Unit =
|
||||
def generate(source: File, target: File, algorithm: String): Unit =
|
||||
sbt.IO write (target, compute(source, algorithm))
|
||||
|
||||
def compute(file:File, algorithm:String):String =
|
||||
def compute(file: File, algorithm: String): String =
|
||||
hex(raw(file, algorithm))
|
||||
|
||||
def raw(file:File, algorithm:String):Array[Byte] =
|
||||
def raw(file: File, algorithm: String): Array[Byte] =
|
||||
(Using fileInputStream file) { is =>
|
||||
val md = MessageDigest getInstance algorithm
|
||||
val buf = new Array[Byte](bufferSize)
|
||||
@@ -29,6 +29,8 @@ object Checksums {
|
||||
md.digest()
|
||||
}
|
||||
|
||||
def hex(bytes:Array[Byte]):String =
|
||||
bytes map { it => "%02x" format (it.toInt & 0xff) } mkString ""
|
||||
def hex(bytes: Array[Byte]): String =
|
||||
bytes map { it =>
|
||||
"%02x" format (it.toInt & 0xff)
|
||||
} mkString ""
|
||||
}
|
||||
|
||||
@@ -13,4 +13,3 @@ object PluginsJson {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ object ExternalDBTest extends Tag("ExternalDBTest")
|
||||
|
||||
class GitBucketCoreModuleSpec extends FunSuite {
|
||||
|
||||
test("Migration H2"){
|
||||
test("Migration H2") {
|
||||
new Solidbase().migrate(
|
||||
DriverManager.getConnection("jdbc:h2:mem:test", "sa", "sa"),
|
||||
Thread.currentThread().getContextClassLoader(),
|
||||
@@ -28,7 +28,7 @@ class GitBucketCoreModuleSpec extends FunSuite {
|
||||
)
|
||||
}
|
||||
|
||||
test("Migration MySQL", ExternalDBTest){
|
||||
test("Migration MySQL", ExternalDBTest) {
|
||||
val config = aMysqldConfig(v5_7_latest)
|
||||
.withPort(3306)
|
||||
.withUser("sa", "sa")
|
||||
@@ -53,14 +53,15 @@ class GitBucketCoreModuleSpec extends FunSuite {
|
||||
}
|
||||
}
|
||||
|
||||
test("Migration PostgreSQL", ExternalDBTest){
|
||||
test("Migration PostgreSQL", ExternalDBTest) {
|
||||
val runtime = PostgresStarter.getDefaultInstance()
|
||||
val config = new PostgresConfig(
|
||||
PRODUCTION,
|
||||
new Net("localhost", 5432),
|
||||
new Storage("gitbucket"),
|
||||
new Timeout(),
|
||||
new Credentials("sa", "sa"))
|
||||
new Credentials("sa", "sa")
|
||||
)
|
||||
|
||||
val exec = runtime.prepare(config)
|
||||
val process = exec.start()
|
||||
|
||||
@@ -8,14 +8,13 @@ import org.scalatest.FunSuite
|
||||
|
||||
import java.util.{Calendar, TimeZone, Date}
|
||||
|
||||
|
||||
class JsonFormatSpec extends FunSuite {
|
||||
val date1 = {
|
||||
val d = Calendar.getInstance(TimeZone.getTimeZone("UTC"))
|
||||
d.set(2011,3,14,16,0,49)
|
||||
d.set(2011, 3, 14, 16, 0, 49)
|
||||
d.getTime
|
||||
}
|
||||
def date(date:String): Date = {
|
||||
def date(date: String): Date = {
|
||||
val f = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
|
||||
f.setTimeZone(TimeZone.getTimeZone("UTC"))
|
||||
f.parse(date)
|
||||
@@ -24,12 +23,8 @@ class JsonFormatSpec extends FunSuite {
|
||||
val repo1Name = RepositoryName("octocat/Hello-World")
|
||||
implicit val context = JsonFormat.Context("http://gitbucket.exmple.com", None)
|
||||
|
||||
val apiUser = ApiUser(
|
||||
login = "octocat",
|
||||
email = "octocat@example.com",
|
||||
`type` = "User",
|
||||
site_admin = false,
|
||||
created_at = date1)
|
||||
val apiUser =
|
||||
ApiUser(login = "octocat", email = "octocat@example.com", `type` = "User", site_admin = false, created_at = date1)
|
||||
val apiUserJson = """{
|
||||
"login":"octocat",
|
||||
"email":"octocat@example.com",
|
||||
@@ -49,7 +44,8 @@ class JsonFormatSpec extends FunSuite {
|
||||
forks = 0,
|
||||
`private` = false,
|
||||
default_branch = "master",
|
||||
owner = apiUser)(urlIsHtmlUrl = false)
|
||||
owner = apiUser
|
||||
)(urlIsHtmlUrl = false)
|
||||
val repositoryJson = s"""{
|
||||
"name" : "Hello-World",
|
||||
"full_name" : "octocat/Hello-World",
|
||||
@@ -96,8 +92,9 @@ class JsonFormatSpec extends FunSuite {
|
||||
added = Nil,
|
||||
removed = Nil,
|
||||
modified = List("README.md"),
|
||||
author = ApiPersonIdent("baxterthehacker","baxterthehacker@users.noreply.github.com",date1),
|
||||
committer = ApiPersonIdent("baxterthehacker","baxterthehacker@users.noreply.github.com",date1))(RepositoryName("baxterthehacker", "public-repo"), true)
|
||||
author = ApiPersonIdent("baxterthehacker", "baxterthehacker@users.noreply.github.com", date1),
|
||||
committer = ApiPersonIdent("baxterthehacker", "baxterthehacker@users.noreply.github.com", date1)
|
||||
)(RepositoryName("baxterthehacker", "public-repo"), true)
|
||||
val apiPushCommitJson = s"""{
|
||||
"id": "0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c",
|
||||
// "distinct": true,
|
||||
@@ -127,12 +124,11 @@ class JsonFormatSpec extends FunSuite {
|
||||
]
|
||||
}"""
|
||||
|
||||
val apiComment = ApiComment(
|
||||
id =1,
|
||||
user = apiUser,
|
||||
body= "Me too",
|
||||
created_at= date1,
|
||||
updated_at= date1)(RepositoryName("octocat","Hello-World"), 100, false)
|
||||
val apiComment = ApiComment(id = 1, user = apiUser, body = "Me too", created_at = date1, updated_at = date1)(
|
||||
RepositoryName("octocat", "Hello-World"),
|
||||
100,
|
||||
false
|
||||
)
|
||||
val apiCommentJson = s"""{
|
||||
"id": 1,
|
||||
"body": "Me too",
|
||||
@@ -142,12 +138,11 @@ class JsonFormatSpec extends FunSuite {
|
||||
"updated_at": "2011-04-14T16:00:49Z"
|
||||
}"""
|
||||
|
||||
val apiCommentPR = ApiComment(
|
||||
id =1,
|
||||
user = apiUser,
|
||||
body= "Me too",
|
||||
created_at= date1,
|
||||
updated_at= date1)(RepositoryName("octocat","Hello-World"), 100, true)
|
||||
val apiCommentPR = ApiComment(id = 1, user = apiUser, body = "Me too", created_at = date1, updated_at = date1)(
|
||||
RepositoryName("octocat", "Hello-World"),
|
||||
100,
|
||||
true
|
||||
)
|
||||
val apiCommentPRJson = s"""{
|
||||
"id": 1,
|
||||
"body": "Me too",
|
||||
@@ -157,7 +152,7 @@ class JsonFormatSpec extends FunSuite {
|
||||
"updated_at": "2011-04-14T16:00:49Z"
|
||||
}"""
|
||||
|
||||
val apiPersonIdent = ApiPersonIdent("Monalisa Octocat","support@example.com",date1)
|
||||
val apiPersonIdent = ApiPersonIdent("Monalisa Octocat", "support@example.com", date1)
|
||||
val apiPersonIdentJson = """ {
|
||||
"name": "Monalisa Octocat",
|
||||
"email": "support@example.com",
|
||||
@@ -172,8 +167,9 @@ class JsonFormatSpec extends FunSuite {
|
||||
committer = apiPersonIdent
|
||||
)(sha1, repo1Name),
|
||||
author = Some(apiUser),
|
||||
committer= Some(apiUser),
|
||||
parents= Seq(ApiCommitListItem.Parent("6dcb09b5b57875f334f61aebed695e2e4193db5e")(repo1Name)))(repo1Name)
|
||||
committer = Some(apiUser),
|
||||
parents = Seq(ApiCommitListItem.Parent("6dcb09b5b57875f334f61aebed695e2e4193db5e")(repo1Name))
|
||||
)(repo1Name)
|
||||
val apiCommitListItemJson = s"""{
|
||||
"url": "${context.baseUrl}/api/v3/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
|
||||
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e",
|
||||
@@ -198,7 +194,8 @@ class JsonFormatSpec extends FunSuite {
|
||||
sha = sha1,
|
||||
total_count = 2,
|
||||
statuses = List(apiCommitStatus),
|
||||
repository = repository)
|
||||
repository = repository
|
||||
)
|
||||
val apiCombinedCommitStatusJson = s"""{
|
||||
"state": "success",
|
||||
"sha": "$sha1",
|
||||
@@ -208,9 +205,7 @@ class JsonFormatSpec extends FunSuite {
|
||||
"url": "${context.baseUrl}/api/v3/repos/octocat/Hello-World/commits/$sha1/status"
|
||||
}"""
|
||||
|
||||
val apiLabel = ApiLabel(
|
||||
name = "bug",
|
||||
color = "f29513")(RepositoryName("octocat","Hello-World"))
|
||||
val apiLabel = ApiLabel(name = "bug", color = "f29513")(RepositoryName("octocat", "Hello-World"))
|
||||
val apiLabelJson = s"""{
|
||||
"name": "bug",
|
||||
"color": "f29513",
|
||||
@@ -225,7 +220,8 @@ class JsonFormatSpec extends FunSuite {
|
||||
state = "open",
|
||||
body = "I'm having a problem with this.",
|
||||
created_at = date1,
|
||||
updated_at = date1)(RepositoryName("octocat","Hello-World"), false)
|
||||
updated_at = date1
|
||||
)(RepositoryName("octocat", "Hello-World"), false)
|
||||
val apiIssueJson = s"""{
|
||||
"number": 1347,
|
||||
"state": "open",
|
||||
@@ -247,7 +243,8 @@ class JsonFormatSpec extends FunSuite {
|
||||
state = "open",
|
||||
body = "I'm having a problem with this.",
|
||||
created_at = date1,
|
||||
updated_at = date1)(RepositoryName("octocat","Hello-World"), true)
|
||||
updated_at = date1
|
||||
)(RepositoryName("octocat", "Hello-World"), true)
|
||||
val apiIssuePRJson = s"""{
|
||||
"number": 1347,
|
||||
"state": "open",
|
||||
@@ -272,14 +269,8 @@ class JsonFormatSpec extends FunSuite {
|
||||
state = "open",
|
||||
updated_at = date1,
|
||||
created_at = date1,
|
||||
head = ApiPullRequest.Commit(
|
||||
sha = sha1,
|
||||
ref = "new-topic",
|
||||
repo = repository)("octocat"),
|
||||
base = ApiPullRequest.Commit(
|
||||
sha = sha1,
|
||||
ref = "master",
|
||||
repo = repository)("octocat"),
|
||||
head = ApiPullRequest.Commit(sha = sha1, ref = "new-topic", repo = repository)("octocat"),
|
||||
base = ApiPullRequest.Commit(sha = sha1, ref = "master", repo = repository)("octocat"),
|
||||
mergeable = None,
|
||||
merged = false,
|
||||
merged_at = Some(date1),
|
||||
@@ -381,8 +372,10 @@ class JsonFormatSpec extends FunSuite {
|
||||
}
|
||||
}"""
|
||||
|
||||
|
||||
val apiBranchProtection = ApiBranchProtection(true, Some(ApiBranchProtection.Status(ApiBranchProtection.Everyone, Seq("continuous-integration/travis-ci"))))
|
||||
val apiBranchProtection = ApiBranchProtection(
|
||||
true,
|
||||
Some(ApiBranchProtection.Status(ApiBranchProtection.Everyone, Seq("continuous-integration/travis-ci")))
|
||||
)
|
||||
val apiBranchProtectionJson = """{
|
||||
"enabled": true,
|
||||
"required_status_checks": {
|
||||
|
||||
@@ -3,7 +3,6 @@ package gitbucket.core.model
|
||||
import gitbucket.core.model.CommitState._
|
||||
import org.scalatest.FunSpec
|
||||
|
||||
|
||||
class CommitStateSpec extends FunSpec {
|
||||
describe("CommitState") {
|
||||
it("should combine empty must eq PENDING") {
|
||||
|
||||
@@ -8,29 +8,36 @@ import gitbucket.core.model.Profile.profile.blockingApi._
|
||||
|
||||
class AccessTokenServiceSpec extends FunSuite with ServiceSpecBase {
|
||||
|
||||
test("generateAccessToken") { withTestDB { implicit session =>
|
||||
test("generateAccessToken") {
|
||||
withTestDB { implicit session =>
|
||||
assert(AccessTokenService.generateAccessToken("root", "note") match {
|
||||
case (id, token) => id != 0
|
||||
})
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
test("getAccessTokens") { withTestDB { implicit session =>
|
||||
test("getAccessTokens") {
|
||||
withTestDB { implicit session =>
|
||||
val (id, token) = AccessTokenService.generateAccessToken("root", "note")
|
||||
val tokenHash = AccessTokenService.tokenToHash(token)
|
||||
|
||||
assert(AccessTokenService.getAccessTokens("root") == List(AccessToken(`id`, "root", `tokenHash`, "note")))
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
test("getAccessTokens(root) get root's tokens") { withTestDB { implicit session =>
|
||||
test("getAccessTokens(root) get root's tokens") {
|
||||
withTestDB { implicit session =>
|
||||
val (id, token) = AccessTokenService.generateAccessToken("root", "note")
|
||||
val tokenHash = AccessTokenService.tokenToHash(token)
|
||||
val user2 = generateNewAccount("user2")
|
||||
AccessTokenService.generateAccessToken("user2", "note2")
|
||||
|
||||
assert(AccessTokenService.getAccessTokens("root") == List(AccessToken(`id`, "root", `tokenHash`, "note")))
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
test("deleteAccessToken") { withTestDB { implicit session =>
|
||||
test("deleteAccessToken") {
|
||||
withTestDB { implicit session =>
|
||||
val (id, token) = AccessTokenService.generateAccessToken("root", "note")
|
||||
val user2 = generateNewAccount("user2")
|
||||
AccessTokenService.generateAccessToken("user2", "note2")
|
||||
@@ -38,34 +45,42 @@ class AccessTokenServiceSpec extends FunSuite with ServiceSpecBase {
|
||||
AccessTokenService.deleteAccessToken("root", id)
|
||||
|
||||
assert(AccessTokenService.getAccessTokens("root").isEmpty)
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
test("getAccountByAccessToken") { withTestDB { implicit session =>
|
||||
test("getAccountByAccessToken") {
|
||||
withTestDB { implicit session =>
|
||||
val (id, token) = AccessTokenService.generateAccessToken("root", "note")
|
||||
assert(AccessTokenService.getAccountByAccessToken(token) match {
|
||||
case Some(user) => user.userName == "root"
|
||||
})
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
test("getAccountByAccessToken don't get removed account") { withTestDB { implicit session =>
|
||||
test("getAccountByAccessToken don't get removed account") {
|
||||
withTestDB { implicit session =>
|
||||
val user2 = generateNewAccount("user2")
|
||||
val (id, token) = AccessTokenService.generateAccessToken("user2", "note")
|
||||
AccountService.updateAccount(user2.copy(isRemoved=true))
|
||||
AccountService.updateAccount(user2.copy(isRemoved = true))
|
||||
|
||||
assert(AccessTokenService.getAccountByAccessToken(token).isEmpty)
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
test("generateAccessToken create uniq token") { withTestDB { implicit session =>
|
||||
val tokenIt = List("token1","token1","token1","token2").iterator
|
||||
val service = new AccessTokenService{
|
||||
override def makeAccessTokenString:String = tokenIt.next
|
||||
test("generateAccessToken create uniq token") {
|
||||
withTestDB { implicit session =>
|
||||
val tokenIt = List("token1", "token1", "token1", "token2").iterator
|
||||
val service = new AccessTokenService {
|
||||
override def makeAccessTokenString: String = tokenIt.next
|
||||
}
|
||||
|
||||
assert(service.generateAccessToken("root", "note1")._2 == "token1")
|
||||
assert(service.generateAccessToken("root", "note2")._2 == "token2")
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
test("when update Account.userName then AccessToken.userName changed") { withTestDB { implicit session =>
|
||||
test("when update Account.userName then AccessToken.userName changed") {
|
||||
withTestDB { implicit session =>
|
||||
val user2 = generateNewAccount("user2")
|
||||
val (id, token) = AccessTokenService.generateAccessToken("user2", "note")
|
||||
|
||||
@@ -74,6 +89,6 @@ class AccessTokenServiceSpec extends FunSuite with ServiceSpecBase {
|
||||
assert(AccessTokenService.getAccountByAccessToken(token) match {
|
||||
case Some(user) => user.userName == "user3"
|
||||
})
|
||||
}}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,13 @@ class AccountFederationServiceSpec extends FunSpec with ServiceSpecBase {
|
||||
describe("getOrCreateFederatedUser") {
|
||||
it("should create a federated account if it does not exist") {
|
||||
withTestDB { implicit session =>
|
||||
val actual = AccountFederationService.getOrCreateFederatedUser("someIssuer", "someSubject", "dummy@example.com", Some("foo"), Some("Foo"))
|
||||
val actual = AccountFederationService.getOrCreateFederatedUser(
|
||||
"someIssuer",
|
||||
"someSubject",
|
||||
"dummy@example.com",
|
||||
Some("foo"),
|
||||
Some("Foo")
|
||||
)
|
||||
assert(actual.get.userName == "foo")
|
||||
assert(actual.get.password == "[DUMMY]")
|
||||
assert(actual.get.fullName == "Foo")
|
||||
@@ -22,7 +28,13 @@ class AccountFederationServiceSpec extends FunSpec with ServiceSpecBase {
|
||||
generateNewAccount("someUser")
|
||||
AccountFederationService.createAccountFederation("someIssuer", "someSubject", "someUser")
|
||||
|
||||
val actual = AccountFederationService.getOrCreateFederatedUser("someIssuer", "someSubject", "dummy@example.com", Some("dummy"), Some("dummy"))
|
||||
val actual = AccountFederationService.getOrCreateFederatedUser(
|
||||
"someIssuer",
|
||||
"someSubject",
|
||||
"dummy@example.com",
|
||||
Some("dummy"),
|
||||
Some("dummy")
|
||||
)
|
||||
assert(actual.get.userName == "someUser")
|
||||
}
|
||||
}
|
||||
@@ -32,7 +44,13 @@ class AccountFederationServiceSpec extends FunSpec with ServiceSpecBase {
|
||||
AccountFederationService.createAccountFederation("someIssuer", "someSubject", "someUser")
|
||||
AccountService.updateAccount(user.copy(isRemoved = true))
|
||||
|
||||
val actual = AccountFederationService.getOrCreateFederatedUser("someIssuer", "someSubject", "dummy@example.com", Some("dummy"), Some("dummy"))
|
||||
val actual = AccountFederationService.getOrCreateFederatedUser(
|
||||
"someIssuer",
|
||||
"someSubject",
|
||||
"dummy@example.com",
|
||||
Some("dummy"),
|
||||
Some("dummy")
|
||||
)
|
||||
assert(actual.isEmpty)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,23 +8,30 @@ class AccountServiceSpec extends FunSuite with ServiceSpecBase {
|
||||
|
||||
val RootMailAddress = "root@localhost"
|
||||
|
||||
test("getAllUsers") { withTestDB { implicit session =>
|
||||
test("getAllUsers") {
|
||||
withTestDB { implicit session =>
|
||||
assert(AccountService.getAllUsers() match {
|
||||
case List(Account("root", "root", RootMailAddress, _, true, _, _, _, None, None, false, false, None)) => true
|
||||
case _ => false
|
||||
})
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
test("getAccountByUserName") { withTestDB { implicit session =>
|
||||
test("getAccountByUserName") {
|
||||
withTestDB { implicit session =>
|
||||
assert(AccountService.getAccountByUserName("root").get.userName == "root")
|
||||
assert(AccountService.getAccountByUserName("invalid user name").isEmpty)
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
test("getAccountByMailAddress") { withTestDB { implicit session =>
|
||||
test("getAccountByMailAddress") {
|
||||
withTestDB { implicit session =>
|
||||
assert(AccountService.getAccountByMailAddress(RootMailAddress).isDefined)
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
test("updateLastLoginDate") { withTestDB { implicit session =>
|
||||
test("updateLastLoginDate") {
|
||||
withTestDB { implicit session =>
|
||||
val root = "root"
|
||||
def user() = AccountService.getAccountByUserName(root).getOrElse(sys.error(s"user $root does not exists"))
|
||||
|
||||
@@ -38,9 +45,11 @@ class AccountServiceSpec extends FunSuite with ServiceSpecBase {
|
||||
Thread.sleep(1000)
|
||||
AccountService.updateLastLoginDate(root)
|
||||
assert(user().lastLoginDate.get.compareTo(date2) > 0)
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
test("updateAccount") { withTestDB { implicit session =>
|
||||
test("updateAccount") {
|
||||
withTestDB { implicit session =>
|
||||
val root = "root"
|
||||
def user() = AccountService.getAccountByUserName(root).getOrElse(sys.error(s"user $root does not exists"))
|
||||
|
||||
@@ -55,9 +64,11 @@ class AccountServiceSpec extends FunSuite with ServiceSpecBase {
|
||||
val newDescription = Some("http://new.url.example/path")
|
||||
AccountService.updateAccount(user().copy(description = newDescription))
|
||||
assert(user().description == newDescription)
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
test("group") { withTestDB { implicit session =>
|
||||
test("group") {
|
||||
withTestDB { implicit session =>
|
||||
val group1 = "group1"
|
||||
val user1 = "root"
|
||||
AccountService.createGroup(group1, None, None)
|
||||
@@ -74,21 +85,26 @@ class AccountServiceSpec extends FunSuite with ServiceSpecBase {
|
||||
|
||||
assert(AccountService.getGroupMembers(group1) == Nil)
|
||||
assert(AccountService.getGroupsByUserName(user1) == Nil)
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
test("createGroup save description") { withTestDB { implicit session =>
|
||||
test("createGroup save description") {
|
||||
withTestDB { implicit session =>
|
||||
AccountService.createGroup("some-group", Some("some clever description"), None)
|
||||
val maybeGroup = AccountService.getAccountByUserName("some-group")
|
||||
|
||||
assert(maybeGroup.flatMap(_.description) == Some("some clever description"))
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
test("updateGroup save description") { withTestDB { implicit session =>
|
||||
test("updateGroup save description") {
|
||||
withTestDB { implicit session =>
|
||||
AccountService.createGroup("a-group", None, None)
|
||||
|
||||
AccountService.updateGroup("a-group", Some("new description"), None, false)
|
||||
|
||||
val group = AccountService.getAccountByUserName("a-group")
|
||||
assert(group.flatMap(_.description) == Some("new description"))
|
||||
}}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,12 @@ import gitbucket.core.model.Profile.profile._
|
||||
import gitbucket.core.model.Profile.profile.blockingApi._
|
||||
import org.scalatest.FunSuite
|
||||
|
||||
|
||||
class CommitStatusServiceSpec extends FunSuite with ServiceSpecBase with CommitStatusService
|
||||
with RepositoryService with AccountService{
|
||||
class CommitStatusServiceSpec
|
||||
extends FunSuite
|
||||
with ServiceSpecBase
|
||||
with CommitStatusService
|
||||
with RepositoryService
|
||||
with AccountService {
|
||||
val now = new java.util.Date()
|
||||
val fixture1 = CommitStatus(
|
||||
userName = "root",
|
||||
@@ -20,9 +23,11 @@ class CommitStatusServiceSpec extends FunSuite with ServiceSpecBase with CommitS
|
||||
targetUrl = Some("http://example.com/target"),
|
||||
description = Some("description"),
|
||||
updatedDate = now,
|
||||
registeredDate = now)
|
||||
def findById(id: Int)(implicit s:Session) = CommitStatuses.filter(_.byPrimaryKey(id)).firstOption
|
||||
def generateFixture1(tester:Account)(implicit s:Session) = createCommitStatus(
|
||||
registeredDate = now
|
||||
)
|
||||
def findById(id: Int)(implicit s: Session) = CommitStatuses.filter(_.byPrimaryKey(id)).firstOption
|
||||
def generateFixture1(tester: Account)(implicit s: Session) =
|
||||
createCommitStatus(
|
||||
userName = fixture1.userName,
|
||||
repositoryName = fixture1.repositoryName,
|
||||
sha = fixture1.commitId,
|
||||
@@ -31,12 +36,16 @@ class CommitStatusServiceSpec extends FunSuite with ServiceSpecBase with CommitS
|
||||
targetUrl = fixture1.targetUrl,
|
||||
description = fixture1.description,
|
||||
creator = tester,
|
||||
now = fixture1.registeredDate)
|
||||
test("createCommitState can insert and update") { withTestDB { implicit session =>
|
||||
now = fixture1.registeredDate
|
||||
)
|
||||
test("createCommitState can insert and update") {
|
||||
withTestDB { implicit session =>
|
||||
val tester = generateNewAccount(fixture1.creator)
|
||||
insertRepository(fixture1.repositoryName,fixture1.userName,None,false)
|
||||
val id = generateFixture1(tester:Account)
|
||||
assert(getCommitStatus(fixture1.userName, fixture1.repositoryName, id) == Some(fixture1.copy(commitStatusId=id)))
|
||||
insertRepository(fixture1.repositoryName, fixture1.userName, None, false)
|
||||
val id = generateFixture1(tester: Account)
|
||||
assert(
|
||||
getCommitStatus(fixture1.userName, fixture1.repositoryName, id) == Some(fixture1.copy(commitStatusId = id))
|
||||
)
|
||||
// other one can update
|
||||
val tester2 = generateNewAccount("tester2")
|
||||
val time2 = new java.util.Date()
|
||||
@@ -49,27 +58,44 @@ class CommitStatusServiceSpec extends FunSuite with ServiceSpecBase with CommitS
|
||||
targetUrl = Some("http://example.com/target2"),
|
||||
description = Some("description2"),
|
||||
creator = tester2,
|
||||
now = time2)
|
||||
assert(getCommitStatus(fixture1.userName, fixture1.repositoryName, id2) == Some(fixture1.copy(
|
||||
now = time2
|
||||
)
|
||||
assert(
|
||||
getCommitStatus(fixture1.userName, fixture1.repositoryName, id2) == Some(
|
||||
fixture1.copy(
|
||||
commitStatusId = id,
|
||||
creator = "tester2",
|
||||
state = CommitState.SUCCESS,
|
||||
targetUrl = Some("http://example.com/target2"),
|
||||
description = Some("description2"),
|
||||
updatedDate = time2)))
|
||||
}}
|
||||
updatedDate = time2
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
test("getCommitStatus can find by commitId and context") { withTestDB { implicit session =>
|
||||
test("getCommitStatus can find by commitId and context") {
|
||||
withTestDB { implicit session =>
|
||||
val tester = generateNewAccount(fixture1.creator)
|
||||
insertRepository(fixture1.repositoryName,fixture1.userName,None,false)
|
||||
val id = generateFixture1(tester:Account)
|
||||
assert(getCommitStatus(fixture1.userName, fixture1.repositoryName, fixture1.commitId, fixture1.context) == Some(fixture1.copy(commitStatusId=id)))
|
||||
}}
|
||||
insertRepository(fixture1.repositoryName, fixture1.userName, None, false)
|
||||
val id = generateFixture1(tester: Account)
|
||||
assert(
|
||||
getCommitStatus(fixture1.userName, fixture1.repositoryName, fixture1.commitId, fixture1.context) == Some(
|
||||
fixture1.copy(commitStatusId = id)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
test("getCommitStatus can find by commitStatusId") { withTestDB { implicit session =>
|
||||
test("getCommitStatus can find by commitStatusId") {
|
||||
withTestDB { implicit session =>
|
||||
val tester = generateNewAccount(fixture1.creator)
|
||||
insertRepository(fixture1.repositoryName,fixture1.userName,None,false)
|
||||
val id = generateFixture1(tester:Account)
|
||||
assert(getCommitStatus(fixture1.userName, fixture1.repositoryName, id) == Some(fixture1.copy(commitStatusId=id)))
|
||||
}}
|
||||
insertRepository(fixture1.repositoryName, fixture1.userName, None, false)
|
||||
val id = generateFixture1(tester: Account)
|
||||
assert(
|
||||
getCommitStatus(fixture1.userName, fixture1.repositoryName, id) == Some(fixture1.copy(commitStatusId = id))
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,44 +4,94 @@ import gitbucket.core.model._
|
||||
import gitbucket.core.service.IssuesService._
|
||||
import org.scalatest.FunSuite
|
||||
|
||||
|
||||
class IssuesServiceSpec extends FunSuite with ServiceSpecBase {
|
||||
test("getCommitStatues") {
|
||||
withTestDB { implicit session =>
|
||||
val user1 = generateNewUserWithDBRepository("user1","repo1")
|
||||
val user1 = generateNewUserWithDBRepository("user1", "repo1")
|
||||
|
||||
def getCommitStatues(issueId: Int) = dummyService.getCommitStatues("user1","repo1",issueId)
|
||||
def getCommitStatues(issueId: Int) = dummyService.getCommitStatues("user1", "repo1", issueId)
|
||||
|
||||
assert(getCommitStatues(1) == None)
|
||||
|
||||
val now = new java.util.Date()
|
||||
val issueId = generateNewIssue("user1","repo1")
|
||||
val issueId = generateNewIssue("user1", "repo1")
|
||||
assert(issueId == 1)
|
||||
|
||||
assert(getCommitStatues(1) == None)
|
||||
|
||||
val cs = dummyService.createCommitStatus("user1","repo1","shasha", "default", CommitState.SUCCESS, Some("http://exmple.com/ci"), Some("exampleService"), now, user1)
|
||||
val cs = dummyService.createCommitStatus(
|
||||
"user1",
|
||||
"repo1",
|
||||
"shasha",
|
||||
"default",
|
||||
CommitState.SUCCESS,
|
||||
Some("http://exmple.com/ci"),
|
||||
Some("exampleService"),
|
||||
now,
|
||||
user1
|
||||
)
|
||||
|
||||
assert(getCommitStatues(1) == None)
|
||||
|
||||
val (is2, pr2) = generateNewPullRequest("user1/repo1/master","user1/repo1/feature1")
|
||||
val (is2, pr2) = generateNewPullRequest("user1/repo1/master", "user1/repo1/feature1")
|
||||
assert(pr2.issueId == 2)
|
||||
|
||||
// if there are no statuses, state is none
|
||||
assert(getCommitStatues(2) == None)
|
||||
|
||||
// if there is a status, state is that
|
||||
val cs2 = dummyService.createCommitStatus("user1","repo1","feature1", "default", CommitState.SUCCESS, Some("http://exmple.com/ci"), Some("exampleService"), now, user1)
|
||||
assert(getCommitStatues(2) == Some(CommitStatusInfo(1,1,Some("default"),Some(CommitState.SUCCESS),Some("http://exmple.com/ci"),Some("exampleService"))))
|
||||
val cs2 = dummyService.createCommitStatus(
|
||||
"user1",
|
||||
"repo1",
|
||||
"feature1",
|
||||
"default",
|
||||
CommitState.SUCCESS,
|
||||
Some("http://exmple.com/ci"),
|
||||
Some("exampleService"),
|
||||
now,
|
||||
user1
|
||||
)
|
||||
assert(
|
||||
getCommitStatues(2) == Some(
|
||||
CommitStatusInfo(
|
||||
1,
|
||||
1,
|
||||
Some("default"),
|
||||
Some(CommitState.SUCCESS),
|
||||
Some("http://exmple.com/ci"),
|
||||
Some("exampleService")
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
// if there are two statuses, state is none
|
||||
val cs3 = dummyService.createCommitStatus("user1","repo1","feature1", "pend", CommitState.PENDING, Some("http://exmple.com/ci"), Some("exampleService"), now, user1)
|
||||
assert(getCommitStatues(2) == Some(CommitStatusInfo(2,1,None,None,None,None)))
|
||||
val cs3 = dummyService.createCommitStatus(
|
||||
"user1",
|
||||
"repo1",
|
||||
"feature1",
|
||||
"pend",
|
||||
CommitState.PENDING,
|
||||
Some("http://exmple.com/ci"),
|
||||
Some("exampleService"),
|
||||
now,
|
||||
user1
|
||||
)
|
||||
assert(getCommitStatues(2) == Some(CommitStatusInfo(2, 1, None, None, None, None)))
|
||||
|
||||
// get only statuses in query issues
|
||||
val (is3, pr3) = generateNewPullRequest("user1/repo1/master","user1/repo1/feature3")
|
||||
val cs4 = dummyService.createCommitStatus("user1","repo1","feature3", "none", CommitState.PENDING, None, None, now, user1)
|
||||
assert(getCommitStatues(2) == Some(CommitStatusInfo(2,1,None,None,None,None)))
|
||||
val (is3, pr3) = generateNewPullRequest("user1/repo1/master", "user1/repo1/feature3")
|
||||
val cs4 = dummyService.createCommitStatus(
|
||||
"user1",
|
||||
"repo1",
|
||||
"feature3",
|
||||
"none",
|
||||
CommitState.PENDING,
|
||||
None,
|
||||
None,
|
||||
now,
|
||||
user1
|
||||
)
|
||||
assert(getCommitStatues(2) == Some(CommitStatusInfo(2, 1, None, None, None, None)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,8 @@ import org.scalatest.FunSpec
|
||||
|
||||
class LabelsServiceSpec extends FunSpec with ServiceSpecBase {
|
||||
describe("getLabels") {
|
||||
it("should be empty when not have any labels") { withTestDB { implicit session =>
|
||||
it("should be empty when not have any labels") {
|
||||
withTestDB { implicit session =>
|
||||
generateNewUserWithDBRepository("user1", "repo1")
|
||||
|
||||
generateNewUserWithDBRepository("user1", "repo2")
|
||||
@@ -15,8 +16,10 @@ class LabelsServiceSpec extends FunSpec with ServiceSpecBase {
|
||||
dummyService.createLabel("user2", "repo1", "label1", "000000")
|
||||
|
||||
assert(dummyService.getLabels("user1", "repo1").isEmpty)
|
||||
}}
|
||||
it("should return contained labels") { withTestDB { implicit session =>
|
||||
}
|
||||
}
|
||||
it("should return contained labels") {
|
||||
withTestDB { implicit session =>
|
||||
generateNewUserWithDBRepository("user1", "repo1")
|
||||
val labelId1 = dummyService.createLabel("user1", "repo1", "label1", "000000")
|
||||
val labelId2 = dummyService.createLabel("user1", "repo1", "label2", "ffffff")
|
||||
@@ -30,21 +33,27 @@ class LabelsServiceSpec extends FunSpec with ServiceSpecBase {
|
||||
def getLabels = dummyService.getLabels("user1", "repo1")
|
||||
|
||||
assert(getLabels.length == 2)
|
||||
assert(getLabels == List(
|
||||
assert(
|
||||
getLabels == List(
|
||||
Label("user1", "repo1", labelId1, "label1", "000000"),
|
||||
Label("user1", "repo1", labelId2, "label2", "ffffff"))
|
||||
Label("user1", "repo1", labelId2, "label2", "ffffff")
|
||||
)
|
||||
}}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
describe("getLabel") {
|
||||
it("should return None when the label not exist") { withTestDB { implicit session =>
|
||||
it("should return None when the label not exist") {
|
||||
withTestDB { implicit session =>
|
||||
generateNewUserWithDBRepository("user1", "repo1")
|
||||
|
||||
assert(dummyService.getLabel("user1", "repo1", 1) == None)
|
||||
assert(dummyService.getLabel("user1", "repo1", "label1") == None)
|
||||
}}
|
||||
it("should return a label fetched by label id") { withTestDB { implicit session =>
|
||||
}
|
||||
}
|
||||
it("should return a label fetched by label id") {
|
||||
withTestDB { implicit session =>
|
||||
generateNewUserWithDBRepository("user1", "repo1")
|
||||
val labelId1 = dummyService.createLabel("user1", "repo1", "label1", "000000")
|
||||
dummyService.createLabel("user1", "repo1", "label2", "ffffff")
|
||||
@@ -57,8 +66,10 @@ class LabelsServiceSpec extends FunSpec with ServiceSpecBase {
|
||||
|
||||
def getLabel = dummyService.getLabel("user1", "repo1", labelId1)
|
||||
assert(getLabel == Some(Label("user1", "repo1", labelId1, "label1", "000000")))
|
||||
}}
|
||||
it("should return a label fetched by label name") { withTestDB { implicit session =>
|
||||
}
|
||||
}
|
||||
it("should return a label fetched by label name") {
|
||||
withTestDB { implicit session =>
|
||||
generateNewUserWithDBRepository("user1", "repo1")
|
||||
val labelId1 = dummyService.createLabel("user1", "repo1", "label1", "000000")
|
||||
dummyService.createLabel("user1", "repo1", "label2", "ffffff")
|
||||
@@ -71,10 +82,12 @@ class LabelsServiceSpec extends FunSpec with ServiceSpecBase {
|
||||
|
||||
def getLabel = dummyService.getLabel("user1", "repo1", "label1")
|
||||
getLabel == Some(Label("user1", "repo1", labelId1, "label1", "000000"))
|
||||
}}
|
||||
}
|
||||
}
|
||||
}
|
||||
describe("createLabel") {
|
||||
it("should return accurate label id") { withTestDB { implicit session =>
|
||||
it("should return accurate label id") {
|
||||
withTestDB { implicit session =>
|
||||
generateNewUserWithDBRepository("user1", "repo1")
|
||||
generateNewUserWithDBRepository("user1", "repo2")
|
||||
generateNewUserWithDBRepository("user2", "repo1")
|
||||
@@ -85,10 +98,12 @@ class LabelsServiceSpec extends FunSpec with ServiceSpecBase {
|
||||
assert(labelId == 4)
|
||||
def getLabel = dummyService.getLabel("user1", "repo1", labelId)
|
||||
assert(getLabel == Some(Label("user1", "repo1", labelId, "label2", "000000")))
|
||||
}}
|
||||
}
|
||||
}
|
||||
}
|
||||
describe("updateLabel") {
|
||||
it("should change target label") { withTestDB { implicit session =>
|
||||
it("should change target label") {
|
||||
withTestDB { implicit session =>
|
||||
generateNewUserWithDBRepository("user1", "repo1")
|
||||
generateNewUserWithDBRepository("user1", "repo2")
|
||||
generateNewUserWithDBRepository("user2", "repo1")
|
||||
@@ -98,10 +113,12 @@ class LabelsServiceSpec extends FunSpec with ServiceSpecBase {
|
||||
dummyService.updateLabel("user1", "repo1", labelId, "updated-label", "ffffff")
|
||||
def getLabel = dummyService.getLabel("user1", "repo1", labelId)
|
||||
assert(getLabel == Some(Label("user1", "repo1", labelId, "updated-label", "ffffff")))
|
||||
}}
|
||||
}
|
||||
}
|
||||
}
|
||||
describe("deleteLabel") {
|
||||
it("should remove target label") { withTestDB { implicit session =>
|
||||
it("should remove target label") {
|
||||
withTestDB { implicit session =>
|
||||
generateNewUserWithDBRepository("user1", "repo1")
|
||||
generateNewUserWithDBRepository("user1", "repo2")
|
||||
generateNewUserWithDBRepository("user2", "repo1")
|
||||
@@ -110,6 +127,7 @@ class LabelsServiceSpec extends FunSpec with ServiceSpecBase {
|
||||
dummyService.createLabel("user2", "repo1", "label1", "000000")
|
||||
dummyService.deleteLabel("user1", "repo1", labelId)
|
||||
assert(dummyService.getLabel("user1", "repo1", labelId) == None)
|
||||
}}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,32 +12,32 @@ import org.scalatest.FunSpec
|
||||
import java.io.File
|
||||
|
||||
class MergeServiceSpec extends FunSpec {
|
||||
val service = new MergeService{}
|
||||
val service = new MergeService {}
|
||||
val branch = "master"
|
||||
val issueId = 10
|
||||
def initRepository(owner:String, name:String): File = {
|
||||
def initRepository(owner: String, name: String): File = {
|
||||
val dir = createTestRepository(getRepositoryDir(owner, name))
|
||||
using(Git.open(dir)){ git =>
|
||||
createFile(git, "refs/heads/master", "test.txt", "hoge" )
|
||||
using(Git.open(dir)) { git =>
|
||||
createFile(git, "refs/heads/master", "test.txt", "hoge")
|
||||
git.branchCreate().setStartPoint(s"refs/heads/master").setName(s"refs/pull/${issueId}/head").call()
|
||||
}
|
||||
dir
|
||||
}
|
||||
def createConfrict(git:Git) = {
|
||||
createFile(git, s"refs/heads/${branch}", "test.txt", "hoge2" )
|
||||
createFile(git, s"refs/pull/${issueId}/head", "test.txt", "hoge4" )
|
||||
def createConfrict(git: Git) = {
|
||||
createFile(git, s"refs/heads/${branch}", "test.txt", "hoge2")
|
||||
createFile(git, s"refs/pull/${issueId}/head", "test.txt", "hoge4")
|
||||
}
|
||||
describe("checkConflict, checkConflictCache") {
|
||||
it("checkConflict false if not conflicted, and create cache") {
|
||||
val repo1Dir = initRepository("user1","repo1")
|
||||
val repo1Dir = initRepository("user1", "repo1")
|
||||
assert(service.checkConflictCache("user1", "repo1", branch, issueId) == None)
|
||||
val conflicted = service.checkConflict("user1", "repo1", branch, issueId)
|
||||
assert(service.checkConflictCache("user1", "repo1", branch, issueId) == Some(None))
|
||||
assert(conflicted.isEmpty)
|
||||
}
|
||||
it("checkConflict true if not conflicted, and create cache") {
|
||||
val repo2Dir = initRepository("user1","repo2")
|
||||
using(Git.open(repo2Dir)){ git =>
|
||||
val repo2Dir = initRepository("user1", "repo2")
|
||||
using(Git.open(repo2Dir)) { git =>
|
||||
createConfrict(git)
|
||||
}
|
||||
assert(service.checkConflictCache("user1", "repo2", branch, issueId) == None)
|
||||
@@ -51,35 +51,35 @@ class MergeServiceSpec extends FunSpec {
|
||||
}
|
||||
describe("checkConflictCache") {
|
||||
it("merged cache invalid if origin branch moved") {
|
||||
val repo3Dir = initRepository("user1","repo3")
|
||||
val repo3Dir = initRepository("user1", "repo3")
|
||||
assert(service.checkConflict("user1", "repo3", branch, issueId).isEmpty)
|
||||
assert(service.checkConflictCache("user1", "repo3", branch, issueId) == Some(None))
|
||||
using(Git.open(repo3Dir)){ git =>
|
||||
createFile(git, s"refs/heads/${branch}", "test.txt", "hoge2" )
|
||||
using(Git.open(repo3Dir)) { git =>
|
||||
createFile(git, s"refs/heads/${branch}", "test.txt", "hoge2")
|
||||
}
|
||||
assert(service.checkConflictCache("user1", "repo3", branch, issueId) == None)
|
||||
}
|
||||
it("merged cache invalid if request branch moved") {
|
||||
val repo4Dir = initRepository("user1","repo4")
|
||||
val repo4Dir = initRepository("user1", "repo4")
|
||||
assert(service.checkConflict("user1", "repo4", branch, issueId).isEmpty)
|
||||
assert(service.checkConflictCache("user1", "repo4", branch, issueId) == Some(None))
|
||||
using(Git.open(repo4Dir)){ git =>
|
||||
createFile(git, s"refs/pull/${issueId}/head", "test.txt", "hoge4" )
|
||||
using(Git.open(repo4Dir)) { git =>
|
||||
createFile(git, s"refs/pull/${issueId}/head", "test.txt", "hoge4")
|
||||
}
|
||||
assert(service.checkConflictCache("user1", "repo4", branch, issueId) == None)
|
||||
}
|
||||
it("should merged cache invalid if origin branch moved") {
|
||||
val repo5Dir = initRepository("user1","repo5")
|
||||
val repo5Dir = initRepository("user1", "repo5")
|
||||
assert(service.checkConflict("user1", "repo5", branch, issueId).isEmpty)
|
||||
assert(service.checkConflictCache("user1", "repo5", branch, issueId) == Some(None))
|
||||
using(Git.open(repo5Dir)){ git =>
|
||||
createFile(git, s"refs/heads/${branch}", "test.txt", "hoge2" )
|
||||
using(Git.open(repo5Dir)) { git =>
|
||||
createFile(git, s"refs/heads/${branch}", "test.txt", "hoge2")
|
||||
}
|
||||
assert(service.checkConflictCache("user1", "repo5", branch, issueId) == None)
|
||||
}
|
||||
it("conflicted cache invalid if request branch moved") {
|
||||
val repo6Dir = initRepository("user1","repo6")
|
||||
using(Git.open(repo6Dir)){ git =>
|
||||
val repo6Dir = initRepository("user1", "repo6")
|
||||
using(Git.open(repo6Dir)) { git =>
|
||||
createConfrict(git)
|
||||
}
|
||||
assert(service.checkConflict("user1", "repo6", branch, issueId).isDefined)
|
||||
@@ -87,14 +87,14 @@ class MergeServiceSpec extends FunSpec {
|
||||
case Some(Some(_: String)) => true
|
||||
case _ => false
|
||||
})
|
||||
using(Git.open(repo6Dir)){ git =>
|
||||
createFile(git, s"refs/pull/${issueId}/head", "test.txt", "hoge4" )
|
||||
using(Git.open(repo6Dir)) { git =>
|
||||
createFile(git, s"refs/pull/${issueId}/head", "test.txt", "hoge4")
|
||||
}
|
||||
assert(service.checkConflictCache("user1", "repo6", branch, issueId) == None)
|
||||
}
|
||||
it("conflicted cache invalid if origin branch moved") {
|
||||
val repo7Dir = initRepository("user1","repo7")
|
||||
using(Git.open(repo7Dir)){ git =>
|
||||
val repo7Dir = initRepository("user1", "repo7")
|
||||
using(Git.open(repo7Dir)) { git =>
|
||||
createConfrict(git)
|
||||
}
|
||||
assert(service.checkConflict("user1", "repo7", branch, issueId).isDefined)
|
||||
@@ -102,17 +102,17 @@ class MergeServiceSpec extends FunSpec {
|
||||
case Some(Some(_)) => true
|
||||
case _ => false
|
||||
})
|
||||
using(Git.open(repo7Dir)){ git =>
|
||||
createFile(git, s"refs/heads/${branch}", "test.txt", "hoge4" )
|
||||
using(Git.open(repo7Dir)) { git =>
|
||||
createFile(git, s"refs/heads/${branch}", "test.txt", "hoge4")
|
||||
}
|
||||
assert(service.checkConflictCache("user1", "repo7", branch, issueId) == None)
|
||||
}
|
||||
}
|
||||
describe("mergePullRequest") {
|
||||
it("can merge") {
|
||||
val repo8Dir = initRepository("user1","repo8")
|
||||
using(Git.open(repo8Dir)){ git =>
|
||||
createFile(git, s"refs/pull/${issueId}/head", "test.txt", "hoge2" )
|
||||
val repo8Dir = initRepository("user1", "repo8")
|
||||
using(Git.open(repo8Dir)) { git =>
|
||||
createFile(git, s"refs/pull/${issueId}/head", "test.txt", "hoge2")
|
||||
val committer = new PersonIdent("dummy2", "dummy2@example.com")
|
||||
assert(getFile(git, branch, "test.txt").content.get == "hoge")
|
||||
val requestBranchId = git.getRepository.resolve(s"refs/pull/${issueId}/head")
|
||||
@@ -123,7 +123,7 @@ class MergeServiceSpec extends FunSpec {
|
||||
assert(commit.getCommitterIdent() == committer)
|
||||
assert(commit.getAuthorIdent() == committer)
|
||||
assert(commit.getFullMessage() == "merged")
|
||||
assert(commit.getParents.toSet == Set( requestBranchId, masterId ))
|
||||
assert(commit.getParents.toSet == Set(requestBranchId, masterId))
|
||||
assert(getFile(git, branch, "test.txt").content.get == "hoge2")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,11 @@ import gitbucket.core.model.CommitState
|
||||
import gitbucket.core.service.ProtectedBranchService.{ProtectedBranchReceiveHook, ProtectedBranchInfo}
|
||||
import org.scalatest.FunSpec
|
||||
|
||||
class ProtectedBranchServiceSpec extends FunSpec with ServiceSpecBase with ProtectedBranchService with CommitStatusService {
|
||||
class ProtectedBranchServiceSpec
|
||||
extends FunSpec
|
||||
with ServiceSpecBase
|
||||
with ProtectedBranchService
|
||||
with CommitStatusService {
|
||||
|
||||
val receiveHook = new ProtectedBranchReceiveHook()
|
||||
val now = new java.util.Date()
|
||||
@@ -24,9 +28,19 @@ class ProtectedBranchServiceSpec extends FunSpec with ServiceSpecBase with Prote
|
||||
withTestDB { implicit session =>
|
||||
generateNewUserWithDBRepository("user1", "repo1")
|
||||
enableBranchProtection("user1", "repo1", "branch", false, Nil)
|
||||
assert(getProtectedBranchInfo("user1", "repo1", "branch") == ProtectedBranchInfo("user1", "repo1", true, Nil, false))
|
||||
enableBranchProtection("user1", "repo1", "branch", true, Seq("hoge","huge"))
|
||||
assert(getProtectedBranchInfo("user1", "repo1", "branch") == ProtectedBranchInfo("user1", "repo1", true, Seq("hoge","huge"), true))
|
||||
assert(
|
||||
getProtectedBranchInfo("user1", "repo1", "branch") == ProtectedBranchInfo("user1", "repo1", true, Nil, false)
|
||||
)
|
||||
enableBranchProtection("user1", "repo1", "branch", true, Seq("hoge", "huge"))
|
||||
assert(
|
||||
getProtectedBranchInfo("user1", "repo1", "branch") == ProtectedBranchInfo(
|
||||
"user1",
|
||||
"repo1",
|
||||
true,
|
||||
Seq("hoge", "huge"),
|
||||
true
|
||||
)
|
||||
)
|
||||
disableBranchProtection("user1", "repo1", "branch")
|
||||
assert(getProtectedBranchInfo("user1", "repo1", "branch") == ProtectedBranchInfo.disabled("user1", "repo1"))
|
||||
}
|
||||
@@ -54,11 +68,18 @@ class ProtectedBranchServiceSpec extends FunSpec with ServiceSpecBase with Prote
|
||||
withTestRepository { git =>
|
||||
val rp = new ReceivePack(git.getRepository)
|
||||
rp.setAllowNonFastForwards(true)
|
||||
val rc = new ReceiveCommand(ObjectId.fromString(sha), ObjectId.fromString(sha2), "refs/heads/branch", ReceiveCommand.Type.UPDATE_NONFASTFORWARD)
|
||||
val rc = new ReceiveCommand(
|
||||
ObjectId.fromString(sha),
|
||||
ObjectId.fromString(sha2),
|
||||
"refs/heads/branch",
|
||||
ReceiveCommand.Type.UPDATE_NONFASTFORWARD
|
||||
)
|
||||
generateNewUserWithDBRepository("user1", "repo1")
|
||||
assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user1") == None)
|
||||
enableBranchProtection("user1", "repo1", "branch", false, Nil)
|
||||
assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user1") == Some("Cannot force-push to a protected branch"))
|
||||
assert(
|
||||
receiveHook.preReceive("user1", "repo1", rp, rc, "user1") == Some("Cannot force-push to a protected branch")
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,11 +88,18 @@ class ProtectedBranchServiceSpec extends FunSpec with ServiceSpecBase with Prote
|
||||
withTestRepository { git =>
|
||||
val rp = new ReceivePack(git.getRepository)
|
||||
rp.setAllowNonFastForwards(true)
|
||||
val rc = new ReceiveCommand(ObjectId.fromString(sha), ObjectId.fromString(sha2), "refs/heads/branch", ReceiveCommand.Type.UPDATE_NONFASTFORWARD)
|
||||
val rc = new ReceiveCommand(
|
||||
ObjectId.fromString(sha),
|
||||
ObjectId.fromString(sha2),
|
||||
"refs/heads/branch",
|
||||
ReceiveCommand.Type.UPDATE_NONFASTFORWARD
|
||||
)
|
||||
generateNewUserWithDBRepository("user1", "repo1")
|
||||
assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user2") == None)
|
||||
enableBranchProtection("user1", "repo1", "branch", false, Nil)
|
||||
assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user2") == Some("Cannot force-push to a protected branch"))
|
||||
assert(
|
||||
receiveHook.preReceive("user1", "repo1", rp, rc, "user2") == Some("Cannot force-push to a protected branch")
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,17 +108,38 @@ class ProtectedBranchServiceSpec extends FunSpec with ServiceSpecBase with Prote
|
||||
withTestRepository { git =>
|
||||
val rp = new ReceivePack(git.getRepository)
|
||||
rp.setAllowNonFastForwards(false)
|
||||
val rc = new ReceiveCommand(ObjectId.fromString(sha), ObjectId.fromString(sha2), "refs/heads/branch", ReceiveCommand.Type.UPDATE)
|
||||
val rc = new ReceiveCommand(
|
||||
ObjectId.fromString(sha),
|
||||
ObjectId.fromString(sha2),
|
||||
"refs/heads/branch",
|
||||
ReceiveCommand.Type.UPDATE
|
||||
)
|
||||
val user1 = generateNewUserWithDBRepository("user1", "repo1")
|
||||
assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user2") == None)
|
||||
enableBranchProtection("user1", "repo1", "branch", false, Seq("must"))
|
||||
assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user2") == Some("Required status check \"must\" is expected"))
|
||||
assert(
|
||||
receiveHook.preReceive("user1", "repo1", rp, rc, "user2") == Some(
|
||||
"Required status check \"must\" is expected"
|
||||
)
|
||||
)
|
||||
enableBranchProtection("user1", "repo1", "branch", false, Seq("must", "must2"))
|
||||
assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user2") == Some("2 of 2 required status checks are expected"))
|
||||
assert(
|
||||
receiveHook.preReceive("user1", "repo1", rp, rc, "user2") == Some(
|
||||
"2 of 2 required status checks are expected"
|
||||
)
|
||||
)
|
||||
createCommitStatus("user1", "repo1", sha2, "context", CommitState.SUCCESS, None, None, now, user1)
|
||||
assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user2") == Some("2 of 2 required status checks are expected"))
|
||||
assert(
|
||||
receiveHook.preReceive("user1", "repo1", rp, rc, "user2") == Some(
|
||||
"2 of 2 required status checks are expected"
|
||||
)
|
||||
)
|
||||
createCommitStatus("user1", "repo1", sha2, "must", CommitState.SUCCESS, None, None, now, user1)
|
||||
assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user2") == Some("Required status check \"must2\" is expected"))
|
||||
assert(
|
||||
receiveHook.preReceive("user1", "repo1", rp, rc, "user2") == Some(
|
||||
"Required status check \"must2\" is expected"
|
||||
)
|
||||
)
|
||||
createCommitStatus("user1", "repo1", sha2, "must2", CommitState.SUCCESS, None, None, now, user1)
|
||||
assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user2") == None)
|
||||
}
|
||||
@@ -101,21 +150,42 @@ class ProtectedBranchServiceSpec extends FunSpec with ServiceSpecBase with Prote
|
||||
withTestRepository { git =>
|
||||
val rp = new ReceivePack(git.getRepository)
|
||||
rp.setAllowNonFastForwards(false)
|
||||
val rc = new ReceiveCommand(ObjectId.fromString(sha), ObjectId.fromString(sha2), "refs/heads/branch", ReceiveCommand.Type.UPDATE)
|
||||
val rc = new ReceiveCommand(
|
||||
ObjectId.fromString(sha),
|
||||
ObjectId.fromString(sha2),
|
||||
"refs/heads/branch",
|
||||
ReceiveCommand.Type.UPDATE
|
||||
)
|
||||
val user1 = generateNewUserWithDBRepository("user1", "repo1")
|
||||
assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user1") == None)
|
||||
enableBranchProtection("user1", "repo1", "branch", false, Seq("must"))
|
||||
assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user1") == None)
|
||||
enableBranchProtection("user1", "repo1", "branch", true, Seq("must"))
|
||||
assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user1") == Some("Required status check \"must\" is expected"))
|
||||
assert(
|
||||
receiveHook.preReceive("user1", "repo1", rp, rc, "user1") == Some(
|
||||
"Required status check \"must\" is expected"
|
||||
)
|
||||
)
|
||||
enableBranchProtection("user1", "repo1", "branch", false, Seq("must", "must2"))
|
||||
assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user1") == None)
|
||||
enableBranchProtection("user1", "repo1", "branch", true, Seq("must", "must2"))
|
||||
assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user1") == Some("2 of 2 required status checks are expected"))
|
||||
assert(
|
||||
receiveHook.preReceive("user1", "repo1", rp, rc, "user1") == Some(
|
||||
"2 of 2 required status checks are expected"
|
||||
)
|
||||
)
|
||||
createCommitStatus("user1", "repo1", sha2, "context", CommitState.SUCCESS, None, None, now, user1)
|
||||
assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user1") == Some("2 of 2 required status checks are expected"))
|
||||
assert(
|
||||
receiveHook.preReceive("user1", "repo1", rp, rc, "user1") == Some(
|
||||
"2 of 2 required status checks are expected"
|
||||
)
|
||||
)
|
||||
createCommitStatus("user1", "repo1", sha2, "must", CommitState.SUCCESS, None, None, now, user1)
|
||||
assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user1") == Some("Required status check \"must2\" is expected"))
|
||||
assert(
|
||||
receiveHook.preReceive("user1", "repo1", rp, rc, "user1") == Some(
|
||||
"Required status check \"must2\" is expected"
|
||||
)
|
||||
)
|
||||
createCommitStatus("user1", "repo1", sha2, "must2", CommitState.SUCCESS, None, None, now, user1)
|
||||
assert(receiveHook.preReceive("user1", "repo1", rp, rc, "user1") == None)
|
||||
}
|
||||
@@ -139,7 +209,7 @@ class ProtectedBranchServiceSpec extends FunSpec with ServiceSpecBase with Prote
|
||||
generateNewAccount("user2")
|
||||
generateNewAccount("user3")
|
||||
|
||||
x.updateGroupMembers("grp1", List("user1"->true, "user2"->false))
|
||||
x.updateGroupMembers("grp1", List("user1" -> true, "user2" -> false))
|
||||
assert(x.isAdministrator("user1") == true)
|
||||
assert(x.isAdministrator("user2") == false)
|
||||
assert(x.isAdministrator("user3") == false)
|
||||
@@ -181,8 +251,8 @@ class ProtectedBranchServiceSpec extends FunSpec with ServiceSpecBase with Prote
|
||||
withTestDB { implicit session =>
|
||||
assert(ProtectedBranchInfo("user1", "repo1", true, Seq("must"), false).needStatusCheck("user2") == true)
|
||||
assert(ProtectedBranchInfo("user1", "repo1", true, Seq("must"), false).needStatusCheck("user1") == false)
|
||||
assert(ProtectedBranchInfo("user1", "repo1", true, Seq("must"), true ).needStatusCheck("user2") == true)
|
||||
assert(ProtectedBranchInfo("user1", "repo1", true, Seq("must"), true ).needStatusCheck("user1") == true)
|
||||
assert(ProtectedBranchInfo("user1", "repo1", true, Seq("must"), true).needStatusCheck("user2") == true)
|
||||
assert(ProtectedBranchInfo("user1", "repo1", true, Seq("must"), true).needStatusCheck("user1") == true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,17 @@ package gitbucket.core.service
|
||||
import gitbucket.core.model._
|
||||
import org.scalatest.FunSpec
|
||||
|
||||
class PullRequestServiceSpec extends FunSpec with ServiceSpecBase
|
||||
with PullRequestService with IssuesService with AccountService with RepositoryService with CommitsService
|
||||
with LabelsService with MilestonesService with PrioritiesService {
|
||||
class PullRequestServiceSpec
|
||||
extends FunSpec
|
||||
with ServiceSpecBase
|
||||
with PullRequestService
|
||||
with IssuesService
|
||||
with AccountService
|
||||
with RepositoryService
|
||||
with CommitsService
|
||||
with LabelsService
|
||||
with MilestonesService
|
||||
with PrioritiesService {
|
||||
|
||||
def swap(r: (Issue, PullRequest)) = (r._2 -> r._1)
|
||||
|
||||
@@ -13,7 +21,8 @@ class PullRequestServiceSpec extends FunSpec with ServiceSpecBase
|
||||
it("""should
|
||||
|return pull request if exists pull request from `branch` to `defaultBranch` and not closed.
|
||||
|return pull request if exists pull request from `branch` to other branch and not closed.
|
||||
|return None if all pull request is closed""".stripMargin.trim) { withTestDB { implicit se =>
|
||||
|return None if all pull request is closed""".stripMargin.trim) {
|
||||
withTestDB { implicit se =>
|
||||
generateNewUserWithDBRepository("user1", "repo1")
|
||||
generateNewUserWithDBRepository("user1", "repo2")
|
||||
generateNewUserWithDBRepository("user2", "repo1")
|
||||
@@ -30,6 +39,7 @@ class PullRequestServiceSpec extends FunSpec with ServiceSpecBase
|
||||
updateClosed("user1", "repo1", r1._1.issueId, true)
|
||||
updateClosed("user1", "repo1", r3._1.issueId, true)
|
||||
assert(getPullRequestFromBranch("user1", "repo1", "head1", "master") == None)
|
||||
} }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,9 @@ package gitbucket.core.service
|
||||
import gitbucket.core.model._
|
||||
import org.scalatest.FunSuite
|
||||
|
||||
class RepositoryServiceSpec extends FunSuite with ServiceSpecBase with RepositoryService with AccountService{
|
||||
test("renameRepository can rename CommitState, ProtectedBranches") { withTestDB { implicit session =>
|
||||
class RepositoryServiceSpec extends FunSuite with ServiceSpecBase with RepositoryService with AccountService {
|
||||
test("renameRepository can rename CommitState, ProtectedBranches") {
|
||||
withTestDB { implicit session =>
|
||||
val tester = generateNewAccount("tester")
|
||||
insertRepository("repo", "root", None, false)
|
||||
val service = new CommitStatusService with ProtectedBranchService {}
|
||||
@@ -17,17 +18,22 @@ class RepositoryServiceSpec extends FunSuite with ServiceSpecBase with Repositor
|
||||
targetUrl = Some("http://example.com/target"),
|
||||
description = Some("description"),
|
||||
creator = tester,
|
||||
now = new java.util.Date)
|
||||
now = new java.util.Date
|
||||
)
|
||||
|
||||
service.enableBranchProtection("root", "repo", "branch", true, Seq("must1", "must2"))
|
||||
|
||||
val orgPbi = service.getProtectedBranchInfo("root", "repo", "branch")
|
||||
val org = service.getCommitStatus("root","repo", id).get
|
||||
val org = service.getCommitStatus("root", "repo", id).get
|
||||
|
||||
renameRepository("root","repo","tester","repo2")
|
||||
renameRepository("root", "repo", "tester", "repo2")
|
||||
|
||||
val neo = service.getCommitStatus("tester","repo2", org.commitId, org.context).get
|
||||
val neo = service.getCommitStatus("tester", "repo2", org.commitId, org.context).get
|
||||
assert(neo == org.copy(commitStatusId = neo.commitStatusId, repositoryName = "repo2", userName = "tester"))
|
||||
assert(service.getProtectedBranchInfo("tester", "repo2", "branch") == orgPbi.copy(owner = "tester", repository = "repo2"))
|
||||
}}
|
||||
assert(
|
||||
service.getProtectedBranchInfo("tester", "repo2", "branch") == orgPbi
|
||||
.copy(owner = "tester", repository = "repo2")
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,14 +18,13 @@ import java.io.File
|
||||
|
||||
import scala.util.Random
|
||||
|
||||
|
||||
trait ServiceSpecBase {
|
||||
|
||||
def withTestDB[A](action: (Session) => A): A = {
|
||||
FileUtil.withTmpDir(new File(FileUtils.getTempDirectory(), Random.alphanumeric.take(10).mkString)){ dir =>
|
||||
FileUtil.withTmpDir(new File(FileUtils.getTempDirectory(), Random.alphanumeric.take(10).mkString)) { dir =>
|
||||
val (url, user, pass) = (DatabaseConfig.url(Some(dir.toString)), DatabaseConfig.user, DatabaseConfig.password)
|
||||
org.h2.Driver.load()
|
||||
using(DriverManager.getConnection(url, user, pass)){ conn =>
|
||||
using(DriverManager.getConnection(url, user, pass)) { conn =>
|
||||
val solidbase = new Solidbase()
|
||||
val db = new H2Database()
|
||||
db.setConnection(new JdbcConnection(conn)) // TODO Remove setConnection in the future
|
||||
@@ -37,23 +36,25 @@ trait ServiceSpecBase {
|
||||
}
|
||||
}
|
||||
|
||||
def generateNewAccount(name:String)(implicit s:Session):Account = {
|
||||
def generateNewAccount(name: String)(implicit s: Session): Account = {
|
||||
AccountService.createAccount(name, name, name, s"${name}@example.com", false, None, None)
|
||||
user(name)
|
||||
}
|
||||
|
||||
def user(name:String)(implicit s:Session):Account = AccountService.getAccountByUserName(name).get
|
||||
def user(name: String)(implicit s: Session): Account = AccountService.getAccountByUserName(name).get
|
||||
|
||||
lazy val dummyService = new RepositoryService with AccountService with IssuesService with PullRequestService
|
||||
with CommitsService with CommitStatusService with LabelsService with MilestonesService with PrioritiesService (){}
|
||||
with CommitsService with CommitStatusService with LabelsService with MilestonesService with PrioritiesService() {}
|
||||
|
||||
def generateNewUserWithDBRepository(userName:String, repositoryName:String)(implicit s:Session):Account = {
|
||||
def generateNewUserWithDBRepository(userName: String, repositoryName: String)(implicit s: Session): Account = {
|
||||
val ac = AccountService.getAccountByUserName(userName).getOrElse(generateNewAccount(userName))
|
||||
dummyService.insertRepository(repositoryName, userName, None, false)
|
||||
ac
|
||||
}
|
||||
|
||||
def generateNewIssue(userName:String, repositoryName:String, loginUser:String="root")(implicit s:Session): Int = {
|
||||
def generateNewIssue(userName: String, repositoryName: String, loginUser: String = "root")(
|
||||
implicit s: Session
|
||||
): Int = {
|
||||
dummyService.insertIssue(
|
||||
owner = userName,
|
||||
repository = repositoryName,
|
||||
@@ -63,12 +64,15 @@ trait ServiceSpecBase {
|
||||
assignedUserName = None,
|
||||
milestoneId = None,
|
||||
priorityId = None,
|
||||
isPullRequest = true)
|
||||
isPullRequest = true
|
||||
)
|
||||
}
|
||||
|
||||
def generateNewPullRequest(base:String, request:String, loginUser:String=null)(implicit s:Session):(Issue, PullRequest) = {
|
||||
val Array(baseUserName, baseRepositoryName, baesBranch)=base.split("/")
|
||||
val Array(requestUserName, requestRepositoryName, requestBranch)=request.split("/")
|
||||
def generateNewPullRequest(base: String, request: String, loginUser: String = null)(
|
||||
implicit s: Session
|
||||
): (Issue, PullRequest) = {
|
||||
val Array(baseUserName, baseRepositoryName, baesBranch) = base.split("/")
|
||||
val Array(requestUserName, requestRepositoryName, requestBranch) = request.split("/")
|
||||
val issueId = generateNewIssue(baseUserName, baseRepositoryName, Option(loginUser).getOrElse(requestUserName))
|
||||
dummyService.createPullRequest(
|
||||
originUserName = baseUserName,
|
||||
@@ -79,7 +83,8 @@ trait ServiceSpecBase {
|
||||
requestRepositoryName = requestRepositoryName,
|
||||
requestBranch = requestBranch,
|
||||
commitIdFrom = baesBranch,
|
||||
commitIdTo = requestBranch)
|
||||
commitIdTo = requestBranch
|
||||
)
|
||||
dummyService.getPullRequest(baseUserName, baseRepositoryName, issueId).get
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,19 +4,20 @@ import gitbucket.core.model.{WebHook, RepositoryWebHook}
|
||||
import org.scalatest.FunSuite
|
||||
import gitbucket.core.model.WebHookContentType
|
||||
|
||||
|
||||
class WebHookServiceSpec extends FunSuite with ServiceSpecBase {
|
||||
lazy val service = new WebHookPullRequestService with AccountService with RepositoryService with PullRequestService
|
||||
with IssuesService with CommitsService with LabelsService with MilestonesService with PrioritiesService
|
||||
|
||||
test("WebHookPullRequestService.getPullRequestsByRequestForWebhook") { withTestDB { implicit session =>
|
||||
val user1 = generateNewUserWithDBRepository("user1","repo1")
|
||||
val user2 = generateNewUserWithDBRepository("user2","repo2")
|
||||
val user3 = generateNewUserWithDBRepository("user3","repo3")
|
||||
test("WebHookPullRequestService.getPullRequestsByRequestForWebhook") {
|
||||
withTestDB { implicit session =>
|
||||
val user1 = generateNewUserWithDBRepository("user1", "repo1")
|
||||
val user2 = generateNewUserWithDBRepository("user2", "repo2")
|
||||
val user3 = generateNewUserWithDBRepository("user3", "repo3")
|
||||
val issueUser = user("root")
|
||||
val (issue1, pullreq1) = generateNewPullRequest("user1/repo1/master1", "user2/repo2/master2", loginUser="root")
|
||||
val (issue3, pullreq3) = generateNewPullRequest("user3/repo3/master3", "user2/repo2/master2", loginUser="root")
|
||||
val (issue32, pullreq32) = generateNewPullRequest("user3/repo3/master32", "user2/repo2/master2", loginUser="root")
|
||||
val (issue1, pullreq1) = generateNewPullRequest("user1/repo1/master1", "user2/repo2/master2", loginUser = "root")
|
||||
val (issue3, pullreq3) = generateNewPullRequest("user3/repo3/master3", "user2/repo2/master2", loginUser = "root")
|
||||
val (issue32, pullreq32) =
|
||||
generateNewPullRequest("user3/repo3/master32", "user2/repo2/master2", loginUser = "root")
|
||||
generateNewPullRequest("user2/repo2/master2", "user1/repo1/master2")
|
||||
service.addWebHook("user1", "repo1", "webhook1-1", Set(WebHook.PullRequest), WebHookContentType.FORM, Some("key"))
|
||||
service.addWebHook("user1", "repo1", "webhook1-2", Set(WebHook.PullRequest), WebHookContentType.FORM, Some("key"))
|
||||
@@ -25,56 +26,107 @@ class WebHookServiceSpec extends FunSuite with ServiceSpecBase {
|
||||
service.addWebHook("user3", "repo3", "webhook3-1", Set(WebHook.PullRequest), WebHookContentType.FORM, Some("key"))
|
||||
service.addWebHook("user3", "repo3", "webhook3-2", Set(WebHook.PullRequest), WebHookContentType.FORM, Some("key"))
|
||||
|
||||
assert(service.getPullRequestsByRequestForWebhook("user1","repo1","master1") == Map.empty)
|
||||
assert(service.getPullRequestsByRequestForWebhook("user1", "repo1", "master1") == Map.empty)
|
||||
|
||||
val r = service.getPullRequestsByRequestForWebhook("user2","repo2","master2").mapValues(_.map(_.url).toSet)
|
||||
val r = service.getPullRequestsByRequestForWebhook("user2", "repo2", "master2").mapValues(_.map(_.url).toSet)
|
||||
|
||||
assert(r.size == 3)
|
||||
assert(r((issue1, issueUser, pullreq1, user1, user2)) == Set("webhook1-1","webhook1-2"))
|
||||
assert(r((issue3, issueUser, pullreq3, user3, user2)) == Set("webhook3-1","webhook3-2"))
|
||||
assert(r((issue32, issueUser, pullreq32, user3, user2)) == Set("webhook3-1","webhook3-2"))
|
||||
assert(r((issue1, issueUser, pullreq1, user1, user2)) == Set("webhook1-1", "webhook1-2"))
|
||||
assert(r((issue3, issueUser, pullreq3, user3, user2)) == Set("webhook3-1", "webhook3-2"))
|
||||
assert(r((issue32, issueUser, pullreq32, user3, user2)) == Set("webhook3-1", "webhook3-2"))
|
||||
|
||||
// when closed, it not founds.
|
||||
service.updateClosed("user1","repo1",issue1.issueId, true)
|
||||
service.updateClosed("user1", "repo1", issue1.issueId, true)
|
||||
|
||||
val r2 = service.getPullRequestsByRequestForWebhook("user2","repo2","master2").mapValues(_.map(_.url).toSet)
|
||||
val r2 = service.getPullRequestsByRequestForWebhook("user2", "repo2", "master2").mapValues(_.map(_.url).toSet)
|
||||
assert(r2.size == 2)
|
||||
assert(r2((issue3, issueUser, pullreq3, user3, user2)) == Set("webhook3-1","webhook3-2"))
|
||||
assert(r2((issue32, issueUser, pullreq32, user3, user2)) == Set("webhook3-1","webhook3-2"))
|
||||
} }
|
||||
assert(r2((issue3, issueUser, pullreq3, user3, user2)) == Set("webhook3-1", "webhook3-2"))
|
||||
assert(r2((issue32, issueUser, pullreq32, user3, user2)) == Set("webhook3-1", "webhook3-2"))
|
||||
}
|
||||
}
|
||||
|
||||
test("add and get and update and delete") { withTestDB { implicit session =>
|
||||
val user1 = generateNewUserWithDBRepository("user1","repo1")
|
||||
test("add and get and update and delete") {
|
||||
withTestDB { implicit session =>
|
||||
val user1 = generateNewUserWithDBRepository("user1", "repo1")
|
||||
val formType = WebHookContentType.FORM
|
||||
val jsonType = WebHookContentType.JSON
|
||||
service.addWebHook("user1", "repo1", "http://example.com", Set(WebHook.PullRequest), formType, Some("key"))
|
||||
assert(service.getWebHooks("user1", "repo1") == List((RepositoryWebHook("user1","repo1","http://example.com", formType, Some("key")),Set(WebHook.PullRequest))))
|
||||
assert(service.getWebHook("user1", "repo1", "http://example.com") == Some((RepositoryWebHook("user1","repo1","http://example.com", formType, Some("key")),Set(WebHook.PullRequest))))
|
||||
assert(service.getWebHooksByEvent("user1", "repo1", WebHook.PullRequest) == List((RepositoryWebHook("user1","repo1","http://example.com", formType, Some("key")))))
|
||||
assert(
|
||||
service.getWebHooks("user1", "repo1") == List(
|
||||
(RepositoryWebHook("user1", "repo1", "http://example.com", formType, Some("key")), Set(WebHook.PullRequest))
|
||||
)
|
||||
)
|
||||
assert(
|
||||
service.getWebHook("user1", "repo1", "http://example.com") == Some(
|
||||
(RepositoryWebHook("user1", "repo1", "http://example.com", formType, Some("key")), Set(WebHook.PullRequest))
|
||||
)
|
||||
)
|
||||
assert(
|
||||
service.getWebHooksByEvent("user1", "repo1", WebHook.PullRequest) == List(
|
||||
(RepositoryWebHook("user1", "repo1", "http://example.com", formType, Some("key")))
|
||||
)
|
||||
)
|
||||
assert(service.getWebHooksByEvent("user1", "repo1", WebHook.Push) == Nil)
|
||||
assert(service.getWebHook("user1", "repo1", "http://example.com2") == None)
|
||||
assert(service.getWebHook("user2", "repo1", "http://example.com") == None)
|
||||
assert(service.getWebHook("user1", "repo2", "http://example.com") == None)
|
||||
service.updateWebHook("user1", "repo1", "http://example.com", Set(WebHook.Push, WebHook.Issues), jsonType, Some("key"))
|
||||
assert(service.getWebHook("user1", "repo1", "http://example.com") == Some((RepositoryWebHook("user1","repo1","http://example.com", jsonType, Some("key")),Set(WebHook.Push, WebHook.Issues))))
|
||||
service.updateWebHook(
|
||||
"user1",
|
||||
"repo1",
|
||||
"http://example.com",
|
||||
Set(WebHook.Push, WebHook.Issues),
|
||||
jsonType,
|
||||
Some("key")
|
||||
)
|
||||
assert(
|
||||
service.getWebHook("user1", "repo1", "http://example.com") == Some(
|
||||
(
|
||||
RepositoryWebHook("user1", "repo1", "http://example.com", jsonType, Some("key")),
|
||||
Set(WebHook.Push, WebHook.Issues)
|
||||
)
|
||||
)
|
||||
)
|
||||
assert(service.getWebHooksByEvent("user1", "repo1", WebHook.PullRequest) == Nil)
|
||||
assert(service.getWebHooksByEvent("user1", "repo1", WebHook.Push) == List((RepositoryWebHook("user1","repo1","http://example.com", jsonType, Some("key")))))
|
||||
assert(
|
||||
service.getWebHooksByEvent("user1", "repo1", WebHook.Push) == List(
|
||||
(RepositoryWebHook("user1", "repo1", "http://example.com", jsonType, Some("key")))
|
||||
)
|
||||
)
|
||||
service.deleteWebHook("user1", "repo1", "http://example.com")
|
||||
assert(service.getWebHook("user1", "repo1", "http://example.com") == None)
|
||||
} }
|
||||
}
|
||||
}
|
||||
|
||||
test("getWebHooks, getWebHooksByEvent") { withTestDB { implicit session =>
|
||||
val user1 = generateNewUserWithDBRepository("user1","repo1")
|
||||
test("getWebHooks, getWebHooksByEvent") {
|
||||
withTestDB { implicit session =>
|
||||
val user1 = generateNewUserWithDBRepository("user1", "repo1")
|
||||
val ctype = WebHookContentType.FORM
|
||||
service.addWebHook("user1", "repo1", "http://example.com/1", Set(WebHook.PullRequest), ctype, Some("key"))
|
||||
service.addWebHook("user1", "repo1", "http://example.com/2", Set(WebHook.Push), ctype, Some("key"))
|
||||
service.addWebHook("user1", "repo1", "http://example.com/3", Set(WebHook.PullRequest,WebHook.Push), ctype, Some("key"))
|
||||
assert(service.getWebHooks("user1", "repo1") == List(
|
||||
RepositoryWebHook("user1","repo1","http://example.com/1", ctype, Some("key"))->Set(WebHook.PullRequest),
|
||||
RepositoryWebHook("user1","repo1","http://example.com/2", ctype, Some("key"))->Set(WebHook.Push),
|
||||
RepositoryWebHook("user1","repo1","http://example.com/3", ctype, Some("key"))->Set(WebHook.PullRequest,WebHook.Push)))
|
||||
assert(service.getWebHooksByEvent("user1", "repo1", WebHook.PullRequest) == List(
|
||||
RepositoryWebHook("user1","repo1","http://example.com/1", ctype, Some("key")),
|
||||
RepositoryWebHook("user1","repo1","http://example.com/3", ctype, Some("key"))))
|
||||
} }
|
||||
service.addWebHook(
|
||||
"user1",
|
||||
"repo1",
|
||||
"http://example.com/3",
|
||||
Set(WebHook.PullRequest, WebHook.Push),
|
||||
ctype,
|
||||
Some("key")
|
||||
)
|
||||
assert(
|
||||
service.getWebHooks("user1", "repo1") == List(
|
||||
RepositoryWebHook("user1", "repo1", "http://example.com/1", ctype, Some("key")) -> Set(WebHook.PullRequest),
|
||||
RepositoryWebHook("user1", "repo1", "http://example.com/2", ctype, Some("key")) -> Set(WebHook.Push),
|
||||
RepositoryWebHook("user1", "repo1", "http://example.com/3", ctype, Some("key")) -> Set(
|
||||
WebHook.PullRequest,
|
||||
WebHook.Push
|
||||
)
|
||||
)
|
||||
)
|
||||
assert(
|
||||
service.getWebHooksByEvent("user1", "repo1", WebHook.PullRequest) == List(
|
||||
RepositoryWebHook("user1", "repo1", "http://example.com/1", ctype, Some("key")),
|
||||
RepositoryWebHook("user1", "repo1", "http://example.com/3", ctype, Some("key"))
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,22 +8,24 @@ class GitCommandFactorySpec extends FunSpec {
|
||||
val factory = new GitCommandFactory("http://localhost:8080", None)
|
||||
|
||||
describe("createCommand") {
|
||||
it("should return GitReceivePack when command is git-receive-pack"){
|
||||
it("should return GitReceivePack when command is git-receive-pack") {
|
||||
assert(factory.createCommand("git-receive-pack '/owner/repo.git'").isInstanceOf[DefaultGitReceivePack] == true)
|
||||
assert(factory.createCommand("git-receive-pack '/owner/repo.wiki.git'").isInstanceOf[DefaultGitReceivePack] == true)
|
||||
assert(
|
||||
factory.createCommand("git-receive-pack '/owner/repo.wiki.git'").isInstanceOf[DefaultGitReceivePack] == true
|
||||
)
|
||||
}
|
||||
it("should return GitUploadPack when command is git-upload-pack"){
|
||||
it("should return GitUploadPack when command is git-upload-pack") {
|
||||
assert(factory.createCommand("git-upload-pack '/owner/repo.git'").isInstanceOf[DefaultGitUploadPack] == true)
|
||||
assert(factory.createCommand("git-upload-pack '/owner/repo.wiki.git'").isInstanceOf[DefaultGitUploadPack] == true)
|
||||
}
|
||||
it("should return UnknownCommand when command is not git-(upload|receive)-pack"){
|
||||
it("should return UnknownCommand when command is not git-(upload|receive)-pack") {
|
||||
assert(factory.createCommand("git- '/owner/repo.git'").isInstanceOf[UnknownCommand] == true)
|
||||
assert(factory.createCommand("git-pack '/owner/repo.git'").isInstanceOf[UnknownCommand] == true)
|
||||
assert(factory.createCommand("git-a-pack '/owner/repo.git'").isInstanceOf[UnknownCommand] == true)
|
||||
assert(factory.createCommand("git-up-pack '/owner/repo.git'").isInstanceOf[UnknownCommand] == true)
|
||||
assert(factory.createCommand("\ngit-upload-pack '/owner/repo.git'").isInstanceOf[UnknownCommand] == true)
|
||||
}
|
||||
it("should return UnknownCommand when git command has no valid arguments"){
|
||||
it("should return UnknownCommand when git command has no valid arguments") {
|
||||
// must be: git-upload-pack '/owner/repository_name.git'
|
||||
assert(factory.createCommand("git-upload-pack").isInstanceOf[UnknownCommand] == true)
|
||||
assert(factory.createCommand("git-upload-pack /owner/repo.git").isInstanceOf[UnknownCommand] == true)
|
||||
|
||||
@@ -4,8 +4,8 @@ import org.scalatest.FunSpec
|
||||
|
||||
class DirectorySpec extends FunSpec {
|
||||
|
||||
describe("GitBucketHome"){
|
||||
it("should set under target in test scope"){
|
||||
describe("GitBucketHome") {
|
||||
it("should set under target in test scope") {
|
||||
assert(Directory.GitBucketHome == new java.io.File("target/gitbucket_home_for_test").getAbsolutePath)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import java.io.File
|
||||
object GitSpecUtil {
|
||||
def withTestFolder[U](f: File => U): U = {
|
||||
val folder = new File(System.getProperty("java.io.tmpdir"), "test-" + System.nanoTime)
|
||||
if(!folder.mkdirs()){
|
||||
if (!folder.mkdirs()) {
|
||||
throw new java.io.IOException("can't create folder " + folder.getAbsolutePath)
|
||||
}
|
||||
try {
|
||||
@@ -34,24 +34,43 @@ object GitSpecUtil {
|
||||
JGitUtil.initRepository(dir)
|
||||
dir
|
||||
}
|
||||
def createFile(git: Git, branch: String, name: String, content: String,
|
||||
autorName: String = "dummy", autorEmail: String = "dummy@example.com",
|
||||
message: String = "test commit") {
|
||||
def createFile(
|
||||
git: Git,
|
||||
branch: String,
|
||||
name: String,
|
||||
content: String,
|
||||
autorName: String = "dummy",
|
||||
autorEmail: String = "dummy@example.com",
|
||||
message: String = "test commit"
|
||||
) {
|
||||
val builder = DirCache.newInCore.builder()
|
||||
val inserter = git.getRepository.newObjectInserter()
|
||||
val headId = git.getRepository.resolve(branch + "^{commit}")
|
||||
if(headId!=null){
|
||||
JGitUtil.processTree(git, headId){ (path, tree) =>
|
||||
if(name != path){
|
||||
if (headId != null) {
|
||||
JGitUtil.processTree(git, headId) { (path, tree) =>
|
||||
if (name != path) {
|
||||
builder.add(JGitUtil.createDirCacheEntry(path, tree.getEntryFileMode, tree.getEntryObjectId))
|
||||
}
|
||||
}
|
||||
}
|
||||
builder.add(JGitUtil.createDirCacheEntry(name, FileMode.REGULAR_FILE,
|
||||
inserter.insert(Constants.OBJ_BLOB, content.getBytes("UTF-8"))))
|
||||
builder.add(
|
||||
JGitUtil.createDirCacheEntry(
|
||||
name,
|
||||
FileMode.REGULAR_FILE,
|
||||
inserter.insert(Constants.OBJ_BLOB, content.getBytes("UTF-8"))
|
||||
)
|
||||
)
|
||||
builder.finish()
|
||||
JGitUtil.createNewCommit(git, inserter, headId, builder.getDirCache.writeTree(inserter),
|
||||
branch, autorName, autorEmail, message)
|
||||
JGitUtil.createNewCommit(
|
||||
git,
|
||||
inserter,
|
||||
headId,
|
||||
builder.getDirCache.writeTree(inserter),
|
||||
branch,
|
||||
autorName,
|
||||
autorEmail,
|
||||
message
|
||||
)
|
||||
inserter.flush()
|
||||
inserter.close()
|
||||
}
|
||||
@@ -70,7 +89,7 @@ object GitSpecUtil {
|
||||
}
|
||||
JGitUtil.getContentInfo(git, path, objectId)
|
||||
}
|
||||
def mergeAndCommit(git: Git, into:String, branch:String, message:String = null):Unit = {
|
||||
def mergeAndCommit(git: Git, into: String, branch: String, message: String = null): Unit = {
|
||||
val repository = git.getRepository
|
||||
val merger = MergeStrategy.RECURSIVE.newMerger(repository, true)
|
||||
val mergeBaseTip = repository.resolve(into)
|
||||
@@ -80,10 +99,10 @@ object GitSpecUtil {
|
||||
} catch {
|
||||
case e: NoMergeBaseException => true
|
||||
}
|
||||
if(conflicted){
|
||||
if (conflicted) {
|
||||
throw new RuntimeException("conflict!")
|
||||
}
|
||||
val mergeTipCommit = using(new RevWalk( repository ))(_.parseCommit( mergeTip ))
|
||||
val mergeTipCommit = using(new RevWalk(repository))(_.parseCommit(mergeTip))
|
||||
val committer = mergeTipCommit.getCommitterIdent
|
||||
// creates merge commit
|
||||
val mergeCommit = new CommitBuilder()
|
||||
|
||||
@@ -5,7 +5,7 @@ import org.scalatest.FunSuite
|
||||
|
||||
class JGitUtilSpec extends FunSuite {
|
||||
|
||||
test("getFileList(git: Git, revision: String, path)"){
|
||||
test("getFileList(git: Git, revision: String, path)") {
|
||||
withTestRepository { git =>
|
||||
def list(branch: String, path: String) =
|
||||
JGitUtil.getFileList(git, branch, path).map(finfo => (finfo.name, finfo.message, finfo.isDirectory))
|
||||
@@ -44,49 +44,118 @@ class JGitUtilSpec extends FunSuite {
|
||||
|
||||
createFile(git, "master", "README5.md", "body5", message = "commit5")
|
||||
|
||||
assert(list("master", ".") == List(("dir/subdir", "commit4", true), ("README.md", "commit2", false), ("README5.md", "commit5", false)))
|
||||
assert(
|
||||
list("master", ".") == List(
|
||||
("dir/subdir", "commit4", true),
|
||||
("README.md", "commit2", false),
|
||||
("README5.md", "commit5", false)
|
||||
)
|
||||
)
|
||||
assert(list("master", "dir/subdir") == List(("File3.md", "commit3", false), ("File4.md", "commit4", false)))
|
||||
assert(list("branch", ".") == Nil)
|
||||
assert(list("branch", "dir/subdir") == Nil)
|
||||
|
||||
createFile(git, "master", "README.md", "body6", message = "commit6")
|
||||
|
||||
assert(list("master", ".") == List(("dir/subdir", "commit4", true), ("README.md", "commit6", false), ("README5.md", "commit5", false)))
|
||||
assert(
|
||||
list("master", ".") == List(
|
||||
("dir/subdir", "commit4", true),
|
||||
("README.md", "commit6", false),
|
||||
("README5.md", "commit5", false)
|
||||
)
|
||||
)
|
||||
assert(list("master", "dir/subdir") == List(("File3.md", "commit3", false), ("File4.md", "commit4", false)))
|
||||
assert(list("branch", ".") == Nil)
|
||||
assert(list("branch", "dir/subdir") == Nil)
|
||||
|
||||
git.branchCreate().setName("branch").setStartPoint("master").call()
|
||||
|
||||
assert(list("master", ".") == List(("dir/subdir", "commit4", true), ("README.md", "commit6", false), ("README5.md", "commit5", false)))
|
||||
assert(
|
||||
list("master", ".") == List(
|
||||
("dir/subdir", "commit4", true),
|
||||
("README.md", "commit6", false),
|
||||
("README5.md", "commit5", false)
|
||||
)
|
||||
)
|
||||
assert(list("master", "dir/subdir") == List(("File3.md", "commit3", false), ("File4.md", "commit4", false)))
|
||||
assert(list("branch", ".") == List(("dir/subdir", "commit4", true), ("README.md", "commit6", false), ("README5.md", "commit5", false)))
|
||||
assert(
|
||||
list("branch", ".") == List(
|
||||
("dir/subdir", "commit4", true),
|
||||
("README.md", "commit6", false),
|
||||
("README5.md", "commit5", false)
|
||||
)
|
||||
)
|
||||
assert(list("branch", "dir/subdir") == List(("File3.md", "commit3", false), ("File4.md", "commit4", false)))
|
||||
|
||||
createFile(git, "branch", "dir/subdir/File3.md", "body7", message = "commit7")
|
||||
|
||||
assert(list("master", ".") == List(("dir/subdir", "commit4", true), ("README.md", "commit6", false), ("README5.md", "commit5", false)))
|
||||
assert(
|
||||
list("master", ".") == List(
|
||||
("dir/subdir", "commit4", true),
|
||||
("README.md", "commit6", false),
|
||||
("README5.md", "commit5", false)
|
||||
)
|
||||
)
|
||||
assert(list("master", "dir/subdir") == List(("File3.md", "commit3", false), ("File4.md", "commit4", false)))
|
||||
assert(list("branch", ".") == List(("dir/subdir", "commit7", true), ("README.md", "commit6", false), ("README5.md", "commit5", false)))
|
||||
assert(
|
||||
list("branch", ".") == List(
|
||||
("dir/subdir", "commit7", true),
|
||||
("README.md", "commit6", false),
|
||||
("README5.md", "commit5", false)
|
||||
)
|
||||
)
|
||||
assert(list("branch", "dir/subdir") == List(("File3.md", "commit7", false), ("File4.md", "commit4", false)))
|
||||
|
||||
createFile(git, "master", "dir8/File8.md", "body8", message = "commit8")
|
||||
|
||||
assert(list("master", ".") == List(("dir/subdir", "commit4", true), ("dir8", "commit8", true), ("README.md", "commit6", false), ("README5.md", "commit5", false)))
|
||||
assert(
|
||||
list("master", ".") == List(
|
||||
("dir/subdir", "commit4", true),
|
||||
("dir8", "commit8", true),
|
||||
("README.md", "commit6", false),
|
||||
("README5.md", "commit5", false)
|
||||
)
|
||||
)
|
||||
assert(list("master", "dir/subdir") == List(("File3.md", "commit3", false), ("File4.md", "commit4", false)))
|
||||
assert(list("branch", ".") == List(("dir/subdir", "commit7", true), ("README.md", "commit6", false), ("README5.md", "commit5", false)))
|
||||
assert(
|
||||
list("branch", ".") == List(
|
||||
("dir/subdir", "commit7", true),
|
||||
("README.md", "commit6", false),
|
||||
("README5.md", "commit5", false)
|
||||
)
|
||||
)
|
||||
assert(list("branch", "dir/subdir") == List(("File3.md", "commit7", false), ("File4.md", "commit4", false)))
|
||||
|
||||
createFile(git, "branch", "dir/subdir9/File9.md", "body9", message = "commit9")
|
||||
|
||||
assert(list("master", ".") == List(("dir/subdir", "commit4", true), ("dir8", "commit8", true), ("README.md", "commit6", false), ("README5.md", "commit5", false)))
|
||||
assert(
|
||||
list("master", ".") == List(
|
||||
("dir/subdir", "commit4", true),
|
||||
("dir8", "commit8", true),
|
||||
("README.md", "commit6", false),
|
||||
("README5.md", "commit5", false)
|
||||
)
|
||||
)
|
||||
assert(list("master", "dir/subdir") == List(("File3.md", "commit3", false), ("File4.md", "commit4", false)))
|
||||
assert(list("branch", ".") == List(("dir", "commit9", true), ("README.md", "commit6", false), ("README5.md", "commit5", false)))
|
||||
assert(
|
||||
list("branch", ".") == List(
|
||||
("dir", "commit9", true),
|
||||
("README.md", "commit6", false),
|
||||
("README5.md", "commit5", false)
|
||||
)
|
||||
)
|
||||
assert(list("branch", "dir/subdir") == List(("File3.md", "commit7", false), ("File4.md", "commit4", false)))
|
||||
|
||||
mergeAndCommit(git, "master", "branch", message = "merge10")
|
||||
|
||||
assert(list("master", ".") == List(("dir", "commit9", true), ("dir8", "commit8", true), ("README.md", "commit6", false), ("README5.md", "commit5", false)))
|
||||
assert(
|
||||
list("master", ".") == List(
|
||||
("dir", "commit9", true),
|
||||
("dir8", "commit8", true),
|
||||
("README.md", "commit6", false),
|
||||
("README5.md", "commit5", false)
|
||||
)
|
||||
)
|
||||
assert(list("master", "dir/subdir") == List(("File3.md", "commit7", false), ("File4.md", "commit4", false)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,9 @@ class StringUtilSpec extends FunSpec {
|
||||
|
||||
describe("escapeHtml") {
|
||||
it("should escape &, <, > and \"") {
|
||||
assert(StringUtil.escapeHtml("<a href=\"/test\">a & b</a>") == "<a href="/test">a & b</a>")
|
||||
assert(
|
||||
StringUtil.escapeHtml("<a href=\"/test\">a & b</a>") == "<a href="/test">a & b</a>"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,21 +68,45 @@ class StringUtilSpec extends FunSpec {
|
||||
|
||||
describe("getRepositoryViewerUrl") {
|
||||
val baseUrl = Some("http://localhost:8080")
|
||||
it("should convert GitBucket repository url"){
|
||||
assert(StringUtil.getRepositoryViewerUrl("http://localhost:8080/git/root/gitbucket.git", baseUrl) == "http://localhost:8080/root/gitbucket")
|
||||
assert(StringUtil.getRepositoryViewerUrl("http://root@localhost:8080/git/root/gitbucket.git", baseUrl) == "http://localhost:8080/root/gitbucket")
|
||||
it("should convert GitBucket repository url") {
|
||||
assert(
|
||||
StringUtil
|
||||
.getRepositoryViewerUrl("http://localhost:8080/git/root/gitbucket.git", baseUrl) == "http://localhost:8080/root/gitbucket"
|
||||
)
|
||||
assert(
|
||||
StringUtil
|
||||
.getRepositoryViewerUrl("http://root@localhost:8080/git/root/gitbucket.git", baseUrl) == "http://localhost:8080/root/gitbucket"
|
||||
)
|
||||
}
|
||||
it("should convert GitHub repository url"){
|
||||
assert(StringUtil.getRepositoryViewerUrl("https://github.com/root/gitbucket.git", baseUrl) == "https://github.com/root/gitbucket")
|
||||
assert(StringUtil.getRepositoryViewerUrl("https://root@github.com/root/gitbucket.git", baseUrl) == "https://github.com/root/gitbucket")
|
||||
it("should convert GitHub repository url") {
|
||||
assert(
|
||||
StringUtil
|
||||
.getRepositoryViewerUrl("https://github.com/root/gitbucket.git", baseUrl) == "https://github.com/root/gitbucket"
|
||||
)
|
||||
assert(
|
||||
StringUtil
|
||||
.getRepositoryViewerUrl("https://root@github.com/root/gitbucket.git", baseUrl) == "https://github.com/root/gitbucket"
|
||||
)
|
||||
}
|
||||
it("should convert BitBucket repository url"){
|
||||
assert(StringUtil.getRepositoryViewerUrl("https://bitbucket.org/root/gitbucket.git", baseUrl) == "https://bitbucket.org/root/gitbucket")
|
||||
assert(StringUtil.getRepositoryViewerUrl("https://root@bitbucket.org/root/gitbucket.git", baseUrl) == "https://bitbucket.org/root/gitbucket")
|
||||
it("should convert BitBucket repository url") {
|
||||
assert(
|
||||
StringUtil
|
||||
.getRepositoryViewerUrl("https://bitbucket.org/root/gitbucket.git", baseUrl) == "https://bitbucket.org/root/gitbucket"
|
||||
)
|
||||
assert(
|
||||
StringUtil
|
||||
.getRepositoryViewerUrl("https://root@bitbucket.org/root/gitbucket.git", baseUrl) == "https://bitbucket.org/root/gitbucket"
|
||||
)
|
||||
}
|
||||
it("should convert GitLab repository url"){
|
||||
assert(StringUtil.getRepositoryViewerUrl("https://gitlab.com/root/gitbucket.git", baseUrl) == "https://gitlab.com/root/gitbucket")
|
||||
assert(StringUtil.getRepositoryViewerUrl("https://root@gitlab.com/root/gitbucket.git", baseUrl) == "https://gitlab.com/root/gitbucket")
|
||||
it("should convert GitLab repository url") {
|
||||
assert(
|
||||
StringUtil
|
||||
.getRepositoryViewerUrl("https://gitlab.com/root/gitbucket.git", baseUrl) == "https://gitlab.com/root/gitbucket"
|
||||
)
|
||||
assert(
|
||||
StringUtil
|
||||
.getRepositoryViewerUrl("https://root@gitlab.com/root/gitbucket.git", baseUrl) == "https://gitlab.com/root/gitbucket"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import org.scalatest.FunSpec
|
||||
import org.scalatest.mockito.MockitoSugar
|
||||
import play.twirl.api.Html
|
||||
|
||||
|
||||
class AvatarImageProviderSpec extends FunSpec with MockitoSugar {
|
||||
|
||||
val request = mock[HttpServletRequest]
|
||||
@@ -28,8 +27,10 @@ class AvatarImageProviderSpec extends FunSpec with MockitoSugar {
|
||||
implicit val context = Context(createSystemSettings(true), None, request)
|
||||
val provider = new AvatarImageProviderImpl(Some(createAccount(None)))
|
||||
|
||||
assert(provider.toHtml("user", 32).toString ==
|
||||
"<img src=\"https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?s=32&d=retro&r=g\" class=\"avatar\" style=\"width: 32px; height: 32px;\" />")
|
||||
assert(
|
||||
provider.toHtml("user", 32).toString ==
|
||||
"<img src=\"https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?s=32&d=retro&r=g\" class=\"avatar\" style=\"width: 32px; height: 32px;\" />"
|
||||
)
|
||||
}
|
||||
|
||||
it("should show uploaded image even if gravatar integration is enabled") {
|
||||
@@ -38,8 +39,10 @@ class AvatarImageProviderSpec extends FunSpec with MockitoSugar {
|
||||
val date = new SimpleDateFormat("yyyyMMddHHmmss").format(account.updatedDate)
|
||||
val provider = new AvatarImageProviderImpl(Some(account))
|
||||
|
||||
assert(provider.toHtml("user", 32).toString ==
|
||||
s"""<img src="/user/_avatar?${date}" class="avatar" style="width: 32px; height: 32px;" />""")
|
||||
assert(
|
||||
provider.toHtml("user", 32).toString ==
|
||||
s"""<img src="/user/_avatar?${date}" class="avatar" style="width: 32px; height: 32px;" />"""
|
||||
)
|
||||
}
|
||||
|
||||
it("should show local image for no image account if gravatar integration is disabled") {
|
||||
@@ -48,40 +51,50 @@ class AvatarImageProviderSpec extends FunSpec with MockitoSugar {
|
||||
val date = new SimpleDateFormat("yyyyMMddHHmmss").format(account.updatedDate)
|
||||
val provider = new AvatarImageProviderImpl(Some(account))
|
||||
|
||||
assert(provider.toHtml("user", 32).toString ==
|
||||
s"""<img src="/user/_avatar?${date}" class="avatar" style="width: 32px; height: 32px;" />""")
|
||||
assert(
|
||||
provider.toHtml("user", 32).toString ==
|
||||
s"""<img src="/user/_avatar?${date}" class="avatar" style="width: 32px; height: 32px;" />"""
|
||||
)
|
||||
}
|
||||
|
||||
it("should show Gravatar image for specified mail address if gravatar integration is enabled") {
|
||||
implicit val context = Context(createSystemSettings(true), None, request)
|
||||
val provider = new AvatarImageProviderImpl(None)
|
||||
|
||||
assert(provider.toHtml("user", 20, "hoge@hoge.com").toString ==
|
||||
"<img src=\"https://www.gravatar.com/avatar/4712f9b0e63f56ad952ad387eaa23b9c?s=20&d=retro&r=g\" class=\"avatar-mini\" style=\"width: 20px; height: 20px;\" />")
|
||||
assert(
|
||||
provider.toHtml("user", 20, "hoge@hoge.com").toString ==
|
||||
"<img src=\"https://www.gravatar.com/avatar/4712f9b0e63f56ad952ad387eaa23b9c?s=20&d=retro&r=g\" class=\"avatar-mini\" style=\"width: 20px; height: 20px;\" />"
|
||||
)
|
||||
}
|
||||
|
||||
it("should show unknown image for unknown user if gravatar integration is enabled") {
|
||||
implicit val context = Context(createSystemSettings(true), None, request)
|
||||
val provider = new AvatarImageProviderImpl(None)
|
||||
|
||||
assert(provider.toHtml("user", 20).toString ==
|
||||
"<img src=\"/_unknown/_avatar\" class=\"avatar-mini\" style=\"width: 20px; height: 20px;\" />")
|
||||
assert(
|
||||
provider.toHtml("user", 20).toString ==
|
||||
"<img src=\"/_unknown/_avatar\" class=\"avatar-mini\" style=\"width: 20px; height: 20px;\" />"
|
||||
)
|
||||
}
|
||||
|
||||
it("should show unknown image for specified mail address if gravatar integration is disabled") {
|
||||
implicit val context = Context(createSystemSettings(false), None, request)
|
||||
val provider = new AvatarImageProviderImpl(None)
|
||||
|
||||
assert(provider.toHtml("user", 20, "hoge@hoge.com").toString ==
|
||||
"<img src=\"/_unknown/_avatar\" class=\"avatar-mini\" style=\"width: 20px; height: 20px;\" />")
|
||||
assert(
|
||||
provider.toHtml("user", 20, "hoge@hoge.com").toString ==
|
||||
"<img src=\"/_unknown/_avatar\" class=\"avatar-mini\" style=\"width: 20px; height: 20px;\" />"
|
||||
)
|
||||
}
|
||||
|
||||
it("should add tooltip if it's enabled") {
|
||||
implicit val context = Context(createSystemSettings(false), None, request)
|
||||
val provider = new AvatarImageProviderImpl(None)
|
||||
|
||||
assert(provider.toHtml("user", 20, "hoge@hoge.com", true).toString ==
|
||||
"<img src=\"/_unknown/_avatar\" class=\"avatar-mini\" style=\"width: 20px; height: 20px;\" data-toggle=\"tooltip\" title=\"user\"/>")
|
||||
assert(
|
||||
provider.toHtml("user", 20, "hoge@hoge.com", true).toString ==
|
||||
"<img src=\"/_unknown/_avatar\" class=\"avatar-mini\" style=\"width: 20px; height: 20px;\" data-toggle=\"tooltip\" title=\"user\"/>"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +112,8 @@ class AvatarImageProviderSpec extends FunSpec with MockitoSugar {
|
||||
image = image,
|
||||
isGroupAccount = false,
|
||||
isRemoved = false,
|
||||
description = None)
|
||||
description = None
|
||||
)
|
||||
|
||||
private def createSystemSettings(useGravatar: Boolean) =
|
||||
SystemSettings(
|
||||
@@ -128,8 +142,9 @@ class AvatarImageProviderSpec extends FunSpec with MockitoSugar {
|
||||
*/
|
||||
class AvatarImageProviderImpl(account: Option[Account]) extends AvatarImageProvider with RequestCache {
|
||||
|
||||
def toHtml(userName: String, size: Int, mailAddress: String = "", tooltip: Boolean = false)
|
||||
(implicit context: Context): Html = getAvatarImageHtml(userName, size, mailAddress, tooltip)
|
||||
def toHtml(userName: String, size: Int, mailAddress: String = "", tooltip: Boolean = false)(
|
||||
implicit context: Context
|
||||
): Html = getAvatarImageHtml(userName, size, mailAddress, tooltip)
|
||||
|
||||
override def getAccountByMailAddress(mailAddress: String)(implicit context: Context): Option[Account] = account
|
||||
override def getAccountByUserName(userName: String)(implicit context: Context): Option[Account] = account
|
||||
|
||||
@@ -35,7 +35,9 @@ class HelpersSpec extends FunSpec with MockitoSugar {
|
||||
it("should convert a multiple links within text") {
|
||||
val before = "Example Project. http://example.com. (See also https://github.com/)"
|
||||
val after = decorateHtml(urlLink(before), repository)
|
||||
assert(after == """Example Project. <a href="http://example.com">http://example.com</a>. (See also <a href="https://github.com/">https://github.com/</a>)""")
|
||||
assert(
|
||||
after == """Example Project. <a href="http://example.com">http://example.com</a>. (See also <a href="https://github.com/">https://github.com/</a>)"""
|
||||
)
|
||||
}
|
||||
|
||||
it("should properly escape html metacharacters") {
|
||||
|
||||
@@ -90,4 +90,3 @@ tasks
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,11 +15,11 @@ class PaginationSpec extends FunSpec {
|
||||
|
||||
describe("omitLeft and omitRight") {
|
||||
it("should return true if pagination links at their side will be omitted") {
|
||||
defining(Pagination(1, 100, 10, 6)){ pagination =>
|
||||
defining(Pagination(1, 100, 10, 6)) { pagination =>
|
||||
assert(pagination.omitLeft == false)
|
||||
assert(pagination.omitRight == true)
|
||||
}
|
||||
defining(Pagination(9, 100, 10, 6)){ pagination =>
|
||||
defining(Pagination(9, 100, 10, 6)) { pagination =>
|
||||
assert(pagination.omitLeft == true)
|
||||
assert(pagination.omitRight == false)
|
||||
}
|
||||
@@ -28,7 +28,7 @@ class PaginationSpec extends FunSpec {
|
||||
|
||||
describe("visibleFor") {
|
||||
it("should return true for visible pagination links") {
|
||||
defining(Pagination(1, 100, 10, 6)){ pagination =>
|
||||
defining(Pagination(1, 100, 10, 6)) { pagination =>
|
||||
assert(pagination.visibleFor(1) == true)
|
||||
assert(pagination.visibleFor(2) == true)
|
||||
assert(pagination.visibleFor(3) == true)
|
||||
@@ -40,7 +40,7 @@ class PaginationSpec extends FunSpec {
|
||||
assert(pagination.visibleFor(9) == false)
|
||||
assert(pagination.visibleFor(10) == true)
|
||||
}
|
||||
defining(Pagination(5, 100, 10, 6)){ pagination =>
|
||||
defining(Pagination(5, 100, 10, 6)) { pagination =>
|
||||
assert(pagination.visibleFor(1) == true)
|
||||
assert(pagination.visibleFor(2) == false)
|
||||
assert(pagination.visibleFor(3) == false)
|
||||
@@ -52,7 +52,7 @@ class PaginationSpec extends FunSpec {
|
||||
assert(pagination.visibleFor(9) == false)
|
||||
assert(pagination.visibleFor(10) == true)
|
||||
}
|
||||
defining(Pagination(8, 100, 10, 6)){ pagination =>
|
||||
defining(Pagination(8, 100, 10, 6)) { pagination =>
|
||||
assert(pagination.visibleFor(1) == true)
|
||||
assert(pagination.visibleFor(2) == false)
|
||||
assert(pagination.visibleFor(3) == false)
|
||||
|
||||
Reference in New Issue
Block a user