Skip to content

Commit

Permalink
Add unit-test for non DML statement
Browse files Browse the repository at this point in the history
  • Loading branch information
RustedBones committed Apr 4, 2023
1 parent 4f26fe7 commit 065dc41
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,23 @@ class BigQueryIT extends AnyFlatSpec with Matchers with BeforeAndAfterEach with
val allRowsQuery = s"SELECT word, word_count FROM `$writableTableRef` LIMIT 10"
val mbq = MockBigQuery()
mbq.mockTable(writableTableRef).withData(MockBQData.inData)
val insertQuery = s"INSERT INTO `${writableTableRef}` (word, word_count) VALUES ('cat', 2)"
val insertQuery = s"INSERT INTO `$writableTableRef` (word, word_count) VALUES ('cat', 2)"
mbq.runDML(insertQuery)
mbq.queryResult(allRowsQuery) should contain theSameElementsAs MockBQData.expected ++ Seq(
MockBQData.wordCount("cat", 2)
)
val updateQuery = s"UPDATE `${writableTableRef}` SET word_count = 4 WHERE word = 'cat'"
val updateQuery = s"UPDATE `$writableTableRef` SET word_count = 4 WHERE word = 'cat'"
mbq.runDML(updateQuery)
mbq.queryResult(allRowsQuery) should contain theSameElementsAs MockBQData.expected ++ Seq(
MockBQData.wordCount("cat", 4)
)
val deleteQuery = s"DELETE FROM `${writableTableRef}` WHERE word = 'cat'"
val deleteQuery = s"DELETE FROM `$writableTableRef` WHERE word = 'cat'"
mbq.runDML(deleteQuery)
mbq.queryResult(allRowsQuery) should contain theSameElementsAs MockBQData.expected

an[IllegalArgumentException] shouldBe thrownBy {
mbq.runDML(allRowsQuery)
}
}

object MockBQWildcardData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private[client] object QueryOps {

private val Priority = if (isInteractive) "INTERACTIVE" else "BATCH"

final private[scio] case class QueryJobConfig(
final private case class QueryJobConfig(
sql: String,
useLegacySql: Boolean,
dryRun: Boolean = false,
Expand Down

0 comments on commit 065dc41

Please sign in to comment.