Skip to content

Commit

Permalink
misc: refactor JMESPath visitor tests (#950)
Browse files Browse the repository at this point in the history
  • Loading branch information
0marperez authored Sep 13, 2023
1 parent ca206c8 commit 459bd06
Show file tree
Hide file tree
Showing 23 changed files with 181 additions and 367 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,19 @@
*/
package com.test

import aws.smithy.kotlin.runtime.retries.Outcome
import aws.smithy.kotlin.runtime.retries.getOrThrow
import com.test.model.EntityLists
import com.test.model.EntityPrimitives
import com.test.model.GetBooleanLogicRequest
import com.test.model.GetBooleanLogicResponse
import com.test.utils.successTest
import com.test.waiters.waitUntilAndEquals
import com.test.waiters.waitUntilNotEquals
import com.test.waiters.waitUntilOrEquals
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals

class BooleanLogicTest {
private fun successTest(
block: suspend WaitersTestClient.(request: GetBooleanLogicRequest) -> Outcome<GetBooleanLogicResponse>,
vararg results: GetBooleanLogicResponse,
): Unit = runTest {
val client = DefaultWaitersTestClient(results.map { Result.success(it) })
val req = GetBooleanLogicRequest { name = "test" }

val outcome = client.block(req)
assertEquals(results.size, outcome.attempts)
assertEquals(results.last(), outcome.getOrThrow())
}

@Test fun testAndEquals() = successTest(
GetBooleanLogicRequest { name = "test" },
WaitersTestClient::waitUntilAndEquals,
GetBooleanLogicResponse { lists = EntityLists { booleans = listOf(false, false) } },
GetBooleanLogicResponse { lists = EntityLists { booleans = listOf(false, true) } },
Expand All @@ -39,6 +25,7 @@ class BooleanLogicTest {
)

@Test fun testOrEquals() = successTest(
GetBooleanLogicRequest { name = "test" },
WaitersTestClient::waitUntilOrEquals,
GetBooleanLogicResponse { lists = EntityLists { booleans = listOf(true, true) } },
GetBooleanLogicResponse { lists = EntityLists { booleans = listOf(true, false) } },
Expand All @@ -47,6 +34,7 @@ class BooleanLogicTest {
)

@Test fun testNotEquals() = successTest(
GetBooleanLogicRequest { name = "test" },
WaitersTestClient::waitUntilNotEquals,
GetBooleanLogicResponse { primitives = EntityPrimitives { boolean = true } },
GetBooleanLogicResponse { primitives = EntityPrimitives { boolean = false } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,48 @@
*/
package com.test

import aws.smithy.kotlin.runtime.retries.Outcome
import aws.smithy.kotlin.runtime.retries.getOrThrow
import com.test.model.EntityPrimitives
import com.test.model.GetFunctionAbsRequest
import com.test.model.GetFunctionAbsResponse
import com.test.utils.successTest
import com.test.waiters.*
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals

class FunctionAbsTest {
private fun successTest(
block: suspend WaitersTestClient.(request: GetFunctionAbsRequest) -> Outcome<GetFunctionAbsResponse>,
vararg results: GetFunctionAbsResponse,
): Unit = runTest {
val client = DefaultWaitersTestClient(results.map { Result.success(it) })
val req = GetFunctionAbsRequest { name = "test" }

val outcome = client.block(req)
assertEquals(results.size, outcome.attempts)
assertEquals(results.last(), outcome.getOrThrow())
}

@Test fun testAbsFunctionShortEquals() = successTest(
GetFunctionAbsRequest { name = "test" },
WaitersTestClient::waitUntilAbsFunctionShortEquals,
GetFunctionAbsResponse { primitives = EntityPrimitives { short = -1 } },
GetFunctionAbsResponse { primitives = EntityPrimitives { short = 1 } },
GetFunctionAbsResponse { primitives = EntityPrimitives { short = 2 } },
)

@Test fun testAbsFunctionIntegerEquals() = successTest(
GetFunctionAbsRequest { name = "test" },
WaitersTestClient::waitUntilAbsFunctionIntegerEquals,
GetFunctionAbsResponse { primitives = EntityPrimitives { integer = -1 } },
GetFunctionAbsResponse { primitives = EntityPrimitives { integer = 1 } },
GetFunctionAbsResponse { primitives = EntityPrimitives { integer = 2 } },
)

@Test fun testAbsFunctionLongEquals() = successTest(
GetFunctionAbsRequest { name = "test" },
WaitersTestClient::waitUntilAbsFunctionLongEquals,
GetFunctionAbsResponse { primitives = EntityPrimitives { long = -1L } },
GetFunctionAbsResponse { primitives = EntityPrimitives { long = 1L } },
GetFunctionAbsResponse { primitives = EntityPrimitives { long = 2L } },
)

@Test fun testAbsFunctionFloatEquals() = successTest(
GetFunctionAbsRequest { name = "test" },
WaitersTestClient::waitUntilAbsFunctionFloatEquals,
GetFunctionAbsResponse { primitives = EntityPrimitives { float = -1f } },
GetFunctionAbsResponse { primitives = EntityPrimitives { float = 1f } },
GetFunctionAbsResponse { primitives = EntityPrimitives { float = 2f } },
)

@Test fun testAbsFunctionDoubleEquals() = successTest(
GetFunctionAbsRequest { name = "test" },
WaitersTestClient::waitUntilAbsFunctionDoubleEquals,
GetFunctionAbsResponse { primitives = EntityPrimitives { double = -1.0 } },
GetFunctionAbsResponse { primitives = EntityPrimitives { double = 1.0 } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,69 +4,54 @@
*/
package com.test

import aws.smithy.kotlin.runtime.retries.Outcome
import aws.smithy.kotlin.runtime.retries.getOrThrow
import com.test.model.EntityLists
import com.test.model.GetFunctionAvgEqualsRequest
import com.test.model.GetFunctionAvgEqualsResponse
import com.test.utils.successTest
import com.test.waiters.*
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals

class FunctionAvgTest {
private fun successTest(
block: suspend WaitersTestClient.(request: GetFunctionAvgEqualsRequest) -> Outcome<GetFunctionAvgEqualsResponse>,
vararg results: GetFunctionAvgEqualsResponse,
): Unit = runTest {
val client = DefaultWaitersTestClient(results.map { Result.success(it) })
val req = GetFunctionAvgEqualsRequest { name = "test" }

val outcome = client.block(req)
assertEquals(results.size, outcome.attempts)
assertEquals(results.last(), outcome.getOrThrow())
}

@Test
fun testEmptyIntegerListAvgNotEquals() = successTest(
@Test fun testEmptyIntegerListAvgNotEquals() = successTest(
GetFunctionAvgEqualsRequest { name = "test" },
WaitersTestClient::waitUntilEmptyIntegerListAvgNotEquals,
GetFunctionAvgEqualsResponse { lists = EntityLists { integers = listOf() } },
)

@Test
fun testShortListAvgNotEquals() = successTest(
@Test fun testShortListAvgNotEquals() = successTest(
GetFunctionAvgEqualsRequest { name = "test" },
WaitersTestClient::waitUntilShortListAvgNotEquals,
GetFunctionAvgEqualsResponse { lists = EntityLists { shorts = listOf(12, 12, 10, 8, 8) } },
GetFunctionAvgEqualsResponse { lists = EntityLists { shorts = listOf(10, 10) } },
GetFunctionAvgEqualsResponse { lists = EntityLists { shorts = listOf(0) } },
)

@Test
fun testIntegerListAvgNotEquals() = successTest(
@Test fun testIntegerListAvgNotEquals() = successTest(
GetFunctionAvgEqualsRequest { name = "test" },
WaitersTestClient::waitUntilIntegerListAvgNotEquals,
GetFunctionAvgEqualsResponse { lists = EntityLists { integers = listOf(12, 12, 10, 8, 8) } },
GetFunctionAvgEqualsResponse { lists = EntityLists { integers = listOf(10, 10) } },
GetFunctionAvgEqualsResponse { lists = EntityLists { integers = listOf(0) } },
)

@Test
fun testLongListAvgNotEquals() = successTest(
@Test fun testLongListAvgNotEquals() = successTest(
GetFunctionAvgEqualsRequest { name = "test" },
WaitersTestClient::waitUntilLongListAvgNotEquals,
GetFunctionAvgEqualsResponse { lists = EntityLists { longs = listOf(12L, 12L, 10L, 8L, 8L) } },
GetFunctionAvgEqualsResponse { lists = EntityLists { longs = listOf(10L, 10L) } },
GetFunctionAvgEqualsResponse { lists = EntityLists { longs = listOf(0L) } },
)

@Test
fun testFloatListAvgNotEquals() = successTest(
@Test fun testFloatListAvgNotEquals() = successTest(
GetFunctionAvgEqualsRequest { name = "test" },
WaitersTestClient::waitUntilFloatListAvgNotEquals,
GetFunctionAvgEqualsResponse { lists = EntityLists { floats = listOf(12f, 12f, 10f, 8f, 8f) } },
GetFunctionAvgEqualsResponse { lists = EntityLists { floats = listOf(10f, 10f) } },
GetFunctionAvgEqualsResponse { lists = EntityLists { floats = listOf(0f) } },
)

@Test
fun testDoubleListAvgNotEquals() = successTest(
@Test fun testDoubleListAvgNotEquals() = successTest(
GetFunctionAvgEqualsRequest { name = "test" },
WaitersTestClient::waitUntilDoubleListAvgNotEquals,
GetFunctionAvgEqualsResponse { lists = EntityLists { doubles = listOf(12.0, 12.0, 10.0, 8.0, 8.0) } },
GetFunctionAvgEqualsResponse { lists = EntityLists { doubles = listOf(10.0, 10.0) } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,37 @@
*/
package com.test

import aws.smithy.kotlin.runtime.retries.Outcome
import aws.smithy.kotlin.runtime.retries.getOrThrow
import com.test.model.EntityPrimitives
import com.test.model.GetFunctionCeilRequest
import com.test.model.GetFunctionCeilResponse
import com.test.utils.successTest
import com.test.waiters.*
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals

class FunctionCeilTest {
private fun successTest(
block: suspend WaitersTestClient.(request: GetFunctionCeilRequest) -> Outcome<GetFunctionCeilResponse>,
vararg results: GetFunctionCeilResponse,
): Unit = runTest {
val client = DefaultWaitersTestClient(results.map { Result.success(it) })
val req = GetFunctionCeilRequest { name = "test" }

val outcome = client.block(req)
assertEquals(results.size, outcome.attempts)
assertEquals(results.last(), outcome.getOrThrow())
}

@Test fun testCeilFunctionShortEquals() = successTest(
GetFunctionCeilRequest { name = "test" },
WaitersTestClient::waitUntilCeilFunctionShortEquals,
GetFunctionCeilResponse { primitives = EntityPrimitives { short = 1 } },
GetFunctionCeilResponse { primitives = EntityPrimitives { short = 2 } },
)

@Test fun testCeilFunctionIntegerEquals() = successTest(
GetFunctionCeilRequest { name = "test" },
WaitersTestClient::waitUntilCeilFunctionIntegerEquals,
GetFunctionCeilResponse { primitives = EntityPrimitives { integer = 1 } },
GetFunctionCeilResponse { primitives = EntityPrimitives { integer = 2 } },
)

@Test fun testCeilFunctionLongEquals() = successTest(
GetFunctionCeilRequest { name = "test" },
WaitersTestClient::waitUntilCeilFunctionLongEquals,
GetFunctionCeilResponse { primitives = EntityPrimitives { long = 1L } },
GetFunctionCeilResponse { primitives = EntityPrimitives { long = 2L } },
)

@Test fun testCeilFunctionFloatEquals() = successTest(
GetFunctionCeilRequest { name = "test" },
WaitersTestClient::waitUntilCeilFunctionFloatEquals,
GetFunctionCeilResponse { primitives = EntityPrimitives { float = 0.0001f } },
GetFunctionCeilResponse { primitives = EntityPrimitives { float = 0.9f } },
Expand All @@ -54,6 +43,7 @@ class FunctionCeilTest {
)

@Test fun testCeilFunctionDoubleEquals() = successTest(
GetFunctionCeilRequest { name = "test" },
WaitersTestClient::waitUntilCeilFunctionDoubleEquals,
GetFunctionCeilResponse { primitives = EntityPrimitives { double = 0.0001 } },
GetFunctionCeilResponse { primitives = EntityPrimitives { double = 0.9 } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,16 @@
*/
package com.test

import aws.smithy.kotlin.runtime.retries.Outcome
import aws.smithy.kotlin.runtime.retries.getOrThrow
import com.test.model.*
import com.test.model.Enum
import com.test.utils.successTest
import com.test.waiters.*
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals

class FunctionContainsTest {
private fun successTest(
block: suspend WaitersTestClient.(request: GetFunctionContainsRequest) -> Outcome<GetFunctionContainsResponse>,
vararg results: GetFunctionContainsResponse,
): Unit = runTest {
val client = DefaultWaitersTestClient(results.map { Result.success(it) })
val req = GetFunctionContainsRequest { name = "test" }

val outcome = client.block(req)
assertEquals(results.size, outcome.attempts)
assertEquals(results.last(), outcome.getOrThrow())
}

// list
@Test fun testBooleanListContains() = successTest(
GetFunctionContainsRequest { name = "test" },
WaitersTestClient::waitUntilBooleanListContains,
GetFunctionContainsResponse {
primitives = EntityPrimitives { boolean = true }
Expand All @@ -40,6 +26,7 @@ class FunctionContainsTest {
)

@Test fun testBooleanListContainsIdentityProjection() = successTest(
GetFunctionContainsRequest { name = "test" },
WaitersTestClient::waitUntilBooleanListContainsIdentityProjection,
GetFunctionContainsResponse {
primitives = EntityPrimitives { boolean = true }
Expand All @@ -52,6 +39,7 @@ class FunctionContainsTest {
)

@Test fun testStringListContains() = successTest(
GetFunctionContainsRequest { name = "test" },
WaitersTestClient::waitUntilStringListContains,
GetFunctionContainsResponse {
primitives = EntityPrimitives { string = "bar" }
Expand All @@ -64,6 +52,7 @@ class FunctionContainsTest {
)

@Test fun testIntegerListContains() = successTest(
GetFunctionContainsRequest { name = "test" },
WaitersTestClient::waitUntilIntegerListContains,
GetFunctionContainsResponse {
primitives = EntityPrimitives { integer = 10 }
Expand All @@ -76,6 +65,7 @@ class FunctionContainsTest {
)

@Test fun testEnumListContains() = successTest(
GetFunctionContainsRequest { name = "test" },
WaitersTestClient::waitUntilEnumListContains,
GetFunctionContainsResponse {
primitives = EntityPrimitives { enum = Enum.Two }
Expand All @@ -88,6 +78,7 @@ class FunctionContainsTest {
)

@Test fun testIntEnumListContains() = successTest(
GetFunctionContainsRequest { name = "test" },
WaitersTestClient::waitUntilIntEnumListContains,
GetFunctionContainsResponse {
primitives = EntityPrimitives { intEnum = IntEnum.Two }
Expand All @@ -101,6 +92,7 @@ class FunctionContainsTest {

// object projection
@Test fun testBooleanMapContains() = successTest(
GetFunctionContainsRequest { name = "test" },
WaitersTestClient::waitUntilBooleanMapContains,
GetFunctionContainsResponse {
primitives = EntityPrimitives { boolean = false }
Expand All @@ -113,6 +105,7 @@ class FunctionContainsTest {
)

@Test fun testStringMapContains() = successTest(
GetFunctionContainsRequest { name = "test" },
WaitersTestClient::waitUntilStringMapContains,
GetFunctionContainsResponse {
primitives = EntityPrimitives { string = "bar" }
Expand All @@ -125,6 +118,7 @@ class FunctionContainsTest {
)

@Test fun testIntegerMapContains() = successTest(
GetFunctionContainsRequest { name = "test" },
WaitersTestClient::waitUntilIntegerMapContains,
GetFunctionContainsResponse {
primitives = EntityPrimitives { integer = 10 }
Expand All @@ -137,6 +131,7 @@ class FunctionContainsTest {
)

@Test fun testEnumMapContains() = successTest(
GetFunctionContainsRequest { name = "test" },
WaitersTestClient::waitUntilEnumMapContains,
GetFunctionContainsResponse {
primitives = EntityPrimitives { enum = Enum.Two }
Expand All @@ -149,6 +144,7 @@ class FunctionContainsTest {
)

@Test fun testIntEnumMapContains() = successTest(
GetFunctionContainsRequest { name = "test" },
WaitersTestClient::waitUntilIntEnumMapContains,
GetFunctionContainsResponse {
primitives = EntityPrimitives { intEnum = IntEnum.Two }
Expand Down
Loading

0 comments on commit 459bd06

Please sign in to comment.