-
Notifications
You must be signed in to change notification settings - Fork 35
chore: Opt-in service client tests #1000
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
base: main
Are you sure you want to change the base?
Changes from all commits
2b786ae
bab3f79
3fd2e3e
3aa053f
fc22c30
4083247
0969649
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,13 +5,13 @@ | |
| package software.amazon.smithy.swift.codegen | ||
|
|
||
| import software.amazon.smithy.codegen.core.SymbolDependency | ||
| import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator | ||
| import software.amazon.smithy.swift.codegen.core.GenerationContext | ||
|
|
||
| class PackageManifestGenerator( | ||
| val ctx: ProtocolGenerator.GenerationContext, | ||
| val ctx: GenerationContext, | ||
| ) { | ||
| fun writePackageManifest(dependencies: List<SymbolDependency>) { | ||
| ctx.delegator.useFileWriter("Package.swift") { writer -> | ||
| ctx.writerDelegator().useFileWriter("Package.swift") { writer -> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| writer.write("// swift-tools-version: \$L", ctx.settings.swiftVersion) | ||
| writer.write("") | ||
| writer.write("import PackageDescription") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,8 +38,6 @@ private const val MERGE_MODELS = "mergeModels" | |
| private const val COPYRIGHT_NOTICE = "copyrightNotice" | ||
| private const val VISIBILITY = "visibility" | ||
| private const val INTERNAL_CLIENT = "internalClient" | ||
| private const val GENERATE_PACKAGE_MANIFEST = "generatePackageManifest" | ||
| private const val GENERATE_DEPENDENCY_JSON = "generateDependencyJSON" | ||
|
|
||
| // Prioritized list of protocols supported for code generation | ||
| private val DEFAULT_PROTOCOL_RESOLUTION_PRIORITY = | ||
|
|
@@ -67,8 +65,6 @@ class SwiftSettings( | |
| val copyrightNotice: String, | ||
| val visibility: String, | ||
| val internalClient: Boolean, | ||
| val generatePackageManifest: Boolean, | ||
| val generateDependencyJSON: Boolean, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two |
||
| ) { | ||
| companion object { | ||
| private val LOGGER: Logger = Logger.getLogger(SwiftSettings::class.java.name) | ||
|
|
@@ -100,8 +96,6 @@ class SwiftSettings( | |
| COPYRIGHT_NOTICE, | ||
| VISIBILITY, | ||
| INTERNAL_CLIENT, | ||
| GENERATE_PACKAGE_MANIFEST, | ||
| GENERATE_DEPENDENCY_JSON, | ||
| ), | ||
| ) | ||
|
|
||
|
|
@@ -127,8 +121,6 @@ class SwiftSettings( | |
| ) | ||
| val visibility = config.getStringMemberOrDefault(VISIBILITY, "public") | ||
| val internalClient = config.getBooleanMemberOrDefault(INTERNAL_CLIENT, false) | ||
| val generatePackageManifest = config.getBooleanMemberOrDefault(GENERATE_PACKAGE_MANIFEST, true) | ||
| val generateDependencyJSON = config.getBooleanMemberOrDefault(GENERATE_DEPENDENCY_JSON, false) | ||
|
|
||
| return SwiftSettings( | ||
| serviceId, | ||
|
|
@@ -144,8 +136,6 @@ class SwiftSettings( | |
| copyrightNotice, | ||
| visibility, | ||
| internalClient, | ||
| generatePackageManifest, | ||
| generateDependencyJSON, | ||
| ) | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ 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.core.GenerationContext | ||
| import software.amazon.smithy.swift.codegen.customtraits.SwiftBoxTrait | ||
| import software.amazon.smithy.swift.codegen.integration.HTTPBindingProtocolGenerator | ||
| import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator | ||
|
|
@@ -328,6 +329,7 @@ fun createStructureWithOptionalErrorMessage(): StructureShape { | |
| } | ||
|
|
||
| class TestContext( | ||
| val context: GenerationContext, | ||
| val generationCtx: ProtocolGenerator.GenerationContext, | ||
| val manifest: MockManifest, | ||
| val generator: ProtocolGenerator, | ||
|
|
@@ -398,6 +400,17 @@ fun Model.newTestContext( | |
| .get() | ||
| val delegator = SwiftDelegator(settings, this, manifest, provider) | ||
|
|
||
| val context = | ||
| GenerationContext( | ||
| this, | ||
| provider, | ||
| settings, | ||
| manifest, | ||
| generator, | ||
| emptyList(), | ||
| delegator, | ||
| ) | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This allows for testing codegen outside of a specific protocol. |
||
| val ctx = | ||
| ProtocolGenerator.GenerationContext( | ||
| settings, | ||
|
|
@@ -408,7 +421,7 @@ fun Model.newTestContext( | |
| generator.protocol, | ||
| delegator, | ||
| ) | ||
| return TestContext(ctx, manifest, generator) | ||
| return TestContext(context, ctx, manifest, generator) | ||
| } | ||
|
|
||
| fun getSettingsNode( | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,15 +98,15 @@ class PackageManifestGeneratorTests { | |
| smithyFile: String, | ||
| serviceShapeId: String, | ||
| ): TestContext { | ||
| val context = | ||
| val testContext = | ||
| TestContext.initContextFrom(smithyFile, serviceShapeId, MockHTTPAWSJson11ProtocolGenerator()) { model -> | ||
| model.defaultSettings(serviceShapeId, "MockSDK", "2019-12-16", "MockSDKID") | ||
| } | ||
| context.generationCtx.delegator.useFileWriter("xyz.swift") { writer -> | ||
| testContext.generationCtx.delegator.useFileWriter("xyz.swift") { writer -> | ||
| writer.addDependency(SwiftDependency.CLIENT_RUNTIME) | ||
| } | ||
| PackageManifestGenerator(context.generationCtx).writePackageManifest(context.generationCtx.delegator.dependencies) | ||
| context.generationCtx.delegator.flushWriters() | ||
| return context | ||
| PackageManifestGenerator(testContext.context).writePackageManifest(testContext.generationCtx.delegator.dependencies) | ||
| testContext.generationCtx.delegator.flushWriters() | ||
| return testContext | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test setup modified to use the See just below for where the |
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.