Skip to content

Commit

Permalink
Merge branch 'main' into jbe/fix_modifiedContext_compile_warning
Browse files Browse the repository at this point in the history
  • Loading branch information
jbelkins committed Jun 21, 2023
2 parents f4c67cf + 4702133 commit e5601f0
Show file tree
Hide file tree
Showing 897 changed files with 409,966 additions and 551,478 deletions.
3 changes: 3 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ disabled_rules:
- syntactic_sugar
- unused_capture_list
- nesting
- operator_whitespace
- large_tuple

opt_in_rules:
Expand All @@ -32,6 +33,8 @@ empty_enum_arguments: error
function_body_length:
warning: 100
error: 150
generic_type_name:
max_length: 48
identifier_name:
excluded:
- id
Expand Down
88 changes: 88 additions & 0 deletions IntegrationTests/Services/AWSS3IntegrationTests/S3ErrorTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import XCTest
import AWSS3
import AWSClientRuntime

class S3ErrorTests: S3XCTestCase {

func test_noSuchKey_throwsNoSuchKeyWhenUnknownKeyIsUsed() async throws {
do {
let input = GetObjectInput(bucket: bucketName, key: UUID().uuidString)
_ = try await client.getObject(input: input)
XCTFail("Request should not have succeeded")
} catch let error as NoSuchKey {
XCTAssertEqual(error.httpResponse.statusCode, .notFound)
XCTAssertEqual(error.message, "The specified key does not exist.")
} catch {
XCTFail("Unexpected error thrown: \(error)")
}
}

func test_noSuchBucket_throwsNoSuchBucketWhenUnknownBucketIsUsed() async throws {
do {
let input = ListObjectsV2Input(bucket: bucketName + "x")
_ = try await client.listObjectsV2(input: input)
XCTFail("Request should not have succeeded")
} catch let error as NoSuchBucket {
XCTAssertEqual(error.httpResponse.statusCode, .notFound)
XCTAssertEqual(error.message, "The specified bucket does not exist")
} catch {
XCTFail("Unexpected error thrown: \(error)")
}
}

func test_requestID_hasARequestIDAndRequestID2() async throws {
do {
let input = GetObjectInput(bucket: bucketName, key: UUID().uuidString)
_ = try await client.getObject(input: input)
XCTFail("Request should not have succeeded")
} catch let error as NoSuchKey {
let requestID = try XCTUnwrap(error.requestID)
let requestID2 = try XCTUnwrap(error.requestID2)
XCTAssertFalse(requestID.isEmpty)
XCTAssertFalse(requestID2.isEmpty)
} catch {
XCTFail("Unexpected error thrown: \(error)")
}
}

func test_InvalidObjectState_hasReadableProperties() async throws {
do {
let key = UUID().uuidString + ".txt"
let putInput = PutObjectInput(bucket: bucketName, key: key, storageClass: .glacier)
_ = try await client.putObject(input: putInput)
let getInput = GetObjectInput(bucket: bucketName, key: key)
_ = try await client.getObject(input: getInput)
XCTFail("Request should not have succeeded")
} catch let error as InvalidObjectState {
XCTAssertEqual(error.properties.accessTier, nil)
XCTAssertEqual(error.properties.storageClass, .glacier)
XCTAssertEqual(error.message, "The operation is not valid for the object\'s storage class")
} catch {
XCTFail("Unexpected error thrown: \(error)")
}
}

func test_InvalidAccessKeyID_isThrownWhenAppropriate() async throws {
do {
let credentials = Credentials(accessKey: "AKIDEXAMPLE", secret: "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY")
let credentialsProvider = try StaticCredentialsProvider(credentials)
let config = try S3Client.S3ClientConfiguration(region: region, credentialsProvider: credentialsProvider)
let input = GetObjectInput(bucket: bucketName, key: UUID().uuidString)
_ = try await S3Client(config: config).getObject(input: input)
XCTFail("Request should not have succeeded")
} catch let error as InvalidAccessKeyId {
XCTAssertEqual(error.httpResponse.statusCode, .forbidden)
XCTAssertEqual(error.message, "The AWS Access Key Id you provided does not exist in our records.")
} catch {
XCTFail("Unexpected error thrown: \(error)")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class S3URLEncodingTests: S3XCTestCase {
let config = try await S3Client.S3ClientConfiguration(region: region)
for key in keys {
let input = PutObjectInput(body: .data(Data()), bucket: bucketName, key: key)
let presignedURLOrNil = try await input.presignURL(config: config, expiration: 600.0)
let presignedURLOrNil = try await input.presignURL(config: config, expiration: 30.0)
let presignedURL = try XCTUnwrap(presignedURLOrNil)
var urlRequest = URLRequest(url: presignedURL)
urlRequest.httpMethod = "PUT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import AWSS3
class S3XCTestCase: XCTestCase {
static var client: S3Client!
static let region = "us-west-2"
static let bucketName = "aws-sdk-s3-integration-test-\(UUID().uuidString.split(separator: "-").first!.lowercased())"
var client: S3Client { Self.client }
var region: String { Self.region }
var bucketName: String { Self.bucketName }
var bucketName: String!

struct HTTPError: Error, CustomDebugStringConvertible {
let code: Int
Expand All @@ -36,14 +35,15 @@ class S3XCTestCase: XCTestCase {
}

override func setUp() async throws{
self.bucketName = "aws-sdk-s3-integration-test-\(UUID().uuidString.split(separator: "-").first!.lowercased())"
Self.client = try S3Client(region: region)
try await Self.createBucket()
try await Self.createBucket(bucketName: bucketName)
}

/// Empty & delete the test bucket before each test.
override func tearDown() async throws {
try await emptyBucket()
try await Self.deleteBucket()
try await Self.deleteBucket(bucketName: bucketName)
}

// MARK: Helpers
Expand All @@ -70,7 +70,7 @@ class S3XCTestCase: XCTestCase {
}
}

static func createBucket() async throws {
static func createBucket(bucketName: String) async throws {
let input = CreateBucketInput(bucket: bucketName, createBucketConfiguration: S3ClientTypes.CreateBucketConfiguration(locationConstraint: S3ClientTypes.BucketLocationConstraint.usWest2))
_ = try await Self.client.createBucket(input: input)
}
Expand Down Expand Up @@ -107,7 +107,7 @@ class S3XCTestCase: XCTestCase {
}
}

static func deleteBucket() async throws {
static func deleteBucket(bucketName: String) async throws {
let input = DeleteBucketInput(bucket: bucketName)
_ = try await client.deleteBucket(input: input)
}
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func addProtocolTests() {
// MARK: - Generated

addDependencies(
clientRuntimeVersion: "0.20.0",
clientRuntimeVersion: "0.21.0",
crtVersion: "0.12.0"
)

Expand Down
2 changes: 1 addition & 1 deletion Package.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.17.0
0.18.0
Loading

0 comments on commit e5601f0

Please sign in to comment.