Skip to content

Commit 9948ade

Browse files
committed
Add bare bone test for migration to 154 to 155
1 parent 43032c5 commit 9948ade

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import CoreData
2+
import Testing
3+
@testable import WordPressData
4+
5+
struct MigrationTests {
6+
7+
// See https://github.com/wordpress-mobile/WordPress-iOS/pull/24494#discussion_r2057152526
8+
@Test("Verify migration from version 154 (latest version before extraction to framework) to 155 (first version in framework with module modifications) works.")
9+
func migrate154to155() throws {
10+
let storeURL = FileManager.default.temporaryDirectory.appendingPathComponent("Migration154to155.sqlite")
11+
12+
let contextManager154 = ContextManager(
13+
modelName: "WordPress 154",
14+
store: storeURL
15+
)
16+
let context154 = contextManager154.newDerivedContext()
17+
let blog = BlogBuilder(context154)
18+
.build()
19+
contextManager154.saveContextAndWait(context154)
20+
21+
// Create a context manager for the 155 model, it will run the migration automatically
22+
let contextManager155 = ContextManager(
23+
modelName: "WordPress 155",
24+
store: storeURL
25+
)
26+
27+
// Check the blog is still there, just to exercise the model...
28+
let context155 = contextManager155.newDerivedContext()
29+
let request = Blog.fetchRequest()
30+
request.predicate = NSPredicate(format: "url == %@", blog.url!)
31+
let results = try context155.fetch(request)
32+
#expect(results.count == 1)
33+
#expect((results.first as? Blog)?.url == blog.url)
34+
}
35+
}

0 commit comments

Comments
 (0)