diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index 3b1954b..b3b165f 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -5,16 +5,28 @@ name: SPM Build and Test on: push: - branches: [ "feature/unit-test" ] + branches: [ "feature/unit-test", "main", "release/*"] pull_request: - branches: [ "feature/unit-test" ] + branches: [ "feature/unit-test", "main", "release/*" ] jobs: build: runs-on: macos-latest + strategy: + matrix: + platform: [ ios ] steps: - - uses: actions/checkout@v4 + + - name: Clean DerivedData + run: rm -rf ~/Library/Developer/Xcode/DerivedData + + - name: Checkout code + uses: actions/checkout@v4 + + - name: Generate Folder Structure + run: bash generate_folder_structure.sh + - name: Build and run tests - run: xcodebuild test -scheme PlaybackSDK -destination 'platform=iOS Simulator,name=iPhone 13' + run: xcodebuild test -scheme PlaybackSDK -destination 'platform=iOS Simulator,name=iPhone 15,OS=17.4' diff --git a/Package.swift b/Package.swift index 74145a4..edb1cc2 100644 --- a/Package.swift +++ b/Package.swift @@ -43,6 +43,11 @@ let package = Package( ), .testTarget( name: "PlaybackSDKTests", - dependencies: ["PlaybackSDK"]), + dependencies: ["PlaybackSDK"], + exclude: ["Folder Structure.md"], // Exclude non-Swift test files if needed + swiftSettings: [ + // Set the swift settings specifically for iOS platform + .define("iOS_TEST", .when(platforms: [.iOS])), + ]), ] ) diff --git a/Tests/PlaybackSDKTests/Folder Structure.md b/Tests/PlaybackSDKTests/Folder Structure.md new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Tests/PlaybackSDKTests/Folder Structure.md @@ -0,0 +1 @@ + diff --git a/Tests/PlaybackSDKTests/PlayBackSDKManagerTests.swift.swift b/Tests/PlaybackSDKTests/PlayBackSDKManagerTests.swift similarity index 66% rename from Tests/PlaybackSDKTests/PlayBackSDKManagerTests.swift.swift rename to Tests/PlaybackSDKTests/PlayBackSDKManagerTests.swift index 9652f90..6ab902c 100644 --- a/Tests/PlaybackSDKTests/PlayBackSDKManagerTests.swift.swift +++ b/Tests/PlaybackSDKTests/PlayBackSDKManagerTests.swift @@ -34,6 +34,23 @@ class PlayBackSDKManagerTests: XCTestCase { func testInitialization() throws { XCTAssertNotNil(manager, "Manager should not be nil after initialization") } + + func testInitializeWithCustomUserAgent() { + let expectation = expectation(description: "Initialization expectation") + + manager.initialize(apiKey: apiKey, userAgent: "IOS Tests") { result in + switch result { + case .success(let license): + XCTAssertNotNil(license, "Bitmovin license should not be nil") + XCTAssertFalse(license.isEmpty, "Bitmovin license should not be empty") + expectation.fulfill() + case .failure(let error): + XCTFail("Initialization failed with error: \(error.localizedDescription)") + } + } + + waitForExpectations(timeout: 5, handler: nil) + } func testInitializeWithValidAPIKey() { let expectation = expectation(description: "Initialization expectation") @@ -94,6 +111,37 @@ class PlayBackSDKManagerTests: XCTestCase { waitForExpectations(timeout: 5, handler: nil) } + func testFailedEntryId() { + let initializationExpectation = expectation(description: "SDK initialization") + manager.initialize(apiKey: apiKey) { result in + switch result { + case .success: + initializationExpectation.fulfill() + case .failure(let error): + XCTFail("SDK initialization failed with error: \(error.localizedDescription)") + } + } + waitForExpectations(timeout: 5, handler: nil) + + let hlsExpectation = expectation(description: "Empty entry id loading expectation") + manager.loadHLSStream(forEntryId: "", andAuthorizationToken: nil) { result in + switch result { + case .success(let hlsURL): + XCTFail("Empty entry id provided but got HLS stream") + case .failure(let error): + switch error { + case .networkError(_): + hlsExpectation.fulfill() + default: + hlsExpectation.fulfill() + } + + } + } + + waitForExpectations(timeout: 5, handler: nil) + } + func testLoadPlayer() { let playerView = manager.loadPlayer(entryID: "exampleEntryID", authorizationToken: "exampleToken", onError: { _ in }) // Assert that playerView is not nil or do further UI testing if possible diff --git a/Tests/PlaybackSDKTests/TestConfig.swift b/Tests/PlaybackSDKTests/TestConfig.swift index f956a42..7d5e217 100644 --- a/Tests/PlaybackSDKTests/TestConfig.swift +++ b/Tests/PlaybackSDKTests/TestConfig.swift @@ -8,6 +8,6 @@ import Foundation internal struct TestConfig { - static let testAPIKey = "f3Beljhmlz2ea7M9TfErE6mKPsAcY3BrasMMEG24" - static let testEntryID = "0_k3mz0mf8" + static let testAPIKey = "EJEZPIezBkaf0EQ7ey5Iu2MDA2ARUkgc79eyDOnG" + static let testEntryID = "0_qt9cy11s" } diff --git a/generate_folder_structure.sh b/generate_folder_structure.sh new file mode 100644 index 0000000..fe43922 --- /dev/null +++ b/generate_folder_structure.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Determine the current working directory +CURRENT_DIR=$(pwd) + +# Create the Folder Structure.md file in the specified directory +mkdir -p "$CURRENT_DIR/Tests/PlaybackSDKTests" +echo "# Folder Structure" > "$CURRENT_DIR/Tests/PlaybackSDKTests/Folder Structure.md" +echo "" >> "$CURRENT_DIR/Tests/PlaybackSDKTests/Folder Structure.md" +echo "This file represents the folder structure of the project." >> "$CURRENT_DIR/Tests/PlaybackSDKTests/Folder Structure.md" +echo "You can update it with the actual structure if needed." >> "$CURRENT_DIR/Tests/PlaybackSDKTests/Folder Structure.md" + +echo "Folder Structure.md generated successfully in $CURRENT_DIR/Tests/PlaybackSDKTests"