Skip to content

Commit a9c1aa9

Browse files
sichanyooSichan Yoo
andauthored
chore: Organize codegen tests & Kotlin unit tests (#830)
* Organize codegen tests & refactor setup tests for XML codegen tests to reduce duplicate code. * ktlint --------- Co-authored-by: Sichan Yoo <[email protected]>
1 parent 5ce644b commit a9c1aa9

File tree

76 files changed

+453
-422
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+453
-422
lines changed

smithy-swift-codegen/src/test/kotlin/HttpProtocolClientGeneratorTests.kt renamed to smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/HttpProtocolClientGeneratorTests.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package software.amazon.smithy.swift.codegen
2+
13
/*
24
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
35
* SPDX-License-Identifier: Apache-2.0.
@@ -6,7 +8,7 @@
68
import io.kotest.matchers.string.shouldContain
79
import io.kotest.matchers.string.shouldContainOnlyOnce
810
import org.junit.jupiter.api.Test
9-
import software.amazon.smithy.swift.codegen.DefaultClientConfigurationIntegration
11+
import software.amazon.smithy.swift.codegen.protocolgeneratormocks.MockHTTPRestJsonProtocolGenerator
1012

1113
class HttpProtocolClientGeneratorTests {
1214
@Test

smithy-swift-codegen/src/test/kotlin/HttpProtocolUnitTestErrorGeneratorTests.kt renamed to smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/HttpProtocolUnitTestErrorGeneratorTests.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package software.amazon.smithy.swift.codegen
2+
13
/*
24
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
35
* SPDX-License-Identifier: Apache-2.0.

smithy-swift-codegen/src/test/kotlin/HttpProtocolUnitTestResponseGeneratorTests.kt renamed to smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/HttpProtocolUnitTestResponseGeneratorTests.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package software.amazon.smithy.swift.codegen
2+
13
/*
24
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
35
* SPDX-License-Identifier: Apache-2.0.
@@ -8,7 +10,7 @@ import org.junit.jupiter.api.Test
810
import software.amazon.smithy.swift.codegen.model.AddOperationShapes
911

1012
open class HttpProtocolUnitTestResponseGeneratorTests {
11-
var model = javaClass.getResource("http-binding-protocol-generator-test.smithy").asSmithy()
13+
var model = javaClass.classLoader.getResource("http-binding-protocol-generator-test.smithy").asSmithy()
1214
private fun newTestContext(): TestContext {
1315
val settings = model.defaultSettings()
1416
model = AddOperationShapes.execute(model, settings.getService(model), settings.moduleName)

smithy-swift-codegen/src/test/kotlin/PaginatorGeneratorTest.kt renamed to smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/PaginatorGeneratorTest.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1+
package software.amazon.smithy.swift.codegen
2+
3+
/*
4+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5+
* SPDX-License-Identifier: Apache-2.0.
6+
*/
17

28
import io.kotest.matchers.string.shouldContainOnlyOnce
39
import org.junit.jupiter.api.Test
410
import software.amazon.smithy.build.FileManifest
511
import software.amazon.smithy.codegen.core.SymbolProvider
612
import software.amazon.smithy.codegen.core.WriterDelegator
713
import software.amazon.smithy.model.Model
8-
import software.amazon.smithy.swift.codegen.PaginatorGenerator
9-
import software.amazon.smithy.swift.codegen.SwiftDelegator
10-
import software.amazon.smithy.swift.codegen.SwiftSettings
11-
import software.amazon.smithy.swift.codegen.SwiftWriter
1214
import software.amazon.smithy.swift.codegen.core.SwiftCodegenContext
1315
import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator
1416
import software.amazon.smithy.swift.codegen.integration.SwiftIntegration
17+
import software.amazon.smithy.swift.codegen.protocolgeneratormocks.MockHTTPRestJsonProtocolGenerator
1518

1619
class PaginatorGeneratorTest {
1720
@Test

smithy-swift-codegen/src/test/kotlin/ServiceRenamesTests.kt renamed to smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/ServiceRenamesTests.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package software.amazon.smithy.swift.codegen
2+
13
/*
24
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
35
* SPDX-License-Identifier: Apache-2.0.

smithy-swift-codegen/src/test/kotlin/TestUtils.kt renamed to smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/TestUtils.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package software.amazon.smithy.swift.codegen
2+
13
/*
24
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
35
* SPDX-License-Identifier: Apache-2.0.
@@ -21,9 +23,6 @@ import software.amazon.smithy.model.traits.DocumentationTrait
2123
import software.amazon.smithy.model.traits.ErrorTrait
2224
import software.amazon.smithy.model.traits.HttpErrorTrait
2325
import software.amazon.smithy.model.traits.RetryableTrait
24-
import software.amazon.smithy.swift.codegen.SwiftCodegenPlugin
25-
import software.amazon.smithy.swift.codegen.SwiftDelegator
26-
import software.amazon.smithy.swift.codegen.SwiftSettings
2726
import software.amazon.smithy.swift.codegen.customtraits.SwiftBoxTrait
2827
import software.amazon.smithy.swift.codegen.integration.HTTPBindingProtocolGenerator
2928
import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator
@@ -32,6 +31,7 @@ import software.amazon.smithy.swift.codegen.model.AddOperationShapes
3231
import software.amazon.smithy.swift.codegen.model.NeedsReaderWriterTransformer
3332
import software.amazon.smithy.swift.codegen.model.NestedShapeTransformer
3433
import software.amazon.smithy.swift.codegen.model.RecursiveShapeBoxer
34+
import software.amazon.smithy.swift.codegen.protocolgeneratormocks.MockHTTPRestJsonProtocolGenerator
3535
import java.net.URL
3636

3737
/**
@@ -277,7 +277,7 @@ class TestContext(
277277

278278
var modelAssembler = Model.assembler()
279279
for (smithyFile in smithyFiles) {
280-
modelAssembler.addImport(javaClass.getResource(smithyFile))
280+
modelAssembler.addImport(javaClass.classLoader.getResource(smithyFile))
281281
}
282282
var model = modelAssembler
283283
.discoverModels()

smithy-swift-codegen/src/test/kotlin/EnumGeneratorTests.kt renamed to smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/basicshapes/EnumGeneratorTests.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package software.amazon.smithy.swift.codegen.basicshapes
2+
13
/*
24
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
35
* SPDX-License-Identifier: Apache-2.0.
@@ -15,6 +17,10 @@ import software.amazon.smithy.model.traits.EnumTrait
1517
import software.amazon.smithy.swift.codegen.EnumGenerator
1618
import software.amazon.smithy.swift.codegen.SwiftCodegenPlugin
1719
import software.amazon.smithy.swift.codegen.SwiftWriter
20+
import software.amazon.smithy.swift.codegen.asSmithy
21+
import software.amazon.smithy.swift.codegen.buildMockPluginContext
22+
import software.amazon.smithy.swift.codegen.createModelFromShapes
23+
import software.amazon.smithy.swift.codegen.defaultSettings
1824

1925
class EnumGeneratorTests {
2026

@@ -130,7 +136,7 @@ public enum MyEnum: Swift.Equatable, Swift.RawRepresentable, Swift.CaseIterable,
130136

131137
@Test
132138
fun `generates enums from IDL-2 enum shape`() {
133-
val model = javaClass.getResource("enum-shape-test.smithy").asSmithy()
139+
val model = javaClass.classLoader.getResource("enum-shape-test.smithy").asSmithy()
134140
val manifest = MockManifest()
135141
val context = buildMockPluginContext(model, manifest, "smithy.example#Example")
136142
SwiftCodegenPlugin().execute(context)

smithy-swift-codegen/src/test/kotlin/IntEnumGeneratorTests.kt renamed to smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/basicshapes/IntEnumGeneratorTests.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1+
package software.amazon.smithy.swift.codegen.basicshapes
2+
3+
/*
4+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5+
* SPDX-License-Identifier: Apache-2.0.
6+
*/
7+
18
import io.kotest.matchers.string.shouldContain
29
import org.junit.jupiter.api.Assertions
310
import org.junit.jupiter.api.Test
411
import software.amazon.smithy.build.MockManifest
512
import software.amazon.smithy.swift.codegen.SwiftCodegenPlugin
13+
import software.amazon.smithy.swift.codegen.asSmithy
14+
import software.amazon.smithy.swift.codegen.buildMockPluginContext
615

716
class IntEnumGeneratorTests {
817

918
@Test
1019
fun `generates int enum`() {
11-
val model = javaClass.getResource("int-enum-shape-test.smithy").asSmithy()
20+
val model = javaClass.classLoader.getResource("int-enum-shape-test.smithy").asSmithy()
1221
val manifest = MockManifest()
1322
val context = buildMockPluginContext(model, manifest, "smithy.example#Example")
1423
SwiftCodegenPlugin().execute(context)

smithy-swift-codegen/src/test/kotlin/StructDecodeGenerationTests.kt renamed to smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/basicshapes/StructDecodeGenerationTests.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package software.amazon.smithy.swift.codegen.basicshapes
2+
13
/*
24
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
35
* SPDX-License-Identifier: Apache-2.0.
@@ -6,13 +8,19 @@
68
import io.kotest.matchers.string.shouldContainOnlyOnce
79
import org.junit.jupiter.api.Assertions
810
import org.junit.jupiter.api.Test
11+
import software.amazon.smithy.swift.codegen.TestContext
12+
import software.amazon.smithy.swift.codegen.asSmithy
13+
import software.amazon.smithy.swift.codegen.defaultSettings
14+
import software.amazon.smithy.swift.codegen.getModelFileContents
915
import software.amazon.smithy.swift.codegen.model.AddOperationShapes
1016
import software.amazon.smithy.swift.codegen.model.NeedsReaderWriterTransformer
1117
import software.amazon.smithy.swift.codegen.model.NestedShapeTransformer
1218
import software.amazon.smithy.swift.codegen.model.RecursiveShapeBoxer
19+
import software.amazon.smithy.swift.codegen.newTestContext
20+
import software.amazon.smithy.swift.codegen.shouldSyntacticSanityCheck
1321

1422
class StructDecodeGenerationTests {
15-
var model = javaClass.getResource("http-binding-protocol-generator-test.smithy").asSmithy()
23+
var model = javaClass.classLoader.getResource("http-binding-protocol-generator-test.smithy").asSmithy()
1624
private fun newTestContext(): TestContext {
1725
val settings = model.defaultSettings()
1826
model = AddOperationShapes.execute(model, settings.getService(model), settings.moduleName)

smithy-swift-codegen/src/test/kotlin/StructEncodeGenerationIsolatedTests.kt renamed to smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/basicshapes/StructEncodeGenerationIsolatedTests.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package software.amazon.smithy.swift.codegen.basicshapes
2+
13
/*
24
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
35
* SPDX-License-Identifier: Apache-2.0.
@@ -6,6 +8,10 @@
68
import io.kotest.matchers.string.shouldContainOnlyOnce
79
import org.junit.jupiter.api.Assertions
810
import org.junit.jupiter.api.Test
11+
import software.amazon.smithy.swift.codegen.TestContext
12+
import software.amazon.smithy.swift.codegen.getFileContents
13+
import software.amazon.smithy.swift.codegen.getModelFileContents
14+
import software.amazon.smithy.swift.codegen.shouldSyntacticSanityCheck
915

1016
class StructEncodeGenerationIsolatedTests {
1117
@Test

0 commit comments

Comments
 (0)