Skip to content

Commit

Permalink
Merge pull request #22 from StreamAMG/feature/ZEUS-4454-Fix-tests-for…
Browse files Browse the repository at this point in the history
…-PlaybackSDK-iOS

Feature/zeus 4454 fix tests for playback sdk i os
  • Loading branch information
KharchenkoAlex authored Jul 3, 2024
2 parents d54667d + 78fd2c6 commit a5e43fa
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 7 deletions.
20 changes: 16 additions & 4 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
7 changes: 6 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])),
]),
]
)
1 change: 1 addition & 0 deletions Tests/PlaybackSDKTests/Folder Structure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Tests/PlaybackSDKTests/TestConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
13 changes: 13 additions & 0 deletions generate_folder_structure.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit a5e43fa

Please sign in to comment.