Skip to content

Commit 730c993

Browse files
Merge pull request #3714 from SwiftPackageIndex/issue-3655-swift-testing-part-28
Issue 3655 swift testing part 28
2 parents f379cd2 + b6f6487 commit 730c993

File tree

4 files changed

+40
-42
lines changed

4 files changed

+40
-42
lines changed

Tests/AuthenticationTests/APIKeyTests.swift

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,32 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import XCTest
16-
1715
@testable import Authentication
1816

1917
import JWTKit
18+
import Testing
2019

2120

22-
final class APIKeyTests: XCTestCase {
21+
@Suite struct APIKeyTests {
2322

24-
func test_verify() throws {
23+
@Test func verify() throws {
2524
// Ensure verification rejects expired tokens
2625
let s = Signer(secretSigningKey: "secret")
2726
let token = try s.generateToken(for: "foo", expiringOn: .distantPast, contact: "bar", tier: .tier1)
2827
do {
2928
_ = try s.verifyToken(token)
30-
XCTFail("Expected a JWTError.claimVerificationFailure to the thrown")
29+
Issue.record("Expected a JWTError.claimVerificationFailure to the thrown")
3130
} catch let JWTError.claimVerificationFailure(name: name, reason: reason) {
32-
XCTAssertEqual(name, "exp")
33-
XCTAssertEqual(reason, "expired")
31+
#expect(name == "exp")
32+
#expect(reason == "expired")
3433
}
3534
}
3635

37-
func test_isAuthorized() throws {
38-
XCTAssertTrue(APIKey.mock(tier: .internal).isAuthorized(for: .tier1))
39-
XCTAssertTrue(APIKey.mock(tier: .internal).isAuthorized(for: .tier2))
40-
XCTAssertTrue(APIKey.mock(tier: .tier1).isAuthorized(for: .tier1))
41-
XCTAssertFalse(APIKey.mock(tier: .tier1).isAuthorized(for: .tier2))
36+
@Test func isAuthorized() throws {
37+
#expect(APIKey.mock(tier: .internal).isAuthorized(for: .tier1))
38+
#expect(APIKey.mock(tier: .internal).isAuthorized(for: .tier2))
39+
#expect(APIKey.mock(tier: .tier1).isAuthorized(for: .tier1))
40+
#expect(!APIKey.mock(tier: .tier1).isAuthorized(for: .tier2))
4241
}
4342

4443
}

Tests/AuthenticationTests/SignerTests.swift

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,32 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import XCTest
16-
1715
@testable import Authentication
1816

1917
import JWTKit
18+
import Testing
2019

2120

22-
final class SignerTests: XCTestCase {
21+
@Suite struct SignerTests {
2322

24-
func test_generateToken_verifyToken() throws {
23+
@Test func generateToken_verifyToken() throws {
2524
// Round trip test
2625
let s = Signer(secretSigningKey: "secret")
2726
let token = try s.generateToken(for: "foo", contact: "bar", tier: .tier1)
28-
XCTAssertTrue(!token.isEmpty)
27+
#expect(!token.isEmpty)
2928
let key = try s.verifyToken(token)
30-
XCTAssertEqual(key.sub, .init(value: "foo"))
31-
XCTAssertEqual(key.contact, "bar")
32-
XCTAssertEqual(key.tier, .tier1)
29+
#expect(key.sub == .init(value: "foo"))
30+
#expect(key.contact == "bar")
31+
#expect(key.tier == .tier1)
3332
}
3433

35-
func test_verifyToken_failure() throws {
34+
@Test func verifyToken_failure() throws {
3635
// Ensure verification requires the correct secret
3736
let token = try Signer(secretSigningKey: "secret").generateToken(for: "foo", contact: "bar", tier: .tier1)
3837
let otherSigner = Signer(secretSigningKey: "other")
3938
do {
4039
_ = try otherSigner.verifyToken(token)
41-
XCTFail("Expected a JWTError.signatureVerifictionFailed to the thrown")
40+
Issue.record("Expected a JWTError.signatureVerifictionFailed to the thrown")
4241
} catch JWTError.signatureVerifictionFailed { }
4342
}
4443

Tests/AuthenticationTests/TierTests.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import XCTest
16-
1715
@testable import Authentication
1816

17+
import Testing
18+
1919

20-
final class TierTests: XCTestCase {
20+
@Suite struct TierTests {
2121

22-
func test_Comparable() throws {
23-
XCTAssertTrue(Tier<V1>.tier1 < Tier<V1>.tier2)
24-
XCTAssertTrue(Tier<V1>.tier2 < Tier<V1>.internal)
22+
@Test func Comparable() throws {
23+
#expect(Tier<V1>.tier1 < Tier<V1>.tier2)
24+
#expect(Tier<V1>.tier2 < Tier<V1>.internal)
2525

26-
XCTAssertFalse(Tier<V1>.tier1 > Tier<V1>.tier2)
26+
#expect(!(Tier<V1>.tier1 > Tier<V1>.tier2))
2727

28-
XCTAssertTrue(Tier<V1>.tier1 <= Tier<V1>.tier1)
29-
XCTAssertTrue(Tier<V1>.tier1 >= Tier<V1>.tier1)
28+
#expect(Tier<V1>.tier1 <= Tier<V1>.tier1)
29+
#expect(Tier<V1>.tier1 >= Tier<V1>.tier1)
3030
}
3131

3232
}

Tests/S3StoreTests/S3StoreTests.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,36 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import XCTest
16-
1715
@testable import S3Store
1816

17+
import Testing
18+
1919

20-
final class S3StoreTests: XCTestCase {
20+
@Suite struct S3StoreTests {
2121

22-
func test_Key_path() throws {
22+
@Test func Key_path() throws {
2323
do {
2424
let key = S3Store.Key(bucket: "bucket", path: "foo/bar")
25-
XCTAssertEqual(key.path, "foo/bar")
25+
#expect(key.path == "foo/bar")
2626
}
2727
do {
2828
let key = S3Store.Key(bucket: "bucket", path: "/foo/bar")
29-
XCTAssertEqual(key.path, "foo/bar")
29+
#expect(key.path == "foo/bar")
3030
}
3131
do {
3232
let key = S3Store.Key(bucket: "bucket", path: "//foo/bar")
33-
XCTAssertEqual(key.path, "foo/bar")
33+
#expect(key.path == "foo/bar")
3434
}
3535
}
3636

37-
func test_Key_objectUrl() throws {
37+
@Test func Key_objectUrl() throws {
3838
let key = S3Store.Key(bucket: "bucket", path: "foo/bar")
39-
XCTAssertEqual(key.objectUrl, "https://bucket.s3.us-east-2.amazonaws.com/foo/bar")
39+
#expect(key.objectUrl == "https://bucket.s3.us-east-2.amazonaws.com/foo/bar")
4040
}
4141

42-
func test_Key_s3Uri() throws {
42+
@Test func Key_s3Uri() throws {
4343
let key = S3Store.Key(bucket: "bucket", path: "foo/bar")
44-
XCTAssertEqual(key.s3Uri, "s3://bucket/foo/bar")
44+
#expect(key.s3Uri == "s3://bucket/foo/bar")
4545
}
4646

4747
}

0 commit comments

Comments
 (0)