Skip to content

Commit

Permalink
Dropped back down to XCtest for CI
Browse files Browse the repository at this point in the history
  • Loading branch information
donnywals committed Nov 28, 2024
1 parent 7d68848 commit 1b0b754
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 89 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/transloaditkit-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ jobs:
name: Swift ${{ matrix.swift }} on ${{ matrix.os }}
strategy:
matrix:
os: ["macOS-15"]
swift: ["6.0"]
os: ["macos-latest"]
swift: ["5.10"]
runs-on: ${{ matrix.os }}
steps:
- name: Extract Branch Name
Expand Down
176 changes: 89 additions & 87 deletions Tests/TransloaditKitTests/SessionCopyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,94 +5,96 @@
// Created by Donny Wals on 28/11/2024.
//

import Testing
import XCTest
import Foundation
@testable import TransloaditKit

let expectedTUSClientConfigIdentifier = "com.transloadit.tus.bg"
let expectedTransloaditConfigIdentifier = "com.transloadit.bg"
let transloaditConfigIdentifierForTesting = "com.transloadit.bg1"

@Test("Default session should not use an identifier when copying")
func defaultSessionIgnoresIdentifierWhenCopyingSession() async throws {
let session = URLSessionConfiguration.default
#expect(session.identifier == nil)
let copy = session.copy(withIdentifier: "testIdentifier")
#expect(copy.identifier == nil)
}

@Test("Background session should use an identifier when copying")
func backgroundSessionUsesIdentifierWhenCopyingSession() async throws {
let session = URLSessionConfiguration.background(withIdentifier: transloaditConfigIdentifierForTesting)
#expect(session.identifier == transloaditConfigIdentifierForTesting)
let copy = session.copy(withIdentifier: "com.transloadit.bg2")
#expect(copy.identifier == "com.transloadit.bg2")
}

@Test("TransloaditKit should use provided configuration")
func transloaditKitShouldUseProvidedConfig() async throws {
let config = URLSessionConfiguration.background(withIdentifier: transloaditConfigIdentifierForTesting)
let transloadit = Transloadit(
credentials: .init(key: "", secret: ""),
sessionConfiguration: config)
#expect(transloadit.api.configuration.identifier == transloaditConfigIdentifierForTesting)
}

@Test("TransloaditKit should make config copy when given a background URLSession")
func transloaditKitShouldMakeConfigCopyForBackgroundURLSession() async throws {
let config = URLSessionConfiguration.background(withIdentifier: transloaditConfigIdentifierForTesting)
let session = URLSession(configuration: config)
let transloadit = Transloadit(
credentials: .init(key: "", secret: ""),
session: session)
#expect(transloadit.api.configuration.identifier == expectedTransloaditConfigIdentifier)
}

@Test("TUSClient should be given its own background configuration")
func tusClientShouldMakeSessionCopy() async throws {
let config = URLSessionConfiguration.background(withIdentifier: transloaditConfigIdentifierForTesting)
let transloadit = Transloadit(
credentials: .init(key: "", secret: ""),
sessionConfiguration: config)
#expect(transloadit.tusSessionConfig.identifier == expectedTUSClientConfigIdentifier)
}

@Test("TUSClient and TransloaditKit should have unique session configuration identifiers when providing a config")
func tusAndTransloaditHaveUniqueIdentifiersWhenProvidingConfiguration() async throws {
let config = URLSessionConfiguration.background(withIdentifier: transloaditConfigIdentifierForTesting)
let transloadit = Transloadit(
credentials: .init(key: "", secret: ""),
sessionConfiguration: config)
#expect(transloadit.tusSessionConfig.identifier == expectedTUSClientConfigIdentifier)
#expect(transloadit.api.configuration.identifier == transloaditConfigIdentifierForTesting)
}

@Test("TUSClient and TransloaditKit should have unique session configuration identifiers when providing a session")
func tusAndTransloaditHaveUniqueIdentifiersWhenProvidingSession() async throws {
let config = URLSessionConfiguration.background(withIdentifier: transloaditConfigIdentifierForTesting)
let transloadit = Transloadit(
credentials: .init(key: "", secret: ""),
session: URLSession(configuration: config))
#expect(transloadit.tusSessionConfig.identifier == expectedTUSClientConfigIdentifier)
#expect(transloadit.api.configuration.identifier == expectedTransloaditConfigIdentifier)
}

@Test("Checking session configurations should report correctly for background config")
func transloaditReportsCorrectSessionTypesBGConfig() async throws {
let config = URLSessionConfiguration.background(withIdentifier: transloaditConfigIdentifierForTesting)
let transloadit = Transloadit(
credentials: .init(key: "", secret: ""),
sessionConfiguration: config)
#expect(transloadit.isUsingBackgroundConfiguration.transloadit)
#expect(transloadit.isUsingBackgroundConfiguration.tus)
}

@Test("Checking session configurations should report correctly for default config")
func transloaditReportsCorrectSessionTypesDefaultConfig() async throws {
let config = URLSessionConfiguration.default
let transloadit = Transloadit(
credentials: .init(key: "", secret: ""),
sessionConfiguration: config)
#expect(!transloadit.isUsingBackgroundConfiguration.transloadit)
#expect(!transloadit.isUsingBackgroundConfiguration.tus)
class SessionCopyTests: XCTestCase {
let expectedTUSClientConfigIdentifier = "com.transloadit.tus.bg"
let expectedTransloaditConfigIdentifier = "com.transloadit.bg"
let transloaditConfigIdentifierForTesting = "com.transloadit.bg1"

// @Test("Default session should not use an identifier when copying")
func test_defaultSessionIgnoresIdentifierWhenCopyingSession() async throws {
let session = URLSessionConfiguration.default
XCTAssert(session.identifier == nil)
let copy = session.copy(withIdentifier: "testIdentifier")
XCTAssert(copy.identifier == nil)
}

// @Test("Background session should use an identifier when copying")
func test_backgroundSessionUsesIdentifierWhenCopyingSession() async throws {
let session = URLSessionConfiguration.background(withIdentifier: transloaditConfigIdentifierForTesting)
XCTAssert(session.identifier == transloaditConfigIdentifierForTesting)
let copy = session.copy(withIdentifier: "com.transloadit.bg2")
XCTAssert(copy.identifier == "com.transloadit.bg2")
}

// @Test("TransloaditKit should use provided configuration")
func test_transloaditKitShouldUseProvidedConfig() async throws {
let config = URLSessionConfiguration.background(withIdentifier: transloaditConfigIdentifierForTesting)
let transloadit = Transloadit(
credentials: .init(key: "", secret: ""),
sessionConfiguration: config)
XCTAssert(transloadit.api.configuration.identifier == transloaditConfigIdentifierForTesting)
}

// @Test("TransloaditKit should make config copy when given a background URLSession")
func test_transloaditKitShouldMakeConfigCopyForBackgroundURLSession() async throws {
let config = URLSessionConfiguration.background(withIdentifier: transloaditConfigIdentifierForTesting)
let session = URLSession(configuration: config)
let transloadit = Transloadit(
credentials: .init(key: "", secret: ""),
session: session)
XCTAssert(transloadit.api.configuration.identifier == expectedTransloaditConfigIdentifier)
}

// @Test("TUSClient should be given its own background configuration")
func test_tusClientShouldMakeSessionCopy() async throws {
let config = URLSessionConfiguration.background(withIdentifier: transloaditConfigIdentifierForTesting)
let transloadit = Transloadit(
credentials: .init(key: "", secret: ""),
sessionConfiguration: config)
XCTAssert(transloadit.tusSessionConfig.identifier == expectedTUSClientConfigIdentifier)
}

// @Test("TUSClient and TransloaditKit should have unique session configuration identifiers when providing a config")
func test_tusAndTransloaditHaveUniqueIdentifiersWhenProvidingConfiguration() async throws {
let config = URLSessionConfiguration.background(withIdentifier: transloaditConfigIdentifierForTesting)
let transloadit = Transloadit(
credentials: .init(key: "", secret: ""),
sessionConfiguration: config)
XCTAssert(transloadit.tusSessionConfig.identifier == expectedTUSClientConfigIdentifier)
XCTAssert(transloadit.api.configuration.identifier == transloaditConfigIdentifierForTesting)
}

// @Test("TUSClient and TransloaditKit should have unique session configuration identifiers when providing a session")
func test_tusAndTransloaditHaveUniqueIdentifiersWhenProvidingSession() async throws {
let config = URLSessionConfiguration.background(withIdentifier: transloaditConfigIdentifierForTesting)
let transloadit = Transloadit(
credentials: .init(key: "", secret: ""),
session: URLSession(configuration: config))
XCTAssert(transloadit.tusSessionConfig.identifier == expectedTUSClientConfigIdentifier)
XCTAssert(transloadit.api.configuration.identifier == expectedTransloaditConfigIdentifier)
}

// @Test("Checking session configurations should report correctly for background config")
func test_transloaditReportsCorrectSessionTypesBGConfig() async throws {
let config = URLSessionConfiguration.background(withIdentifier: transloaditConfigIdentifierForTesting)
let transloadit = Transloadit(
credentials: .init(key: "", secret: ""),
sessionConfiguration: config)
XCTAssert(transloadit.isUsingBackgroundConfiguration.transloadit)
XCTAssert(transloadit.isUsingBackgroundConfiguration.tus)
}

// @Test("Checking session configurations should report correctly for default config")
func test_transloaditReportsCorrectSessionTypesDefaultConfig() async throws {
let config = URLSessionConfiguration.default
let transloadit = Transloadit(
credentials: .init(key: "", secret: ""),
sessionConfiguration: config)
XCTAssert(!transloadit.isUsingBackgroundConfiguration.transloadit)
XCTAssert(!transloadit.isUsingBackgroundConfiguration.tus)
}
}

0 comments on commit 1b0b754

Please sign in to comment.