Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
takapi327 committed Dec 30, 2024
1 parent 13f0749 commit 9ebda5e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 61 deletions.
2 changes: 1 addition & 1 deletion tests/src/test/scala/ldbc/tests/CodecTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ trait CodecTest extends CatsEffectSuite:
(for
_ <- sql"CREATE TABLE none_test (none INT)".update
_ <- sql"INSERT INTO none_test (none) VALUES (NULL)".update
result <- sql"SELECT * FROM none_test WHERE none IS NULL".query[None.type].to[Option]
result <- sql"SELECT * FROM none_test WHERE none IS NULL".query[Option[String]].to[Option]
yield result).transaction(conn)
},
Some(None)
Expand Down
75 changes: 15 additions & 60 deletions tests/src/test/scala/ldbc/tests/SQLStringContextQueryTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,6 @@ class LdbcSQLStringContextQueryTest extends SQLStringContextQueryTest:
ssl = SSL.Trusted
)

test(
"If the acquired column name and the field name of the class to be mapped are different, an exception is raised."
) {
case class City(id: Int, title: String)

interceptIO[ldbc.connector.exception.SQLException](
connection.use { conn =>
sql"SELECT Id, Name FROM city LIMIT 1"
.query[City]
.to[Option]
.readOnly(conn)
}
)
}

test(
"If the number of columns retrieved is different from the number of fields in the class to be mapped, an exception is raised."
) {
case class City(id: Int, name: String, age: Int)

interceptIO[ldbc.connector.exception.SQLException](
connection.use { conn =>
sql"SELECT Id, Name FROM city LIMIT 1"
.query[City]
.to[Option]
.readOnly(conn)
}
)
}

class JdbcSQLStringContextQueryTest extends SQLStringContextQueryTest:

val ds = new MysqlDataSource()
Expand All @@ -75,36 +45,6 @@ class JdbcSQLStringContextQueryTest extends SQLStringContextQueryTest:
override def connection: Resource[IO, Connection[IO]] =
Resource.make(jdbc.connector.MysqlDataSource[IO](ds).getConnection)(_.close())

test(
"If the acquired column name and the field name of the class to be mapped are different, an exception is raised."
) {
case class City(id: Int, title: String)

interceptIO[java.sql.SQLException](
connection.use { conn =>
sql"SELECT Id, Name FROM city LIMIT 1"
.query[City]
.to[Option]
.readOnly(conn)
}
)
}

test(
"If the number of columns retrieved is different from the number of fields in the class to be mapped, an exception is raised."
) {
case class City(id: Int, name: String, age: Int)

interceptIO[java.sql.SQLException](
connection.use { conn =>
sql"SELECT Id, Name FROM city LIMIT 1"
.query[City]
.to[Option]
.readOnly(conn)
}
)
}

trait SQLStringContextQueryTest extends CatsEffectSuite:

given Tracer[IO] = Tracer.noop[IO]
Expand Down Expand Up @@ -788,3 +728,18 @@ trait SQLStringContextQueryTest extends CatsEffectSuite:
Some((City(1, "Kabul"), Country("AFG", "Afghanistan")))
)
}

test(
"If the number of columns retrieved is different from the number of fields in the class to be mapped, an exception is raised."
) {
case class City(id: Int, name: String, age: Int)

interceptIO[ArrayIndexOutOfBoundsException](
connection.use { conn =>
sql"SELECT Id, Name FROM city LIMIT 1"
.query[City]
.to[Option]
.readOnly(conn)
}
)
}

0 comments on commit 9ebda5e

Please sign in to comment.