Skip to content

Commit

Permalink
more IT tests, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
googley42 committed Jul 27, 2023
1 parent 185da86 commit 3cfe1ef
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 44 deletions.
78 changes: 36 additions & 42 deletions dynamodb/src/it/scala/zio/dynamodb/LiveSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ object LiveSpec extends ZIOSpecDefault {
}
}

def withKeywordsTable(
def withPkKeywordsTable(
f: String => ZIO[DynamoDBExecutor, Throwable, TestResult]
) =
ZIO.scoped {
Expand Down Expand Up @@ -198,65 +198,59 @@ object LiveSpec extends ZIOSpecDefault {
val (id, num, ttl) = ProjectionExpression.accessors[ExpressionAttrNames]
}

final case class ExpressionAttrNames2(and: String, source: String, ttl: Option[Long])
object ExpressionAttrNames2 {
implicit val schema: Schema.CaseClass3[String, String, Option[Long], ExpressionAttrNames2] =
DeriveSchema.gen[ExpressionAttrNames2]
val (and, source, ttl) = ProjectionExpression.accessors[ExpressionAttrNames2]
final case class ExpressionAttrNamesPkKeywords(and: String, source: String, ttl: Option[Long])
object ExpressionAttrNamesPkKeywords {
implicit val schema: Schema.CaseClass3[String, String, Option[Long], ExpressionAttrNamesPkKeywords] =
DeriveSchema.gen[ExpressionAttrNamesPkKeywords]
val (and, source, ttl) = ProjectionExpression.accessors[ExpressionAttrNamesPkKeywords]
}

val debugSuite = suite("debug")(
test("queryAll should handle keywords in primary key names using high level API") {
withKeywordsTable { tableName =>
val query = DynamoDBQuery
.queryAll[ExpressionAttrNames2](tableName)
.whereKey(ExpressionAttrNames2.and === "and1" && ExpressionAttrNames2.source === "source1")
.filter(ExpressionAttrNames2.ttl.notExists)
query.execute.flatMap(_.runDrain).exit.map { result =>
assert(result)(succeeds(isUnit))
}
}
},
test("queryAll should handle keywords in primary key names using low level API") {
withKeywordsTable { tableName =>
val query = DynamoDBQuery
.queryAll[ExpressionAttrNames2](tableName)
.whereKey(partitionKey("and") === "and1" && sortKey("source") === "source1")
.filter(ExpressionAttrNames2.ttl.notExists)
query.execute.flatMap(_.runDrain).exit.map { result =>
assert(result)(succeeds(isUnit))
}
}
}
)
.provideSomeLayerShared[TestEnvironment](
testLayer.orDie
) @@ nondeterministic

val mainSuite: Spec[TestEnvironment, Any] =
suite("live test")(
suite("key words in Key Condition Expressions")(
test("queryAll should handle keywords in primary key name using high level API") {
withKeywordsTable { tableName =>
test("queryAll should handle keywords in primary key names using high level API") {
withPkKeywordsTable { tableName =>
val query = DynamoDBQuery
.queryAll[ExpressionAttrNames2](tableName)
.whereKey(ExpressionAttrNames2.and === "and1" && ExpressionAttrNames2.source === "source1")
.filter(ExpressionAttrNames2.ttl.notExists)
.queryAll[ExpressionAttrNamesPkKeywords](tableName)
.whereKey(ExpressionAttrNamesPkKeywords.and === "and1" && ExpressionAttrNamesPkKeywords.source === "source1")
.filter(ExpressionAttrNamesPkKeywords.ttl.notExists)
query.execute.flatMap(_.runDrain).exit.map { result =>
assert(result)(succeeds(isUnit))
}
}
},
test("queryAll should handle keywords in primary key name using low level API") {
withKeywordsTable { tableName =>
withPkKeywordsTable { tableName =>
val query = DynamoDBQuery
.queryAll[ExpressionAttrNames2](tableName)
.queryAll[ExpressionAttrNamesPkKeywords](tableName)
.whereKey(partitionKey("and") === "and1" && sortKey("source") === "source1")
.filter(ExpressionAttrNames2.ttl.notExists)
.filter(ExpressionAttrNamesPkKeywords.ttl.notExists)
query.execute.flatMap(_.runDrain).exit.map { result =>
assert(result)(succeeds(isUnit))
}
}
},
test("querySome should handle keywords in primary key name using high level API") {
withPkKeywordsTable { tableName =>
val query = DynamoDBQuery
.querySome[ExpressionAttrNamesPkKeywords](tableName, 1)
.whereKey(ExpressionAttrNamesPkKeywords.and === "and1" && ExpressionAttrNamesPkKeywords.source === "source1")
.filter(ExpressionAttrNamesPkKeywords.ttl.notExists)
for {
result <- query.execute
} yield assert(result._1)(hasSize(equalTo(0)))
}
},
test("querySome should handle keywords in primary key name using low level API") {
withPkKeywordsTable { tableName =>
val query = DynamoDBQuery
.querySome[ExpressionAttrNames](tableName, 1)
.whereKey(partitionKey("and") === "and1" && sortKey("source") === "source1")
.filter(ExpressionAttrNames.ttl.notExists)
for {
result <- query.execute
} yield assert(result._1)(hasSize(equalTo(0)))
}
}
),
suite("keywords in expression attribute names")(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ sealed trait KeyConditionExpression extends Renderable { self =>

object KeyConditionExpression {

def getOrInsert[From](primaryKeyName: String): AliasMapRender[String] =
AliasMapRender.getOrInsert(ProjectionExpression.MapElement[From, String](Root, primaryKeyName))
def getOrInsert[From, To](primaryKeyName: String): AliasMapRender[String] =
AliasMapRender.getOrInsert(ProjectionExpression.MapElement[From, To](Root, primaryKeyName))
private[dynamodb] final case class And(left: PartitionKeyExpression, right: SortKeyExpression)
extends KeyConditionExpression
def partitionKey(key: String): PartitionKey = PartitionKey(key)
Expand Down

0 comments on commit 3cfe1ef

Please sign in to comment.