Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Organize codegen tests & Kotlin unit tests #830

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package software.amazon.smithy.swift.codegen

/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
Expand All @@ -6,7 +8,7 @@
import io.kotest.matchers.string.shouldContain
import io.kotest.matchers.string.shouldContainOnlyOnce
import org.junit.jupiter.api.Test
import software.amazon.smithy.swift.codegen.DefaultClientConfigurationIntegration
import software.amazon.smithy.swift.codegen.protocolgeneratormocks.MockHTTPRestJsonProtocolGenerator

class HttpProtocolClientGeneratorTests {
@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package software.amazon.smithy.swift.codegen

/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package software.amazon.smithy.swift.codegen

/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
Expand All @@ -8,7 +10,7 @@ import org.junit.jupiter.api.Test
import software.amazon.smithy.swift.codegen.model.AddOperationShapes

open class HttpProtocolUnitTestResponseGeneratorTests {
var model = javaClass.getResource("http-binding-protocol-generator-test.smithy").asSmithy()
var model = javaClass.classLoader.getResource("http-binding-protocol-generator-test.smithy").asSmithy()
private fun newTestContext(): TestContext {
val settings = model.defaultSettings()
model = AddOperationShapes.execute(model, settings.getService(model), settings.moduleName)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package software.amazon.smithy.swift.codegen

/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

import io.kotest.matchers.string.shouldContainOnlyOnce
import org.junit.jupiter.api.Test
import software.amazon.smithy.build.FileManifest
import software.amazon.smithy.codegen.core.SymbolProvider
import software.amazon.smithy.codegen.core.WriterDelegator
import software.amazon.smithy.model.Model
import software.amazon.smithy.swift.codegen.PaginatorGenerator
import software.amazon.smithy.swift.codegen.SwiftDelegator
import software.amazon.smithy.swift.codegen.SwiftSettings
import software.amazon.smithy.swift.codegen.SwiftWriter
import software.amazon.smithy.swift.codegen.core.SwiftCodegenContext
import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator
import software.amazon.smithy.swift.codegen.integration.SwiftIntegration
import software.amazon.smithy.swift.codegen.protocolgeneratormocks.MockHTTPRestJsonProtocolGenerator

class PaginatorGeneratorTest {
@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package software.amazon.smithy.swift.codegen

/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package software.amazon.smithy.swift.codegen

/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
Expand All @@ -21,9 +23,6 @@ import software.amazon.smithy.model.traits.DocumentationTrait
import software.amazon.smithy.model.traits.ErrorTrait
import software.amazon.smithy.model.traits.HttpErrorTrait
import software.amazon.smithy.model.traits.RetryableTrait
import software.amazon.smithy.swift.codegen.SwiftCodegenPlugin
import software.amazon.smithy.swift.codegen.SwiftDelegator
import software.amazon.smithy.swift.codegen.SwiftSettings
import software.amazon.smithy.swift.codegen.customtraits.SwiftBoxTrait
import software.amazon.smithy.swift.codegen.integration.HTTPBindingProtocolGenerator
import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator
Expand All @@ -32,6 +31,7 @@ import software.amazon.smithy.swift.codegen.model.AddOperationShapes
import software.amazon.smithy.swift.codegen.model.NeedsReaderWriterTransformer
import software.amazon.smithy.swift.codegen.model.NestedShapeTransformer
import software.amazon.smithy.swift.codegen.model.RecursiveShapeBoxer
import software.amazon.smithy.swift.codegen.protocolgeneratormocks.MockHTTPRestJsonProtocolGenerator
import java.net.URL

/**
Expand Down Expand Up @@ -277,7 +277,7 @@ class TestContext(

var modelAssembler = Model.assembler()
for (smithyFile in smithyFiles) {
modelAssembler.addImport(javaClass.getResource(smithyFile))
modelAssembler.addImport(javaClass.classLoader.getResource(smithyFile))
}
var model = modelAssembler
.discoverModels()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package software.amazon.smithy.swift.codegen.basicshapes

/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
Expand All @@ -15,6 +17,10 @@ import software.amazon.smithy.model.traits.EnumTrait
import software.amazon.smithy.swift.codegen.EnumGenerator
import software.amazon.smithy.swift.codegen.SwiftCodegenPlugin
import software.amazon.smithy.swift.codegen.SwiftWriter
import software.amazon.smithy.swift.codegen.asSmithy
import software.amazon.smithy.swift.codegen.buildMockPluginContext
import software.amazon.smithy.swift.codegen.createModelFromShapes
import software.amazon.smithy.swift.codegen.defaultSettings

class EnumGeneratorTests {

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

@Test
fun `generates enums from IDL-2 enum shape`() {
val model = javaClass.getResource("enum-shape-test.smithy").asSmithy()
val model = javaClass.classLoader.getResource("enum-shape-test.smithy").asSmithy()
val manifest = MockManifest()
val context = buildMockPluginContext(model, manifest, "smithy.example#Example")
SwiftCodegenPlugin().execute(context)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
package software.amazon.smithy.swift.codegen.basicshapes

/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

import io.kotest.matchers.string.shouldContain
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import software.amazon.smithy.build.MockManifest
import software.amazon.smithy.swift.codegen.SwiftCodegenPlugin
import software.amazon.smithy.swift.codegen.asSmithy
import software.amazon.smithy.swift.codegen.buildMockPluginContext

class IntEnumGeneratorTests {

@Test
fun `generates int enum`() {
val model = javaClass.getResource("int-enum-shape-test.smithy").asSmithy()
val model = javaClass.classLoader.getResource("int-enum-shape-test.smithy").asSmithy()
val manifest = MockManifest()
val context = buildMockPluginContext(model, manifest, "smithy.example#Example")
SwiftCodegenPlugin().execute(context)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package software.amazon.smithy.swift.codegen.basicshapes

/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
Expand All @@ -6,13 +8,19 @@
import io.kotest.matchers.string.shouldContainOnlyOnce
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import software.amazon.smithy.swift.codegen.TestContext
import software.amazon.smithy.swift.codegen.asSmithy
import software.amazon.smithy.swift.codegen.defaultSettings
import software.amazon.smithy.swift.codegen.getModelFileContents
import software.amazon.smithy.swift.codegen.model.AddOperationShapes
import software.amazon.smithy.swift.codegen.model.NeedsReaderWriterTransformer
import software.amazon.smithy.swift.codegen.model.NestedShapeTransformer
import software.amazon.smithy.swift.codegen.model.RecursiveShapeBoxer
import software.amazon.smithy.swift.codegen.newTestContext
import software.amazon.smithy.swift.codegen.shouldSyntacticSanityCheck

class StructDecodeGenerationTests {
var model = javaClass.getResource("http-binding-protocol-generator-test.smithy").asSmithy()
var model = javaClass.classLoader.getResource("http-binding-protocol-generator-test.smithy").asSmithy()
private fun newTestContext(): TestContext {
val settings = model.defaultSettings()
model = AddOperationShapes.execute(model, settings.getService(model), settings.moduleName)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package software.amazon.smithy.swift.codegen.basicshapes

/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
Expand All @@ -6,6 +8,10 @@
import io.kotest.matchers.string.shouldContainOnlyOnce
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import software.amazon.smithy.swift.codegen.TestContext
import software.amazon.smithy.swift.codegen.getFileContents
import software.amazon.smithy.swift.codegen.getModelFileContents
import software.amazon.smithy.swift.codegen.shouldSyntacticSanityCheck

class StructEncodeGenerationIsolatedTests {
@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package software.amazon.smithy.swift.codegen.basicshapes

/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
Expand All @@ -6,12 +8,18 @@
import io.kotest.matchers.string.shouldContainOnlyOnce
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import software.amazon.smithy.swift.codegen.TestContext
import software.amazon.smithy.swift.codegen.asSmithy
import software.amazon.smithy.swift.codegen.defaultSettings
import software.amazon.smithy.swift.codegen.getModelFileContents
import software.amazon.smithy.swift.codegen.model.AddOperationShapes
import software.amazon.smithy.swift.codegen.model.NeedsReaderWriterTransformer
import software.amazon.smithy.swift.codegen.model.RecursiveShapeBoxer
import software.amazon.smithy.swift.codegen.newTestContext
import software.amazon.smithy.swift.codegen.shouldSyntacticSanityCheck

class StructEncodeGenerationTests {
var model = javaClass.getResource("http-binding-protocol-generator-test.smithy").asSmithy()
var model = javaClass.classLoader.getResource("http-binding-protocol-generator-test.smithy").asSmithy()
private fun newTestContext(): TestContext {
val settings = model.defaultSettings()
model = AddOperationShapes.execute(model, settings.getService(model), settings.moduleName)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package software.amazon.smithy.swift.codegen.basicshapes

/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
Expand All @@ -16,6 +18,15 @@ import software.amazon.smithy.model.shapes.StructureShape
import software.amazon.smithy.swift.codegen.StructureGenerator
import software.amazon.smithy.swift.codegen.SwiftCodegenPlugin
import software.amazon.smithy.swift.codegen.SwiftWriter
import software.amazon.smithy.swift.codegen.asSmithy
import software.amazon.smithy.swift.codegen.buildMockPluginContext
import software.amazon.smithy.swift.codegen.createModelWithStructureWithoutErrorTrait
import software.amazon.smithy.swift.codegen.createStructureContainingNestedRecursiveShape
import software.amazon.smithy.swift.codegen.createStructureContainingNestedRecursiveShapeList
import software.amazon.smithy.swift.codegen.createStructureWithOptionalErrorMessage
import software.amazon.smithy.swift.codegen.defaultSettings
import software.amazon.smithy.swift.codegen.getModelFileContents
import software.amazon.smithy.swift.codegen.shouldSyntacticSanityCheck
import java.util.function.Consumer

class StructureGeneratorTests {
Expand Down Expand Up @@ -58,7 +69,7 @@ class StructureGeneratorTests {

@Test
fun `it renders struct with primitive types`() {
val model = javaClass.getResource("primitive-type-encode-test.smithy").asSmithy()
val model = javaClass.classLoader.getResource("primitive-type-encode-test.smithy").asSmithy()
val manifest = MockManifest()
val context = buildMockPluginContext(model, manifest, "smithy.example#Example")
SwiftCodegenPlugin().execute(context)
Expand Down Expand Up @@ -127,7 +138,7 @@ class StructureGeneratorTests {
@Test
fun `it renders recursive nested shapes`() {
val structs = createStructureContainingNestedRecursiveShape()
val model = javaClass.getResource("recursive-shape-test.smithy").asSmithy()
val model = javaClass.classLoader.getResource("recursive-shape-test.smithy").asSmithy()
val swiftSettings = model.defaultSettings()
val provider = SwiftCodegenPlugin.createSymbolProvider(model, swiftSettings)
val writer = SwiftWriter("MockPackage")
Expand Down Expand Up @@ -185,7 +196,7 @@ public struct RecursiveShapesInputOutput {
@Test
fun `it renders recursive nested shapes in lists`() {
val structs = createStructureContainingNestedRecursiveShapeList()
val model = javaClass.getResource("recursive-shape-test.smithy").asSmithy()
val model = javaClass.classLoader.getResource("recursive-shape-test.smithy").asSmithy()
val swiftSettings = model.defaultSettings()
val provider = SwiftCodegenPlugin.createSymbolProvider(model, swiftSettings)
val writer = SwiftWriter("MockPackage")
Expand Down Expand Up @@ -301,7 +312,7 @@ public struct MyError: ClientRuntime.ModeledError, ClientRuntime.ServiceError, C

@Test
fun `check for sparse and dense datatypes in list`() {
val model = javaClass.getResource("sparse-trait-test.smithy").asSmithy()
val model = javaClass.classLoader.getResource("sparse-trait-test.smithy").asSmithy()
val manifest = MockManifest()
val context = buildMockPluginContext(model, manifest, "smithy.example#Example")
SwiftCodegenPlugin().execute(context)
Expand Down Expand Up @@ -347,7 +358,7 @@ public struct JsonListsInput {
separate structs for input and output with members given in smithy model, without creating
additional structs in the model
*/
val model = javaClass.getResource("sparse-trait-test.smithy").asSmithy()
val model = javaClass.classLoader.getResource("sparse-trait-test.smithy").asSmithy()
val manifest = MockManifest()
val context = buildMockPluginContext(model, manifest, "smithy.example#Example")
SwiftCodegenPlugin().execute(context)
Expand Down Expand Up @@ -431,7 +442,7 @@ public struct JsonMapsOutput {

@Test
fun `deprecated trait on structure`() {
val model = javaClass.getResource("deprecated-trait-test.smithy").asSmithy()
val model = javaClass.classLoader.getResource("deprecated-trait-test.smithy").asSmithy()
val manifest = MockManifest()
val context = buildMockPluginContext(model, manifest, "smithy.example#Example")
SwiftCodegenPlugin().execute(context)
Expand Down Expand Up @@ -459,7 +470,7 @@ public struct JsonMapsOutput {

@Test
fun `deprecated trait on synthetically cloned structure and structure member`() {
val model = javaClass.getResource("deprecated-trait-test.smithy").asSmithy()
val model = javaClass.classLoader.getResource("deprecated-trait-test.smithy").asSmithy()
val manifest = MockManifest()
val context = buildMockPluginContext(model, manifest, "smithy.example#Example")
SwiftCodegenPlugin().execute(context)
Expand All @@ -485,7 +496,7 @@ public struct JsonMapsOutput {

@Test
fun `deprecated trait fetched from the target of a struct member`() {
val model = javaClass.getResource("deprecated-trait-test.smithy").asSmithy()
val model = javaClass.classLoader.getResource("deprecated-trait-test.smithy").asSmithy()
val manifest = MockManifest()
val context = buildMockPluginContext(model, manifest, "smithy.example#Example")
SwiftCodegenPlugin().execute(context)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package software.amazon.smithy.swift.codegen.basicshapes

/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
Expand All @@ -6,12 +8,18 @@
import io.kotest.matchers.string.shouldContainOnlyOnce
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import software.amazon.smithy.swift.codegen.TestContext
import software.amazon.smithy.swift.codegen.asSmithy
import software.amazon.smithy.swift.codegen.defaultSettings
import software.amazon.smithy.swift.codegen.getModelFileContents
import software.amazon.smithy.swift.codegen.model.AddOperationShapes
import software.amazon.smithy.swift.codegen.model.NeedsReaderWriterTransformer
import software.amazon.smithy.swift.codegen.model.NestedShapeTransformer
import software.amazon.smithy.swift.codegen.newTestContext
import software.amazon.smithy.swift.codegen.shouldSyntacticSanityCheck

class UnionDecodeGeneratorTests {
var model = javaClass.getResource("http-binding-protocol-generator-test.smithy").asSmithy()
var model = javaClass.classLoader.getResource("http-binding-protocol-generator-test.smithy").asSmithy()
private fun newTestContext(): TestContext {
val settings = model.defaultSettings()
model = AddOperationShapes.execute(model, settings.getService(model), settings.moduleName)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package software.amazon.smithy.swift.codegen.basicshapes

/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
Expand All @@ -7,13 +9,19 @@ import io.kotest.matchers.string.shouldContainOnlyOnce
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import software.amazon.smithy.model.Model
import software.amazon.smithy.swift.codegen.TestContext
import software.amazon.smithy.swift.codegen.asSmithy
import software.amazon.smithy.swift.codegen.defaultSettings
import software.amazon.smithy.swift.codegen.getModelFileContents
import software.amazon.smithy.swift.codegen.model.AddOperationShapes
import software.amazon.smithy.swift.codegen.model.NeedsReaderWriterTransformer
import software.amazon.smithy.swift.codegen.model.NestedShapeTransformer
import software.amazon.smithy.swift.codegen.model.RecursiveShapeBoxer
import software.amazon.smithy.swift.codegen.newTestContext
import software.amazon.smithy.swift.codegen.shouldSyntacticSanityCheck

class UnionEncodeGeneratorTests {
var model = javaClass.getResource("http-binding-protocol-generator-test.smithy").asSmithy()
var model = javaClass.classLoader.getResource("http-binding-protocol-generator-test.smithy").asSmithy()
private fun newTestContext(): TestContext {
model = preprocessModel(model)
return model.newTestContext()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package software.amazon.smithy.swift.codegen.basicshapes

/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
Expand All @@ -13,6 +15,8 @@ import software.amazon.smithy.model.traits.DocumentationTrait
import software.amazon.smithy.swift.codegen.SwiftCodegenPlugin
import software.amazon.smithy.swift.codegen.SwiftWriter
import software.amazon.smithy.swift.codegen.UnionGenerator
import software.amazon.smithy.swift.codegen.createModelFromShapes
import software.amazon.smithy.swift.codegen.defaultSettings
import software.amazon.smithy.swift.codegen.model.UnionIndirectivizer

class UnionGeneratorTests {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
package software.amazon.smithy.swift.codegen.codegencomponents

/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import software.amazon.smithy.swift.codegen.utils.toLowerCamelCase
Expand Down
Loading
Loading