Skip to content

Commit 131b7a0

Browse files
committed
Add tests to demo
1 parent 367a00d commit 131b7a0

File tree

8 files changed

+71
-104
lines changed

8 files changed

+71
-104
lines changed

Demos/SwiftEncryptionDemo/SwiftEncryptionDemo.xcodeproj/project.pbxproj

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@
4545
path = SwiftEncryptionDemoTests;
4646
sourceTree = "<group>";
4747
};
48-
F410AD0D2F11330E003F542F /* SwiftEncryptionDemoUITests */ = {
49-
isa = PBXFileSystemSynchronizedRootGroup;
50-
path = SwiftEncryptionDemoUITests;
51-
sourceTree = "<group>";
52-
};
5348
/* End PBXFileSystemSynchronizedRootGroup section */
5449

5550
/* Begin PBXFrameworksBuildPhase section */
@@ -84,7 +79,6 @@
8479
children = (
8580
F410ACF52F11330D003F542F /* SwiftEncryptionDemo */,
8681
F410AD032F11330E003F542F /* SwiftEncryptionDemoTests */,
87-
F410AD0D2F11330E003F542F /* SwiftEncryptionDemoUITests */,
8882
F410AD232F11353E003F542F /* Frameworks */,
8983
F410ACF42F11330D003F542F /* Products */,
9084
);
@@ -170,9 +164,6 @@
170164
dependencies = (
171165
F410AD0C2F11330E003F542F /* PBXTargetDependency */,
172166
);
173-
fileSystemSynchronizedGroups = (
174-
F410AD0D2F11330E003F542F /* SwiftEncryptionDemoUITests */,
175-
);
176167
name = SwiftEncryptionDemoUITests;
177168
packageProductDependencies = (
178169
);

Demos/SwiftEncryptionDemo/SwiftEncryptionDemo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demos/SwiftEncryptionDemo/SwiftEncryptionDemo/SwiftEncryptionDemoApp.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
//
2-
// SwiftEncryptionDemoApp.swift
3-
// SwiftEncryptionDemo
4-
//
5-
// Created by Simon Binder on 09.01.26.
6-
//
7-
81
import SwiftUI
92

103
@main
Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,64 @@
1-
//
2-
// SwiftEncryptionDemoTests.swift
3-
// SwiftEncryptionDemoTests
4-
//
5-
// Created by Simon Binder on 09.01.26.
6-
//
7-
1+
@testable import PowerSync
82
import Testing
93

10-
struct SwiftEncryptionDemoTests {
11-
12-
@Test func example() async throws {
13-
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
4+
@Suite()
5+
struct EncryptionTests {
6+
@Test("SQLite3MultipleCiphers pragmas are available") @MainActor
7+
func linksSqlite3Mc() async throws {
8+
let database = PowerSyncDatabase(
9+
schema: Schema(),
10+
dbFilename: "linkSqlite3Mc",
11+
logger: DatabaseLogger(DefaultLogger())
12+
)
13+
14+
let cipher = try await database.get("pragma cipher", mapper: {cursor in
15+
try cursor.getString(index: 0)
16+
});
17+
18+
#expect(cipher == "chacha20")
19+
try await database.close(deleteDatabase: true)
1420
}
1521

22+
@Test("can encrypt databases") @MainActor
23+
func encryption() async throws {
24+
let database = PowerSyncDatabase(
25+
schema: Schema(tables: [
26+
Table(
27+
name: "users",
28+
columns: [
29+
.text("name")
30+
]
31+
),
32+
]),
33+
dbFilename: "encrypted.db",
34+
logger: DatabaseLogger(DefaultLogger()),
35+
initialStatements: [
36+
"pragma key = 'foobar'"
37+
],
38+
)
39+
40+
try await database.execute("INSERT INTO users (id, name) VALUES (uuid(), 'test')")
41+
try await database.close()
42+
43+
let another = PowerSyncDatabase(
44+
schema: Schema(tables: [
45+
Table(
46+
name: "users",
47+
columns: [
48+
.text("name")
49+
]
50+
),
51+
]),
52+
dbFilename: "encrypted.db",
53+
logger: DatabaseLogger(DefaultLogger()),
54+
initialStatements: [
55+
"pragma key = 'wrong password'",
56+
],
57+
)
58+
59+
await #expect(throws: (any Error).self) {
60+
try await another.execute("DELETE FROM users")
61+
}
62+
try await another.close(deleteDatabase: true)
63+
}
1664
}

Demos/SwiftEncryptionDemo/SwiftEncryptionDemoUITests/SwiftEncryptionDemoUITests.swift

Lines changed: 0 additions & 41 deletions
This file was deleted.

Demos/SwiftEncryptionDemo/SwiftEncryptionDemoUITests/SwiftEncryptionDemoUITestsLaunchTests.swift

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// Intentionally left empty, we only new a SwiftPM project for package traits
1+
// Intentionally left empty, we only need a SwiftPM project for package traits

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let packageName = "PowerSync"
77

88
// Set this to the absolute path of your Kotlin SDK checkout if you want to use a local Kotlin
99
// build. Also see docs/LocalBuild.md for details
10-
let localKotlinSdkOverride: String? = "/Users/simon/src/powersync-kotlin"
10+
let localKotlinSdkOverride: String? = nil
1111

1212
// Set this to the absolute path of your powersync-sqlite-core checkout if you want to use a
1313
// local build of the core extension.

0 commit comments

Comments
 (0)