Skip to content

Commit

Permalink
update rfc3339 parsing test
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoh committed Jan 19, 2023
1 parent a6df039 commit 843e312
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ import software.amazon.smithy.rust.codegen.client.smithy.endpoint.EndpointTypesG
import software.amazon.smithy.rust.codegen.client.smithy.endpoint.generators.EndpointsModule
import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization
import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig
import software.amazon.smithy.rust.codegen.core.rustlang.Attribute
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.core.rustlang.Writable
import software.amazon.smithy.rust.codegen.core.rustlang.rust
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
import software.amazon.smithy.rust.codegen.core.rustlang.writable
import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig
import software.amazon.smithy.rust.codegen.core.smithy.RustCrate
import software.amazon.smithy.rust.codegen.core.smithy.customize.AdHocSection
Expand Down Expand Up @@ -200,61 +198,6 @@ class AwsEndpointDecorator : ClientCodegenDecorator {
}
}

class SdkEndpointCustomization(
codegenContext: CodegenContext,
) :
ConfigCustomization() {
private val runtimeConfig = codegenContext.runtimeConfig
private val resolveAwsEndpoint = AwsRuntimeType.awsEndpoint(runtimeConfig).resolve("ResolveAwsEndpoint")
private val endpointShim = AwsRuntimeType.awsEndpoint(runtimeConfig).resolve("EndpointShim")
private val codegenScope = arrayOf(
"ResolveAwsEndpoint" to resolveAwsEndpoint,
"EndpointShim" to endpointShim,
"aws_types" to AwsRuntimeType.awsTypes(runtimeConfig),
)

override fun section(section: ServiceConfig): Writable = writable {
when (section) {
ServiceConfig.BuilderImpl -> rustTemplate(
"""
/// Sets the endpoint url used to communicate with this service
///
/// Note: this is used in combination with other endpoint rules, e.g. an API that applies a host-label prefix
/// will be prefixed onto this URL. To fully override the endpoint resolver, use
/// [`Builder::endpoint_resolver`].
pub fn endpoint_url(mut self, endpoint_url: impl Into<String>) -> Self {
self.endpoint_url = Some(endpoint_url.into());
self
}
/// Sets the endpoint url used to communicate with this service
///
/// Note: this is used in combination with other endpoint rules, e.g. an API that applies a host-label prefix
/// will be prefixed onto this URL. To fully override the endpoint resolver, use
/// [`Builder::endpoint_resolver`].
pub fn set_endpoint_url(&mut self, endpoint_url: Option<String>) -> &mut Self {
self.endpoint_url = endpoint_url;
self
}
""",
*codegenScope,
)

ServiceConfig.BuilderBuild -> rust("endpoint_url: self.endpoint_url,")
ServiceConfig.BuilderStruct -> rust("endpoint_url: Option<String>,")
ServiceConfig.ConfigImpl -> {
Attribute.AllowDeadCode.render(this)
rust("pub(crate) fn endpoint_url(&self) -> Option<&str> { self.endpoint_url.as_deref() }")
}

ServiceConfig.ConfigStruct -> rust("endpoint_url: Option<String>,")
ServiceConfig.ConfigStructAdditionalDocs -> emptySection
ServiceConfig.Extras -> emptySection
else -> emptySection
}
}
}

class PubUseEndpoint(private val runtimeConfig: RuntimeConfig) : LibRsCustomization() {
override fun section(section: LibRsSection): Writable {
return when (section) {
Expand Down
9 changes: 2 additions & 7 deletions rust-runtime/aws-smithy-types/src/date_time/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,13 +661,8 @@ mod tests {

#[test]
fn parse_rfc3339_timezone_forbidden() {
let dt = rfc3339::parse("1985-04-12T23:20:50-02:00");
assert!(matches!(
dt.unwrap_err(),
DateTimeParseError {
kind: DateTimeParseErrorKind::Invalid(_)
}
));
let dt = rfc3339::parse("1985-04-12T21:20:51-02:00");
assert_eq!(dt.unwrap(), DateTime::from_secs_and_nanos(482196051, 0));
}

#[test]
Expand Down

0 comments on commit 843e312

Please sign in to comment.