Skip to content

Commit

Permalink
Merge pull request #63 from noppoMan/improve-s3-test-coverage
Browse files Browse the repository at this point in the history
Improve s3 test coverage
  • Loading branch information
noppoMan authored Nov 17, 2017
2 parents 6c87123 + f8d94c2 commit a675b7a
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 28 deletions.
17 changes: 13 additions & 4 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/noppoMan/aws-sdk-swift-core.git",
"state": {
"branch": null,
"revision": "20855789974c8de565626ca2f9f4b147eb60aeef",
"version": "1.0.3"
"revision": "4adb01cf6cac6471783477e1ec8330dbf96ebce1",
"version": "1.0.5"
}
},
{
Expand Down Expand Up @@ -42,8 +42,17 @@
"repositoryURL": "https://github.com/noppoMan/Prorsum.git",
"state": {
"branch": null,
"revision": "6f2558056fb887a84331c5da7d6ac4211bc16187",
"version": "0.1.16"
"revision": "4e5af67f5eb24ef050b38913ce5804071adfdf47",
"version": "0.3.0"
}
},
{
"package": "ProrsumNet",
"repositoryURL": "https://github.com/noppoman/ProrsumNet.git",
"state": {
"branch": null,
"revision": "627eb273db4c37791aacd78ae8aef4da30f95bcb",
"version": "0.1.2"
}
},
{
Expand Down
89 changes: 65 additions & 24 deletions Tests/AWSSDKSwiftTests/Services/S3/S3Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ import Foundation
import Dispatch
import XCTest
@testable import AWSSDKSwift
@testable import AWSSDKSwiftCore

class S3Tests: XCTestCase {
static var allTests : [(String, (S3Tests) -> () throws -> Void)] {
return [
("testPutObject", testPutObject),
]

struct TestData {
static let shared = TestData()
let bucket = "aws-sdk-swift-test-bucket"
let bodyData = "hello world".data(using: .utf8)!
let key = "hello.txt"
}

var client: S3 {
Expand All @@ -26,28 +29,66 @@ class S3Tests: XCTestCase {
endpoint: "http://localhost:4569"
)
}

override func setUp() {
let bucketRequest = S3.CreateBucketRequest(bucket: TestData.shared.bucket)
_ = try? client.createBucket(bucketRequest)
}

var bucket: String {
return "aws-sdk-swift-test-bucket"
override func tearDown() {
let deleteRequest = S3.DeleteObjectRequest(bucket: TestData.shared.bucket, key: TestData.shared.key)
_ = try? client.deleteObject(deleteRequest)
}

override func setUp() {
do {
let bucketRequest = S3.CreateBucketRequest(bucket: bucket)
_ = try client.createBucket(bucketRequest)
} catch {
print(error)
}
}

func testPutObject() {
do {
let bodyData = "hello world".data(using: .utf8)!
let putRequest = S3.PutObjectRequest(bucket: bucket, contentLength: Int64(bodyData.count), key: "hello.txt", body: bodyData, acl: .publicRead)
let output = try client.putObject(putRequest)
XCTAssert(output.eTag != nil)
} catch {
XCTFail("\(error)")
}
func testPutObject() throws {
let putRequest = S3.PutObjectRequest(
bucket: TestData.shared.bucket,
contentLength: Int64(TestData.shared.bodyData.count),
key: TestData.shared.key,
body: TestData.shared.bodyData,
acl: .publicRead)

let output = try client.putObject(putRequest)
XCTAssertNotNil(output.eTag)
}


func testGetObject() throws {
let putRequest = S3.PutObjectRequest(
bucket: TestData.shared.bucket,
contentLength: Int64(TestData.shared.bodyData.count),
key: TestData.shared.key,
body: TestData.shared.bodyData,
acl: .publicRead)

_ = try client.putObject(putRequest)
let object = try client.getObject(S3.GetObjectRequest(bucket: TestData.shared.bucket, key: "hello.txt"))
XCTAssertEqual(object.body, TestData.shared.bodyData)
}

func testListObjects() throws {
let putRequest = S3.PutObjectRequest(
bucket: TestData.shared.bucket,
contentLength: Int64(TestData.shared.bodyData.count),
key: TestData.shared.key,
body: TestData.shared.bodyData,
acl: .publicRead)

let putResult = try client.putObject(putRequest)

let output = try client.listObjects(S3.ListObjectsRequest(bucket: TestData.shared.bucket))
XCTAssertEqual(output.maxKeys, 1000)
XCTAssertEqual(output.contents?.first?.key, TestData.shared.key)
XCTAssertEqual(output.contents?.first?.size, Int32(TestData.shared.bodyData.count))
XCTAssertEqual(output.contents?.first?.eTag, putResult.eTag?.replacingOccurrences(of: "\"", with: ""))
}


static var allTests : [(String, (S3Tests) -> () throws -> Void)] {
return [
("testPutObject", testPutObject),
("testListObjects", testListObjects),
("testGetObject", testGetObject),
]
}
}

0 comments on commit a675b7a

Please sign in to comment.