From be1f30a91aeae5535507c24f075420cae9add7a6 Mon Sep 17 00:00:00 2001 From: Sarah O'Toole Date: Thu, 26 May 2022 18:50:17 +0100 Subject: [PATCH] #679 Clean up FunctionDefSpec (#687) --- .../scala/zio/sql/mysql/FunctionDefSpec.scala | 82 ++++--------------- 1 file changed, 16 insertions(+), 66 deletions(-) diff --git a/mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala b/mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala index 4da50d13d..6bcc24e5c 100644 --- a/mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala +++ b/mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala @@ -1,11 +1,9 @@ package zio.sql.mysql -import zio.Cause import zio.test._ import zio.test.Assertion._ -import java.time.LocalDate -import java.time.{ LocalTime, ZoneId } +import java.time.{ LocalDate, LocalTime, ZoneId } import java.time.format.DateTimeFormatter object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema { @@ -22,11 +20,7 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema { val testResult = execute(query) - val assertion = for { - r <- testResult.runCollect - } yield assert(r.head)(equalTo(expected)) - - assertion.mapErrorCause(cause => Cause.stackless(cause.untraced)) + assertZIO(testResult.runHead.some)(equalTo(expected)) }, // FIXME: lower with string literal should not refer to a column name // See: https://www.w3schools.com/sql/trymysql.asp?filename=trysql_func_mysql_lower @@ -51,11 +45,7 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema { val testResult = execute(query) - val assertion = for { - r <- testResult.runCollect - } yield assert(r.head)(equalTo(expected)) - - assertion.mapErrorCause(cause => Cause.stackless(cause.untraced)) + assertZIO(testResult.runHead.some)(equalTo(expected)) }, test("abs") { val query = select(Abs(-32.0)) @@ -64,11 +54,7 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema { val testResult = execute(query) - val assertion = for { - r <- testResult.runCollect - } yield assert(r.head)(equalTo(expected)) - - assertion.mapErrorCause(cause => Cause.stackless(cause.untraced)) + assertZIO(testResult.runHead.some)(equalTo(expected)) }, test("crc32") { val query = select(Crc32("MySQL")) from customers @@ -77,11 +63,7 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema { val testResult = execute(query) - val assertion = for { - r <- testResult.runCollect - } yield assert(r.head)(equalTo(expected)) - - assertion.mapErrorCause(cause => Cause.stackless(cause.untraced)) + assertZIO(testResult.runHead.some)(equalTo(expected)) }, test("degrees") { val query = select(Degrees(Math.PI)) from customers @@ -90,11 +72,7 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema { val testResult = execute(query) - val assertion = for { - r <- testResult.runCollect - } yield assert(r.head)(equalTo(expected)) - - assertion.mapErrorCause(cause => Cause.stackless(cause.untraced)) + assertZIO(testResult.runHead.some)(equalTo(expected)) }, test("hex") { val query = select(Hex(255L)) from customers @@ -110,11 +88,7 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema { val testResult = execute(query) - val assertion = for { - r <- testResult.runCollect - } yield assert(r.head)(equalTo(expected)) - - assertion.mapErrorCause(cause => Cause.stackless(cause.untraced)) + assertZIO(testResult.runHead.some)(equalTo(expected)) }, test("log10") { val query = select(Log10(1000000d)) from customers @@ -123,11 +97,7 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema { val testResult = execute(query) - val assertion = for { - r <- testResult.runCollect - } yield assert(r.head)(equalTo(expected)) - - assertion.mapErrorCause(cause => Cause.stackless(cause.untraced)) + assertZIO(testResult.runHead.some)(equalTo(expected)) }, test("now") { val timestampFormatter = @@ -137,14 +107,10 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema { val testResult = execute(query) - val assertion = - for { - r <- testResult.runCollect - } yield assert(timestampFormatter.format(r.head))( - Assertion.matchesRegex("[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}") - ) - - assertion.mapErrorCause(cause => Cause.stackless(cause.untraced)) + assertZIO( + testResult.runHead.some + .map(t => timestampFormatter.format(t)) + )(matchesRegex("[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}")) }, test("bit_length") { val query = select(BitLength("hello")) @@ -153,11 +119,7 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema { val testResult = execute(query) - val assertion = for { - r <- testResult.runCollect - } yield assert(r.head)(equalTo(expected)) - - assertion.mapErrorCause(cause => Cause.stackless(cause.untraced)) + assertZIO(testResult.runHead.some)(equalTo(expected)) }, test("current_date") { val query = select(CurrentDate) @@ -166,11 +128,7 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema { val testResult = execute(query) - val assertion = for { - r <- testResult.runCollect - } yield assert(r.head)(equalTo(expected)) - - assertion.mapErrorCause(cause => Cause.stackless(cause.untraced)) + assertZIO(testResult.runHead.some)(equalTo(expected)) }, test("maketime") { val query = select(MakeTime(12, 15, 30.5)) from customers @@ -179,11 +137,7 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema { val testResult = execute(query) - val assertion = for { - r <- testResult.runCollect - } yield assert(r.head)(equalTo(expected)) - - assertion.mapErrorCause(cause => Cause.stackless(cause.untraced)) + assertZIO(testResult.runHead.some)(equalTo(expected)) }, test("pi") { val query = select(Pi) from customers @@ -192,11 +146,7 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema { val testResult = execute(query) - val assertion = for { - r <- testResult.runCollect - } yield assert(r.head)(equalTo(expected)) - - assertion.mapErrorCause(cause => Cause.stackless(cause.untraced)) + assertZIO(testResult.runHead.some)(equalTo(expected)) }, test("rpad") { val cases = Seq(("hi", 5, "?", "hi???"), ("hi", 1, "?", "h"))