Skip to content

Commit 0367406

Browse files
authored
Integration tests (#4)
* AppTest - app starts * DbUpraderTest * AppTest returns js bundle * AppTest returns status
1 parent 6635423 commit 0367406

17 files changed

+234
-110
lines changed

.travis.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env bash
22

3-
function wait_for_service() {
3+
function wait_for_server() {
44
n=0
55
until [ $n -ge 30 ]
66
do
7-
echo -e "Waiting for rbackup"
7+
echo -e "Waiting for RBackup"
88

99
if [ "$(curl "http://$RBACKUP_IP:3369/status" 2>/dev/null | jq -r .status)" == "RBackup running" ]; then
1010
break
@@ -18,15 +18,16 @@ function wait_for_service() {
1818
exit 1
1919
fi
2020

21-
echo -e "rbackup ready"
21+
echo -e "RBackup ready"
2222
}
2323

2424
function client_test() {
2525
cd ci-tests && \
2626
docker-compose up -d --build --force-recreate && \
2727
export RBACKUP_IP=$(docker inspect citests_tests_1 | jq -r '.[0] | .NetworkSettings.Ports."3369/tcp" | .[0].HostIp') && \
28-
wait_for_service && \
28+
wait_for_server && \
2929
cd .. && \
30+
mkdir public && mkdir public/bundle && touch public/bundle/js.bundle.txt && touch public/bundle/style.bundle.txt && \
3031
sbt ";clean;test" && \
3132
cd ci-tests && \
3233
docker-compose down

app/lib/Constants.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package lib
22

33
trait Constants {
4-
final val versionStr: String = "0.1.0"
4+
final val versionStr: String = "0.1.4"
55

66
final val SentryDsn: Option[String] = None
77
}

app/lib/db/DbScheme.scala

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package lib.db
22

3+
import com.typesafe.scalalogging.StrictLogging
4+
import lib.{App, AppVersion}
35
import scalikejdbc._
46

57
//noinspection SqlNoDataSourceInspection
6-
object DbScheme {
8+
object DbScheme extends StrictLogging {
79
def create(implicit session: DBSession): Unit = {
10+
val currentVersionStr = App.versionStr
11+
812
sql"""
913
|CREATE TABLE IF NOT EXISTS FILES
1014
|(
@@ -40,16 +44,26 @@ object DbScheme {
4044
|);
4145
|
4246
""".stripMargin.executeUpdate().apply()
47+
48+
if (App.version > AppVersion(0, 1, 3)) {
49+
if (sql"""select value from settings where key='db_version'""".map(_.string("value")).single().apply().isEmpty) {
50+
logger.info(s"Didn't found db_version in DB, setting to $currentVersionStr")
51+
52+
sql"""
53+
|insert ignore into settings values ('db_version', ${currentVersionStr});
54+
""".stripMargin.executeUpdate().apply()
55+
}
56+
}
4357
}
4458

45-
def truncateAll(implicit session: DBSession): Unit = {
59+
def dropAll(implicit session: DBSession): Unit = {
4660
sql"""
4761
|SET REFERENTIAL_INTEGRITY FALSE;
4862
|
49-
|truncate table files;
50-
|truncate table settings;
51-
|truncate table backup_sets;
52-
|truncate table backup_sets_files;
63+
|drop table if exists files;
64+
|drop table if exists settings;
65+
|drop table if exists backup_sets;
66+
|drop table if exists backup_sets_files;
5367
|
5468
|SET REFERENTIAL_INTEGRITY TRUE;
5569
""".stripMargin.executeUpdate().apply()

app/lib/db/DbUpgrader.scala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ class DbUpgrader(dao: Dao)(implicit sch: Scheduler) extends StrictLogging {
5151
}
5252
.toList
5353
.sequentially
54-
.flatMap { _ =>
55-
dao
56-
.setSetting("db_version", App.versionStr)
57-
.map(_ => logger.debug(s"DB upgraded to version ${App.versionStr}"))
58-
}
54+
.map(_ => ())
5955
}
6056
}
6157
}

build.sbt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ libraryDependencies ++= Seq(
4444
"io.sentry" % "sentry-logback" % "1.7.14",
4545
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.0",
4646
"org.scalatest" %% "scalatest" % "3.0.5",
47+
"org.scalaj" %% "scalaj-http" % "2.4.1" % "test",
48+
"org.scalatestplus.play" %% "scalatestplus-play" % "3.1.2" % "test",
4749
"org.mockito" % "mockito-core" % "2.23.0" % "test"
4850
)
4951

@@ -94,11 +96,12 @@ lazy val setVersionInSources = taskKey[Unit]("Sets build version into sources")
9496

9597
setVersionInSources := {
9698
import java.io.PrintWriter
99+
97100
import scala.io.Source
98-
101+
99102
val version = sys.env.getOrElse("VERSION", throw new IllegalArgumentException("Missing VERSION env property"))
100103
println(s"Setting app version to $version")
101-
104+
102105
val src = Source.fromFile(ConstantsPath).mkString
103106
val updated = src.replaceAll(
104107
"""final val versionStr: String = "\d+.\d+.\d+"""",
@@ -132,8 +135,8 @@ setSentryDsnInSources := {
132135
}
133136
}
134137

135-
sources in (Compile, doc) := Seq.empty
136-
publishArtifact in (Compile, packageDoc) := false
138+
sources in(Compile, doc) := Seq.empty
139+
publishArtifact in(Compile, packageDoc) := false
137140

138141
PlayKeys.playDefaultPort := 3370
139142
PlayKeys.devSettings := Seq("play.server.http.port" -> "3370")

ci-tests/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ FROM jendakol/rbackup:0.1
33
WORKDIR /
44
COPY . .
55

6-
ENTRYPOINT /wait-for-it.sh mysql:3306 -s -t 30 && /start-rbackup.sh
6+
ENTRYPOINT /wait-for-it.sh mysql:3306 -s -t 30 && /start-server.sh
File renamed without changes.

ci-tests/tests.sh

Lines changed: 0 additions & 69 deletions
This file was deleted.

conf/reference.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ cloudConnectorDefaults {
1111
chunkSize = 2048
1212
}
1313

14+
cloudConnector {}
15+
1416
fileHandler {
1517
parallelism = 2 // change the maxConnections accordingly!
1618
retries = 2

test/IntegrationTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import utils.TestOps._
1212

1313
class IntegrationTest extends FunSuite with StrictLogging {
1414
private val rbackupIp: String = {
15-
val ip = System.getenv("RBACKUP_IP")
15+
val ip = Option(System.getenv("RBACKUP_IP")).getOrElse("localhost")
1616

1717
if (ip == "0.0.0.0") "localhost" else ip
1818
}

0 commit comments

Comments
 (0)