mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 05:25:50 +01:00
add AccountServiceSpec
This commit is contained in:
26
src/test/scala/SpecBase.scala
Normal file
26
src/test/scala/SpecBase.scala
Normal file
@@ -0,0 +1,26 @@
|
||||
package service
|
||||
|
||||
import scala.slick.session.Database
|
||||
import util.ControlUtil._
|
||||
import java.sql.DriverManager
|
||||
import org.apache.commons.io.FileUtils
|
||||
import scala.util.Random
|
||||
import java.io.File
|
||||
|
||||
trait SpecBase {
|
||||
|
||||
def withTestDB[A](action: => A): A = {
|
||||
util.FileUtil.withTmpDir(new File(FileUtils.getTempDirectory(), Random.alphanumeric.take(10).mkString)){
|
||||
dir =>
|
||||
val (url, user, pass) = (s"jdbc:h2:${dir}", "sa", "sa")
|
||||
org.h2.Driver.load()
|
||||
using(DriverManager.getConnection(url, user, pass)){ conn =>
|
||||
servlet.AutoUpdate.versions.reverse.foreach(_.update(conn))
|
||||
}
|
||||
Database.forURL(url, user, pass).withSession {
|
||||
action
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user