Skip to content

Commit 79064b1

Browse files
committed
more test on dates with fractional seconds
1 parent 213b75d commit 79064b1

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Tests/AWSLambdaEventsTests/S3Tests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ struct S3Tests {
112112
#expect(record.awsRegion == .eu_central_1)
113113
#expect(record.eventName == "ObjectCreated:Put")
114114
#expect(record.eventTime.ISO8601Format() == Date(timeIntervalSince1970: 1_578_907_540.621).ISO8601Format())
115+
// see https://github.com/swiftlang/swift-foundation/issues/1561#issuecomment-3448853449
116+
#expect(abs(record.eventTime.timeIntervalSince1970 - 1_578_907_540.621) < 0.0005)
115117
#expect(record.userIdentity == S3Event.UserIdentity(principalId: "AWS:AAAAAAAJ2MQ4YFQZ7AULJ"))
116118
#expect(record.requestParameters == S3Event.RequestParameters(sourceIPAddress: "123.123.123.123"))
117119
#expect(record.responseElements.count == 2)
@@ -136,6 +138,8 @@ struct S3Tests {
136138
#expect(record.awsRegion == .eu_central_1)
137139
#expect(record.eventName == "ObjectRemoved:DeleteMarkerCreated")
138140
#expect(record.eventTime.ISO8601Format() == Date(timeIntervalSince1970: 1_578_907_540.621).ISO8601Format())
141+
// see https://github.com/swiftlang/swift-foundation/issues/1561#issuecomment-3448853449
142+
#expect(abs(record.eventTime.timeIntervalSince1970 - 1_578_907_540.621) < 0.0005)
139143
#expect(record.userIdentity == S3Event.UserIdentity(principalId: "AWS:AAAAAAAJ2MQ4YFQZ7AULJ"))
140144
#expect(record.requestParameters == S3Event.RequestParameters(sourceIPAddress: "123.123.123.123"))
141145
#expect(record.responseElements.count == 2)

Tests/AWSLambdaEventsTests/Utils/DateWrapperTests.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,13 @@ struct DateWrapperTests {
6666
let date = "2020-03-26T16:53:05Z" // missing fractional seconds
6767
let json = #"{"date":"\#(date)"}"#
6868
#if swift(<6.2)
69-
let error = (any Error).self
69+
let error = (any Error).self
7070
#else
71-
let error = Never.self
71+
#if canImport(FoundationEssentials)
72+
let error = Never.self
73+
#else
74+
let error = (any Error).self
75+
#endif
7276
#endif
7377
#expect(throws: error) {
7478
try JSONDecoder().decode(TestEvent.self, from: json.data(using: .utf8)!)

0 commit comments

Comments
 (0)