Skip to content

Commit 69bf350

Browse files
committed
feat: implemented secrets in tests
1 parent cc58842 commit 69bf350

7 files changed

Lines changed: 69 additions & 10 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,6 @@ fastlane/test_output
8888
# https://github.com/johnno1962/injectionforxcode
8989

9090
iOSInjectionProject/
91+
92+
# Secrets
93+
secrets.json

Package.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ let package = Package(
3737
),
3838
.testTarget(
3939
name: "SQLiteCloudTests",
40-
dependencies: ["SQLiteCloud"]
40+
dependencies: ["SQLiteCloud"],
41+
exclude: ["Secrets/secrets.json.sample"],
42+
resources: [
43+
.copy("Secrets/secrets.json")
44+
]
4145
),
4246
]
4347
)

Tests/SQLiteCloudTests/Integrations/SQLiteCloudTests+Blob.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ final class SQLiteCloudTests_Blob: XCTestCase {
3636
private var firstRandomData: Data = .empty
3737

3838
override func setUp() async throws {
39-
hostname = ProcessInfo.processInfo.environment["SQ_LITE_CLOUD_HOST"] ?? .empty
40-
username = ProcessInfo.processInfo.environment["SQ_LITE_CLOUD_USER"] ?? .empty
41-
password = ProcessInfo.processInfo.environment["SQ_LITE_CLOUD_PASS"] ?? .empty
39+
let secrets = try Secrets.load()
40+
hostname = secrets.hostname
41+
username = secrets.username
42+
password = secrets.password
4243

4344
let config = SQLiteCloudConfig(hostname: hostname, username: username, password: password)
4445
cloud = SQLiteCloud(config: config)

Tests/SQLiteCloudTests/Integrations/SQLiteCloudTests+Connection.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ final class SQLiteCloudTests_Connection: XCTestCase {
3232
private var password: String = .empty
3333

3434
override func setUpWithError() throws {
35-
hostname = ProcessInfo.processInfo.environment["SQ_LITE_CLOUD_HOST"] ?? .empty
36-
username = ProcessInfo.processInfo.environment["SQ_LITE_CLOUD_USER"] ?? .empty
37-
password = ProcessInfo.processInfo.environment["SQ_LITE_CLOUD_PASS"] ?? .empty
35+
let secrets = try Secrets.load()
36+
hostname = secrets.hostname
37+
username = secrets.username
38+
password = secrets.password
3839
}
3940

4041
func test_connect_withValidCredentials_shouldConnectWithoutError() async throws {

Tests/SQLiteCloudTests/Integrations/SQLiteCloudTests+Execution.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ final class SQLiteCloudTests_Execute: XCTestCase {
3232
private var password: String = .empty
3333

3434
override func setUpWithError() throws {
35-
hostname = ProcessInfo.processInfo.environment["SQ_LITE_CLOUD_HOST"] ?? .empty
36-
username = ProcessInfo.processInfo.environment["SQ_LITE_CLOUD_USER"] ?? .empty
37-
password = ProcessInfo.processInfo.environment["SQ_LITE_CLOUD_PASS"] ?? .empty
35+
let secrets = try Secrets.load()
36+
hostname = secrets.hostname
37+
username = secrets.username
38+
password = secrets.password
3839
}
3940

4041
func test_execute_withValidConnection_shouldReturnValidResult() async throws {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//
2+
// SQLiteCloud
3+
//
4+
// Created by Massimo Oliviero.
5+
//
6+
// Copyright (c) 2023 SQLite Cloud, Inc. (https://sqlitecloud.io/)
7+
//
8+
// Permission is hereby granted, free of charge, to any person obtaining a copy
9+
// of this software and associated documentation files (the "Software"), to deal
10+
// in the Software without restriction, including without limitation the rights
11+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
// copies of the Software, and to permit persons to whom the Software is
13+
// furnished to do so, subject to the following conditions:
14+
//
15+
// The above copyright notice and this permission notice shall be included in
16+
// all copies or substantial portions of the Software.
17+
//
18+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
// THE SOFTWARE.
25+
26+
import Foundation
27+
28+
struct Secrets: Decodable {
29+
let hostname: String
30+
let username: String
31+
let password: String
32+
}
33+
34+
extension Secrets {
35+
static func load() throws -> Self {
36+
let secretsFileUrl = Bundle.module.url(forResource: "secrets", withExtension: "json")
37+
38+
guard let secretsFileUrl = secretsFileUrl, let secretsFileData = try? Data(contentsOf: secretsFileUrl) else {
39+
fatalError("No `secrets.json` file found. Make sure to duplicate `secrets.json.sample` and remove the `.sample` extension.")
40+
}
41+
42+
return try JSONDecoder().decode(Self.self, from: secretsFileData)
43+
}
44+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"hostname": "<your host>",
3+
"username": "<your user>",
4+
"password": "<your pass>"
5+
}

0 commit comments

Comments
 (0)