Skip to content

Commit 459bd06

Browse files
authored
misc: refactor JMESPath visitor tests (#950)
1 parent ca206c8 commit 459bd06

23 files changed

+181
-367
lines changed

tests/codegen/waiter-tests/src/test/kotlin/com/test/BooleanLogicTest.kt

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,19 @@
44
*/
55
package com.test
66

7-
import aws.smithy.kotlin.runtime.retries.Outcome
8-
import aws.smithy.kotlin.runtime.retries.getOrThrow
97
import com.test.model.EntityLists
108
import com.test.model.EntityPrimitives
119
import com.test.model.GetBooleanLogicRequest
1210
import com.test.model.GetBooleanLogicResponse
11+
import com.test.utils.successTest
1312
import com.test.waiters.waitUntilAndEquals
1413
import com.test.waiters.waitUntilNotEquals
1514
import com.test.waiters.waitUntilOrEquals
16-
import kotlinx.coroutines.test.runTest
1715
import org.junit.jupiter.api.Test
18-
import kotlin.test.assertEquals
1916

2017
class BooleanLogicTest {
21-
private fun successTest(
22-
block: suspend WaitersTestClient.(request: GetBooleanLogicRequest) -> Outcome<GetBooleanLogicResponse>,
23-
vararg results: GetBooleanLogicResponse,
24-
): Unit = runTest {
25-
val client = DefaultWaitersTestClient(results.map { Result.success(it) })
26-
val req = GetBooleanLogicRequest { name = "test" }
27-
28-
val outcome = client.block(req)
29-
assertEquals(results.size, outcome.attempts)
30-
assertEquals(results.last(), outcome.getOrThrow())
31-
}
32-
3318
@Test fun testAndEquals() = successTest(
19+
GetBooleanLogicRequest { name = "test" },
3420
WaitersTestClient::waitUntilAndEquals,
3521
GetBooleanLogicResponse { lists = EntityLists { booleans = listOf(false, false) } },
3622
GetBooleanLogicResponse { lists = EntityLists { booleans = listOf(false, true) } },
@@ -39,6 +25,7 @@ class BooleanLogicTest {
3925
)
4026

4127
@Test fun testOrEquals() = successTest(
28+
GetBooleanLogicRequest { name = "test" },
4229
WaitersTestClient::waitUntilOrEquals,
4330
GetBooleanLogicResponse { lists = EntityLists { booleans = listOf(true, true) } },
4431
GetBooleanLogicResponse { lists = EntityLists { booleans = listOf(true, false) } },
@@ -47,6 +34,7 @@ class BooleanLogicTest {
4734
)
4835

4936
@Test fun testNotEquals() = successTest(
37+
GetBooleanLogicRequest { name = "test" },
5038
WaitersTestClient::waitUntilNotEquals,
5139
GetBooleanLogicResponse { primitives = EntityPrimitives { boolean = true } },
5240
GetBooleanLogicResponse { primitives = EntityPrimitives { boolean = false } },

tests/codegen/waiter-tests/src/test/kotlin/com/test/FunctionAbsTest.kt

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,58 +4,48 @@
44
*/
55
package com.test
66

7-
import aws.smithy.kotlin.runtime.retries.Outcome
8-
import aws.smithy.kotlin.runtime.retries.getOrThrow
97
import com.test.model.EntityPrimitives
108
import com.test.model.GetFunctionAbsRequest
119
import com.test.model.GetFunctionAbsResponse
10+
import com.test.utils.successTest
1211
import com.test.waiters.*
13-
import kotlinx.coroutines.test.runTest
1412
import org.junit.jupiter.api.Test
15-
import kotlin.test.assertEquals
1613

1714
class FunctionAbsTest {
18-
private fun successTest(
19-
block: suspend WaitersTestClient.(request: GetFunctionAbsRequest) -> Outcome<GetFunctionAbsResponse>,
20-
vararg results: GetFunctionAbsResponse,
21-
): Unit = runTest {
22-
val client = DefaultWaitersTestClient(results.map { Result.success(it) })
23-
val req = GetFunctionAbsRequest { name = "test" }
24-
25-
val outcome = client.block(req)
26-
assertEquals(results.size, outcome.attempts)
27-
assertEquals(results.last(), outcome.getOrThrow())
28-
}
29-
3015
@Test fun testAbsFunctionShortEquals() = successTest(
16+
GetFunctionAbsRequest { name = "test" },
3117
WaitersTestClient::waitUntilAbsFunctionShortEquals,
3218
GetFunctionAbsResponse { primitives = EntityPrimitives { short = -1 } },
3319
GetFunctionAbsResponse { primitives = EntityPrimitives { short = 1 } },
3420
GetFunctionAbsResponse { primitives = EntityPrimitives { short = 2 } },
3521
)
3622

3723
@Test fun testAbsFunctionIntegerEquals() = successTest(
24+
GetFunctionAbsRequest { name = "test" },
3825
WaitersTestClient::waitUntilAbsFunctionIntegerEquals,
3926
GetFunctionAbsResponse { primitives = EntityPrimitives { integer = -1 } },
4027
GetFunctionAbsResponse { primitives = EntityPrimitives { integer = 1 } },
4128
GetFunctionAbsResponse { primitives = EntityPrimitives { integer = 2 } },
4229
)
4330

4431
@Test fun testAbsFunctionLongEquals() = successTest(
32+
GetFunctionAbsRequest { name = "test" },
4533
WaitersTestClient::waitUntilAbsFunctionLongEquals,
4634
GetFunctionAbsResponse { primitives = EntityPrimitives { long = -1L } },
4735
GetFunctionAbsResponse { primitives = EntityPrimitives { long = 1L } },
4836
GetFunctionAbsResponse { primitives = EntityPrimitives { long = 2L } },
4937
)
5038

5139
@Test fun testAbsFunctionFloatEquals() = successTest(
40+
GetFunctionAbsRequest { name = "test" },
5241
WaitersTestClient::waitUntilAbsFunctionFloatEquals,
5342
GetFunctionAbsResponse { primitives = EntityPrimitives { float = -1f } },
5443
GetFunctionAbsResponse { primitives = EntityPrimitives { float = 1f } },
5544
GetFunctionAbsResponse { primitives = EntityPrimitives { float = 2f } },
5645
)
5746

5847
@Test fun testAbsFunctionDoubleEquals() = successTest(
48+
GetFunctionAbsRequest { name = "test" },
5949
WaitersTestClient::waitUntilAbsFunctionDoubleEquals,
6050
GetFunctionAbsResponse { primitives = EntityPrimitives { double = -1.0 } },
6151
GetFunctionAbsResponse { primitives = EntityPrimitives { double = 1.0 } },

tests/codegen/waiter-tests/src/test/kotlin/com/test/FunctionAvgTest.kt

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,69 +4,54 @@
44
*/
55
package com.test
66

7-
import aws.smithy.kotlin.runtime.retries.Outcome
8-
import aws.smithy.kotlin.runtime.retries.getOrThrow
97
import com.test.model.EntityLists
108
import com.test.model.GetFunctionAvgEqualsRequest
119
import com.test.model.GetFunctionAvgEqualsResponse
10+
import com.test.utils.successTest
1211
import com.test.waiters.*
13-
import kotlinx.coroutines.test.runTest
1412
import org.junit.jupiter.api.Test
15-
import kotlin.test.assertEquals
1613

1714
class FunctionAvgTest {
18-
private fun successTest(
19-
block: suspend WaitersTestClient.(request: GetFunctionAvgEqualsRequest) -> Outcome<GetFunctionAvgEqualsResponse>,
20-
vararg results: GetFunctionAvgEqualsResponse,
21-
): Unit = runTest {
22-
val client = DefaultWaitersTestClient(results.map { Result.success(it) })
23-
val req = GetFunctionAvgEqualsRequest { name = "test" }
24-
25-
val outcome = client.block(req)
26-
assertEquals(results.size, outcome.attempts)
27-
assertEquals(results.last(), outcome.getOrThrow())
28-
}
29-
30-
@Test
31-
fun testEmptyIntegerListAvgNotEquals() = successTest(
15+
@Test fun testEmptyIntegerListAvgNotEquals() = successTest(
16+
GetFunctionAvgEqualsRequest { name = "test" },
3217
WaitersTestClient::waitUntilEmptyIntegerListAvgNotEquals,
3318
GetFunctionAvgEqualsResponse { lists = EntityLists { integers = listOf() } },
3419
)
3520

36-
@Test
37-
fun testShortListAvgNotEquals() = successTest(
21+
@Test fun testShortListAvgNotEquals() = successTest(
22+
GetFunctionAvgEqualsRequest { name = "test" },
3823
WaitersTestClient::waitUntilShortListAvgNotEquals,
3924
GetFunctionAvgEqualsResponse { lists = EntityLists { shorts = listOf(12, 12, 10, 8, 8) } },
4025
GetFunctionAvgEqualsResponse { lists = EntityLists { shorts = listOf(10, 10) } },
4126
GetFunctionAvgEqualsResponse { lists = EntityLists { shorts = listOf(0) } },
4227
)
4328

44-
@Test
45-
fun testIntegerListAvgNotEquals() = successTest(
29+
@Test fun testIntegerListAvgNotEquals() = successTest(
30+
GetFunctionAvgEqualsRequest { name = "test" },
4631
WaitersTestClient::waitUntilIntegerListAvgNotEquals,
4732
GetFunctionAvgEqualsResponse { lists = EntityLists { integers = listOf(12, 12, 10, 8, 8) } },
4833
GetFunctionAvgEqualsResponse { lists = EntityLists { integers = listOf(10, 10) } },
4934
GetFunctionAvgEqualsResponse { lists = EntityLists { integers = listOf(0) } },
5035
)
5136

52-
@Test
53-
fun testLongListAvgNotEquals() = successTest(
37+
@Test fun testLongListAvgNotEquals() = successTest(
38+
GetFunctionAvgEqualsRequest { name = "test" },
5439
WaitersTestClient::waitUntilLongListAvgNotEquals,
5540
GetFunctionAvgEqualsResponse { lists = EntityLists { longs = listOf(12L, 12L, 10L, 8L, 8L) } },
5641
GetFunctionAvgEqualsResponse { lists = EntityLists { longs = listOf(10L, 10L) } },
5742
GetFunctionAvgEqualsResponse { lists = EntityLists { longs = listOf(0L) } },
5843
)
5944

60-
@Test
61-
fun testFloatListAvgNotEquals() = successTest(
45+
@Test fun testFloatListAvgNotEquals() = successTest(
46+
GetFunctionAvgEqualsRequest { name = "test" },
6247
WaitersTestClient::waitUntilFloatListAvgNotEquals,
6348
GetFunctionAvgEqualsResponse { lists = EntityLists { floats = listOf(12f, 12f, 10f, 8f, 8f) } },
6449
GetFunctionAvgEqualsResponse { lists = EntityLists { floats = listOf(10f, 10f) } },
6550
GetFunctionAvgEqualsResponse { lists = EntityLists { floats = listOf(0f) } },
6651
)
6752

68-
@Test
69-
fun testDoubleListAvgNotEquals() = successTest(
53+
@Test fun testDoubleListAvgNotEquals() = successTest(
54+
GetFunctionAvgEqualsRequest { name = "test" },
7055
WaitersTestClient::waitUntilDoubleListAvgNotEquals,
7156
GetFunctionAvgEqualsResponse { lists = EntityLists { doubles = listOf(12.0, 12.0, 10.0, 8.0, 8.0) } },
7257
GetFunctionAvgEqualsResponse { lists = EntityLists { doubles = listOf(10.0, 10.0) } },

tests/codegen/waiter-tests/src/test/kotlin/com/test/FunctionCeilTest.kt

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,37 @@
44
*/
55
package com.test
66

7-
import aws.smithy.kotlin.runtime.retries.Outcome
8-
import aws.smithy.kotlin.runtime.retries.getOrThrow
97
import com.test.model.EntityPrimitives
108
import com.test.model.GetFunctionCeilRequest
119
import com.test.model.GetFunctionCeilResponse
10+
import com.test.utils.successTest
1211
import com.test.waiters.*
13-
import kotlinx.coroutines.test.runTest
1412
import org.junit.jupiter.api.Test
15-
import kotlin.test.assertEquals
1613

1714
class FunctionCeilTest {
18-
private fun successTest(
19-
block: suspend WaitersTestClient.(request: GetFunctionCeilRequest) -> Outcome<GetFunctionCeilResponse>,
20-
vararg results: GetFunctionCeilResponse,
21-
): Unit = runTest {
22-
val client = DefaultWaitersTestClient(results.map { Result.success(it) })
23-
val req = GetFunctionCeilRequest { name = "test" }
24-
25-
val outcome = client.block(req)
26-
assertEquals(results.size, outcome.attempts)
27-
assertEquals(results.last(), outcome.getOrThrow())
28-
}
29-
3015
@Test fun testCeilFunctionShortEquals() = successTest(
16+
GetFunctionCeilRequest { name = "test" },
3117
WaitersTestClient::waitUntilCeilFunctionShortEquals,
3218
GetFunctionCeilResponse { primitives = EntityPrimitives { short = 1 } },
3319
GetFunctionCeilResponse { primitives = EntityPrimitives { short = 2 } },
3420
)
3521

3622
@Test fun testCeilFunctionIntegerEquals() = successTest(
23+
GetFunctionCeilRequest { name = "test" },
3724
WaitersTestClient::waitUntilCeilFunctionIntegerEquals,
3825
GetFunctionCeilResponse { primitives = EntityPrimitives { integer = 1 } },
3926
GetFunctionCeilResponse { primitives = EntityPrimitives { integer = 2 } },
4027
)
4128

4229
@Test fun testCeilFunctionLongEquals() = successTest(
30+
GetFunctionCeilRequest { name = "test" },
4331
WaitersTestClient::waitUntilCeilFunctionLongEquals,
4432
GetFunctionCeilResponse { primitives = EntityPrimitives { long = 1L } },
4533
GetFunctionCeilResponse { primitives = EntityPrimitives { long = 2L } },
4634
)
4735

4836
@Test fun testCeilFunctionFloatEquals() = successTest(
37+
GetFunctionCeilRequest { name = "test" },
4938
WaitersTestClient::waitUntilCeilFunctionFloatEquals,
5039
GetFunctionCeilResponse { primitives = EntityPrimitives { float = 0.0001f } },
5140
GetFunctionCeilResponse { primitives = EntityPrimitives { float = 0.9f } },
@@ -54,6 +43,7 @@ class FunctionCeilTest {
5443
)
5544

5645
@Test fun testCeilFunctionDoubleEquals() = successTest(
46+
GetFunctionCeilRequest { name = "test" },
5747
WaitersTestClient::waitUntilCeilFunctionDoubleEquals,
5848
GetFunctionCeilResponse { primitives = EntityPrimitives { double = 0.0001 } },
5949
GetFunctionCeilResponse { primitives = EntityPrimitives { double = 0.9 } },

tests/codegen/waiter-tests/src/test/kotlin/com/test/FunctionContainsTest.kt

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,16 @@
44
*/
55
package com.test
66

7-
import aws.smithy.kotlin.runtime.retries.Outcome
8-
import aws.smithy.kotlin.runtime.retries.getOrThrow
97
import com.test.model.*
108
import com.test.model.Enum
9+
import com.test.utils.successTest
1110
import com.test.waiters.*
12-
import kotlinx.coroutines.test.runTest
1311
import org.junit.jupiter.api.Test
14-
import kotlin.test.assertEquals
1512

1613
class FunctionContainsTest {
17-
private fun successTest(
18-
block: suspend WaitersTestClient.(request: GetFunctionContainsRequest) -> Outcome<GetFunctionContainsResponse>,
19-
vararg results: GetFunctionContainsResponse,
20-
): Unit = runTest {
21-
val client = DefaultWaitersTestClient(results.map { Result.success(it) })
22-
val req = GetFunctionContainsRequest { name = "test" }
23-
24-
val outcome = client.block(req)
25-
assertEquals(results.size, outcome.attempts)
26-
assertEquals(results.last(), outcome.getOrThrow())
27-
}
28-
2914
// list
3015
@Test fun testBooleanListContains() = successTest(
16+
GetFunctionContainsRequest { name = "test" },
3117
WaitersTestClient::waitUntilBooleanListContains,
3218
GetFunctionContainsResponse {
3319
primitives = EntityPrimitives { boolean = true }
@@ -40,6 +26,7 @@ class FunctionContainsTest {
4026
)
4127

4228
@Test fun testBooleanListContainsIdentityProjection() = successTest(
29+
GetFunctionContainsRequest { name = "test" },
4330
WaitersTestClient::waitUntilBooleanListContainsIdentityProjection,
4431
GetFunctionContainsResponse {
4532
primitives = EntityPrimitives { boolean = true }
@@ -52,6 +39,7 @@ class FunctionContainsTest {
5239
)
5340

5441
@Test fun testStringListContains() = successTest(
42+
GetFunctionContainsRequest { name = "test" },
5543
WaitersTestClient::waitUntilStringListContains,
5644
GetFunctionContainsResponse {
5745
primitives = EntityPrimitives { string = "bar" }
@@ -64,6 +52,7 @@ class FunctionContainsTest {
6452
)
6553

6654
@Test fun testIntegerListContains() = successTest(
55+
GetFunctionContainsRequest { name = "test" },
6756
WaitersTestClient::waitUntilIntegerListContains,
6857
GetFunctionContainsResponse {
6958
primitives = EntityPrimitives { integer = 10 }
@@ -76,6 +65,7 @@ class FunctionContainsTest {
7665
)
7766

7867
@Test fun testEnumListContains() = successTest(
68+
GetFunctionContainsRequest { name = "test" },
7969
WaitersTestClient::waitUntilEnumListContains,
8070
GetFunctionContainsResponse {
8171
primitives = EntityPrimitives { enum = Enum.Two }
@@ -88,6 +78,7 @@ class FunctionContainsTest {
8878
)
8979

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

10293
// object projection
10394
@Test fun testBooleanMapContains() = successTest(
95+
GetFunctionContainsRequest { name = "test" },
10496
WaitersTestClient::waitUntilBooleanMapContains,
10597
GetFunctionContainsResponse {
10698
primitives = EntityPrimitives { boolean = false }
@@ -113,6 +105,7 @@ class FunctionContainsTest {
113105
)
114106

115107
@Test fun testStringMapContains() = successTest(
108+
GetFunctionContainsRequest { name = "test" },
116109
WaitersTestClient::waitUntilStringMapContains,
117110
GetFunctionContainsResponse {
118111
primitives = EntityPrimitives { string = "bar" }
@@ -125,6 +118,7 @@ class FunctionContainsTest {
125118
)
126119

127120
@Test fun testIntegerMapContains() = successTest(
121+
GetFunctionContainsRequest { name = "test" },
128122
WaitersTestClient::waitUntilIntegerMapContains,
129123
GetFunctionContainsResponse {
130124
primitives = EntityPrimitives { integer = 10 }
@@ -137,6 +131,7 @@ class FunctionContainsTest {
137131
)
138132

139133
@Test fun testEnumMapContains() = successTest(
134+
GetFunctionContainsRequest { name = "test" },
140135
WaitersTestClient::waitUntilEnumMapContains,
141136
GetFunctionContainsResponse {
142137
primitives = EntityPrimitives { enum = Enum.Two }
@@ -149,6 +144,7 @@ class FunctionContainsTest {
149144
)
150145

151146
@Test fun testIntEnumMapContains() = successTest(
147+
GetFunctionContainsRequest { name = "test" },
152148
WaitersTestClient::waitUntilIntEnumMapContains,
153149
GetFunctionContainsResponse {
154150
primitives = EntityPrimitives { intEnum = IntEnum.Two }

0 commit comments

Comments
 (0)