-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from penland365/integration-tests
Integration Test setup and QueryIntegrationSpec completed.
- Loading branch information
Showing
8 changed files
with
119 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CREATE TABLE roc_tests( | ||
id SERIAL PRIMARY KEY, | ||
name CHARACTER VARYING(100) NOT NULL | ||
) | ||
WITH(OIDS=FALSE); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
INSERT INTO roc_tests (name) VALUES ('finagle'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
UPDATE roc_tests SET name = 'updated-finagle-name' WHERE id = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package roc | ||
package integrations | ||
|
||
import com.twitter.finagle.{Addr, Address, Name, Service} | ||
import com.twitter.util.Var | ||
import scala.io.Source | ||
|
||
trait Client { | ||
private val db = "circle_test" | ||
private val user = "ubuntu" | ||
private val passwd = "" | ||
private val host = "127.0.0.1" | ||
private val port = 5432 | ||
|
||
private lazy val address = Address(host, port) | ||
protected lazy val Postgres = Postgresql.client | ||
.withUserAndPasswd(user, passwd) | ||
.withDatabase(db) | ||
.newRichClient( | ||
Name.Bound(Var[Addr](Addr.Bound(address)), "roc"), | ||
"roc" | ||
) | ||
} | ||
|
||
trait SqlReader { | ||
|
||
def readSql(filename: String): String = { | ||
val path = s"core/src/it/resources/sql/$filename" | ||
Source.fromFile(path) | ||
.getLines | ||
.foldLeft("")(_ + _) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package roc | ||
package integrations | ||
|
||
import com.twitter.finagle.{Addr, Address, Name, Service} | ||
import com.twitter.util.Var | ||
import com.twitter.util.Await | ||
import org.specs2.Specification | ||
import roc.postgresql.Request | ||
import scala.io.Source | ||
|
||
final class QuerySpec extends Specification | ||
with SqlReader | ||
with Client { def is = sequential ^ s2""" | ||
|
||
Query | ||
must execute a CREATE command $testCreate | ||
must execute an INSERT command $testInsert | ||
must execute an UPDATE command $testUpdate | ||
must execute a SELECT command $testSelect | ||
must execute a DELETE command $testDelete | ||
must execute a DROP command $testDrop | ||
|
||
""" | ||
|
||
def testCreate() = { | ||
val sql = readSql("query/create.sql") | ||
val request = new Request(sql) | ||
val result = Await.result(Postgres.query(request)) | ||
result.completedCommand must_== "CREATE TABLE" | ||
} | ||
|
||
def testInsert() = { | ||
val sql = readSql("query/insert.sql") | ||
val request = new Request(sql) | ||
val result = Await.result(Postgres.query(request)) | ||
result.completedCommand must_== "INSERT 0 1" | ||
} | ||
|
||
def testUpdate() = { | ||
val sql = readSql("query/update.sql") | ||
val request = new Request(sql) | ||
val result = Await.result(Postgres.query(request)) | ||
result.completedCommand must_== "UPDATE 1" | ||
} | ||
|
||
def testSelect() = { | ||
val request = new Request("SELECT name FROM roc_tests WHERE id = 1") | ||
val result = Await.result(Postgres.query(request)) | ||
result.toList.length must_== 1 | ||
} | ||
|
||
def testDelete() = { | ||
val request = new Request("DELETE FROM roc_tests WHERE id = 1;") | ||
val result = Await.result(Postgres.query(request)) | ||
result.completedCommand must_== "DELETE 1" | ||
} | ||
|
||
def testDrop() = { | ||
val request = new Request("DROP TABLE roc_tests;") | ||
val result = Await.result(Postgres.query(request)) | ||
result.completedCommand must_== "DROP TABLE" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters