|
| 1 | +// |
| 2 | +// PluginMetadataRegistrySystemNameAdoptionTests.swift |
| 3 | +// TableProTests |
| 4 | +// |
| 5 | +// A plugin's own snapshot replaces the curated entry when it loads, so a published plugin that lists fewer system |
| 6 | +// names than the app, or none, took them away. No plugin loads under XCTest, so these build the plugin's snapshot |
| 7 | +// from the curated one the way a published plugin would report it. |
| 8 | +// |
| 9 | + |
| 10 | +import Foundation |
| 11 | +@testable import TablePro |
| 12 | +import TableProPluginKit |
| 13 | +import Testing |
| 14 | + |
| 15 | +@Suite("PluginMetadataRegistry system name adoption") |
| 16 | +struct PluginMetadataRegistrySystemNameAdoptionTests { |
| 17 | + private func curated(_ typeId: String) -> PluginMetadataSnapshot? { |
| 18 | + PluginMetadataRegistry.shared.snapshot(forRegisteredTypeId: typeId) |
| 19 | + } |
| 20 | + |
| 21 | + @Test("A published Oracle plugin that lists no system schemas keeps the app's") |
| 22 | + func emptyPluginSchemaListKeepsCuratedSchemas() { |
| 23 | + guard let oracle = curated("Oracle") else { |
| 24 | + Issue.record("Registry default for Oracle missing") |
| 25 | + return |
| 26 | + } |
| 27 | + var published = oracle.withSystemNames( |
| 28 | + databases: ["SYS", "SYSTEM", "OUTLN", "DBSNMP", "APPQOSSYS", "WMSYS", "XDB"], |
| 29 | + schemas: [] |
| 30 | + ) |
| 31 | + |
| 32 | + PluginMetadataRegistry.adoptCuratedSystemNames(&published, registryDefault: oracle) |
| 33 | + |
| 34 | + #expect(published.schema.systemSchemaNames == oracle.schema.systemSchemaNames) |
| 35 | + #expect(Set(published.schema.systemDatabaseNames) == Set(oracle.schema.systemDatabaseNames)) |
| 36 | + } |
| 37 | + |
| 38 | + @Test("A name either side lists counts, the plugin's names first and none twice") |
| 39 | + func namesAreUnitedInOrder() { |
| 40 | + guard let base = curated("Dameng") else { |
| 41 | + Issue.record("Registry default for Dameng missing") |
| 42 | + return |
| 43 | + } |
| 44 | + var plugin = base.withSystemNames(databases: ["b", "a"], schemas: ["S1"]) |
| 45 | + let registryDefault = base.withSystemNames(databases: ["a", "c"], schemas: ["S2", "S1"]) |
| 46 | + |
| 47 | + PluginMetadataRegistry.adoptCuratedSystemNames(&plugin, registryDefault: registryDefault) |
| 48 | + |
| 49 | + #expect(plugin.schema.systemDatabaseNames == ["b", "a", "c"]) |
| 50 | + #expect(plugin.schema.systemSchemaNames == ["S1", "S2"]) |
| 51 | + } |
| 52 | + |
| 53 | + @Test("A plugin that already lists every curated name is left as it reported") |
| 54 | + func completePluginListIsUnchanged() { |
| 55 | + guard let base = curated("Dameng") else { |
| 56 | + Issue.record("Registry default for Dameng missing") |
| 57 | + return |
| 58 | + } |
| 59 | + var plugin = base.withSystemNames(databases: [], schemas: ["CTISYS", "SYS", "SYSAUDITOR", "SYSSSO", "SYSJOB", "SYSGEO2"]) |
| 60 | + |
| 61 | + PluginMetadataRegistry.adoptCuratedSystemNames(&plugin, registryDefault: base) |
| 62 | + |
| 63 | + #expect(plugin.schema.systemSchemaNames == ["CTISYS", "SYS", "SYSAUDITOR", "SYSSSO", "SYSJOB", "SYSGEO2"]) |
| 64 | + } |
| 65 | + |
| 66 | + /// Measured on Oracle AI Database 26ai Free: `ALL_USERS` reports these with `ORACLE_MAINTAINED = 'Y'`, and the |
| 67 | + /// administrator account a PDB is created with, `PDBADMIN`, with `N`. |
| 68 | + @Test("Oracle's own schemas are system schemas, and the accounts users create are not") |
| 69 | + func oracleMaintainedSchemasAreSystem() { |
| 70 | + let schemas = PluginMetadataRegistry.shared.snapshot(for: .oracle)?.schema.systemSchemaNames ?? [] |
| 71 | + for name in ["SYS", "SYSTEM", "XDB", "AUDSYS", "MDSYS", "CTXSYS", "GSMADMIN_INTERNAL", "XS$NULL"] { |
| 72 | + #expect(schemas.contains(name), "\(name) is Oracle-maintained") |
| 73 | + } |
| 74 | + for name in ["PDBADMIN", "OPS$ORACLE", "HR", "SCOTT"] { |
| 75 | + #expect(!schemas.contains(name), "\(name) is not Oracle-maintained") |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + @Test("Oracle names the same schemas whether it is asked for databases or schemas") |
| 80 | + func oracleListsAgree() { |
| 81 | + let schema = PluginMetadataRegistry.shared.snapshot(for: .oracle)?.schema |
| 82 | + #expect(schema?.systemDatabaseNames == schema?.systemSchemaNames) |
| 83 | + } |
| 84 | +} |
0 commit comments