Skip to content

Commit

Permalink
CONFIG: Skip integration tests if TMDb API Key is missing (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamayoung authored Aug 31, 2023
1 parent 14e24cd commit 0c0b14b
Show file tree
Hide file tree
Showing 16 changed files with 80 additions and 61 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cache SPM
uses: actions/cache@v3
with:
path: ~/Library/Developer/Xcode/DerivedData/TMDb-*/SourcePackages
key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
restore-keys: |
${{ runner.os }}-spm-
- name: Build
run: xcodebuild build-for-testing -scheme TMDb -only-testing TMDbTests -destination '${{ matrix.destination }}'
Expand All @@ -68,11 +76,17 @@ jobs:
build-test-linux:
name: Build and Test (Linux)
runs-on: ubuntu-latest
container:
image: swift:5.8.1-focal
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cache SPM
uses: actions/cache@v3
with:
path: .build
key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
restore-keys: |
${{ runner.os }}-spm-
- name: Build
run: swift build -Xswiftc -warnings-as-errors --build-tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ final class CertificationIntegrationTests: XCTestCase {

var certificationService: CertificationService!

override func setUp() {
super.setUp()
TMDb.configure(TMDbConfiguration(apiKey: tmdbAPIKey))
override func setUpWithError() throws {
try super.setUpWithError()
try configureTMDb()
certificationService = CertificationService()
}

Expand Down
6 changes: 3 additions & 3 deletions Tests/TMDbIntegrationTests/CompanyIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ final class CompanyIntegrationTests: XCTestCase {

var companyService: CompanyService!

override func setUp() {
super.setUp()
TMDb.configure(TMDbConfiguration(apiKey: tmdbAPIKey))
override func setUpWithError() throws {
try super.setUpWithError()
try configureTMDb()
companyService = CompanyService()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ final class ConfigurationIntegrationTests: XCTestCase {

var configurationService: ConfigurationService!

override func setUp() {
super.setUp()
TMDb.configure(TMDbConfiguration(apiKey: tmdbAPIKey))
override func setUpWithError() throws {
try super.setUpWithError()
try configureTMDb()
configurationService = ConfigurationService()
}

Expand Down
6 changes: 3 additions & 3 deletions Tests/TMDbIntegrationTests/DiscoverIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ final class DiscoverIntegrationTests: XCTestCase {

var discoverService: DiscoverService!

override func setUp() {
super.setUp()
TMDb.configure(TMDbConfiguration(apiKey: tmdbAPIKey))
override func setUpWithError() throws {
try super.setUpWithError()
try configureTMDb()
discoverService = DiscoverService()
}

Expand Down
20 changes: 0 additions & 20 deletions Tests/TMDbIntegrationTests/Extensions/XCTestCase+Environment.swift

This file was deleted.

6 changes: 3 additions & 3 deletions Tests/TMDbIntegrationTests/GenreIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ final class GenreIntegrationTests: XCTestCase {

var genreService: GenreService!

override func setUp() {
super.setUp()
TMDb.configure(TMDbConfiguration(apiKey: tmdbAPIKey))
override func setUpWithError() throws {
try super.setUpWithError()
try configureTMDb()
genreService = GenreService()
}

Expand Down
6 changes: 3 additions & 3 deletions Tests/TMDbIntegrationTests/MovieIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ final class MovieIntegrationTests: XCTestCase {

var movieService: MovieService!

override func setUp() {
super.setUp()
TMDb.configure(TMDbConfiguration(apiKey: tmdbAPIKey))
override func setUpWithError() throws {
try super.setUpWithError()
try configureTMDb()
movieService = MovieService()
}

Expand Down
6 changes: 3 additions & 3 deletions Tests/TMDbIntegrationTests/PersonIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ final class PersonIntegrationTests: XCTestCase {

var personService: PersonService!

override func setUp() {
super.setUp()
TMDb.configure(TMDbConfiguration(apiKey: tmdbAPIKey))
override func setUpWithError() throws {
try super.setUpWithError()
try configureTMDb()
personService = PersonService()
}

Expand Down
6 changes: 3 additions & 3 deletions Tests/TMDbIntegrationTests/SearchIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ final class SearchIntegrationTests: XCTestCase {

var searchService: SearchService!

override func setUp() {
super.setUp()
TMDb.configure(TMDbConfiguration(apiKey: tmdbAPIKey))
override func setUpWithError() throws {
try super.setUpWithError()
try configureTMDb()
searchService = SearchService()
}

Expand Down
6 changes: 3 additions & 3 deletions Tests/TMDbIntegrationTests/TVShowEpisodeServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ final class TVShowEpisodeServiceTests: XCTestCase {

var tvShowEpisodeService: TVShowEpisodeService!

override func setUp() {
super.setUp()
TMDb.configure(TMDbConfiguration(apiKey: tmdbAPIKey))
override func setUpWithError() throws {
try super.setUpWithError()
try configureTMDb()
tvShowEpisodeService = TVShowEpisodeService()
}

Expand Down
6 changes: 3 additions & 3 deletions Tests/TMDbIntegrationTests/TVShowSeasonService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ final class TVShowSeasonServiceTests: XCTestCase {

var tvShowSeasonService: TVShowSeasonService!

override func setUp() {
super.setUp()
TMDb.configure(TMDbConfiguration(apiKey: tmdbAPIKey))
override func setUpWithError() throws {
try super.setUpWithError()
try configureTMDb()
tvShowSeasonService = TVShowSeasonService()
}

Expand Down
6 changes: 3 additions & 3 deletions Tests/TMDbIntegrationTests/TVShowServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ final class TVShowServiceTests: XCTestCase {

var tvShowService: TVShowService!

override func setUp() {
super.setUp()
TMDb.configure(TMDbConfiguration(apiKey: tmdbAPIKey))
override func setUpWithError() throws {
try super.setUpWithError()
try configureTMDb()
tvShowService = TVShowService()
}

Expand Down
6 changes: 3 additions & 3 deletions Tests/TMDbIntegrationTests/TrendingIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ final class TrendingIntegrationTests: XCTestCase {

var trendingService: TrendingService!

override func setUp() {
super.setUp()
TMDb.configure(TMDbConfiguration(apiKey: tmdbAPIKey))
override func setUpWithError() throws {
try super.setUpWithError()
try configureTMDb()
trendingService = TrendingService()
}

Expand Down
25 changes: 25 additions & 0 deletions Tests/TMDbIntegrationTests/Utility/XCTestCase+ConfigureTMDb.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import TMDb
import XCTest

extension XCTestCase {

func configureTMDb() throws {
try TMDb.configure(TMDbConfiguration(apiKey: tmdbAPIKey()))
}

private func tmdbAPIKey() throws -> String {
try Self.tmdbAPIKey()
}

private static func tmdbAPIKey() throws -> String {
guard
let apiKey = ProcessInfo.processInfo.environment["TMDB_API_KEY"],
!apiKey.isEmpty
else {
throw XCTSkip("TMDB_API_KEY environment variable not set.")
}

return apiKey
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ final class WatchProviderIntegrationTests: XCTestCase {

var watchProviderService: WatchProviderService!

override func setUp() {
super.setUp()
TMDb.configure(TMDbConfiguration(apiKey: tmdbAPIKey))
override func setUpWithError() throws {
try super.setUpWithError()
try configureTMDb()
watchProviderService = WatchProviderService()
}

Expand Down

0 comments on commit 0c0b14b

Please sign in to comment.