Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for computeSchemaChecksum #3733

Merged
merged 13 commits into from
Jun 10, 2022
Merged
2 changes: 2 additions & 0 deletions common/api/core-backend.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2506,6 +2506,8 @@ export class IModelHost {
static tileUploader?: CloudStorageTileUploader;
// @internal
static get usingExternalTileCache(): boolean;
// @internal (undocumented)
static computeSchemaChecksum(arg: { schemaXmlPath: string, referencePaths: string[], exactMatch?: boolean }): string;
}

// @public
Expand Down
5 changes: 5 additions & 0 deletions core/backend/src/IModelHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,11 @@ export class IModelHost {
throw new IModelError(BentleyStatus.ERROR, "Cannot use both Azure and custom cloud storage providers for tile cache.");
}
}

/** @internal */
public static computeSchemaChecksum(arg: { schemaXmlPath: string, referencePaths: string[], exactMatch?: boolean }): string {
kabentley marked this conversation as resolved.
Show resolved Hide resolved
return this.platform.computeSchemaChecksum(arg);
}
}

/** Information about the platform on which the app is running. Also see [[KnownLocations]] and [[IModelJsFs]].
Expand Down
14 changes: 14 additions & 0 deletions core/backend/src/test/IModelHost.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { IModelHost, IModelHostConfiguration, KnownLocations } from "../IModelHo
import { Schemas } from "../Schema";
import { IModelTestUtils, TestUtils } from "./index";
import { AzureBlobStorage } from "../CloudStorageBackend";
import { KnownTestLocations } from "./KnownTestLocations";

describe("IModelHost", () => {

Expand Down Expand Up @@ -197,4 +198,17 @@ describe("IModelHost", () => {
expect(() => IModelHost.hubAccess).throws("IModelHost.hubAccess is undefined. Specify an implementation in your IModelHostConfiguration");
});

it("computeSchemaChecksum", () => {
const assetsDir = path.join(KnownTestLocations.assetsDir, "ECSchemaOps");
const schemaXmlPath = path.join(assetsDir, "SchemaA.ecschema.xml");
let referencePaths = [assetsDir];
let sha1 = IModelHost.computeSchemaChecksum({ schemaXmlPath, referencePaths });
expect(sha1).equal("3ac6578060902aa0b8426b61d62045fdf7fa0b2b");

expect(() => IModelHost.computeSchemaChecksum({ schemaXmlPath, referencePaths, exactMatch: true })).throws("Failed to read schema SchemaA.ecschema");

referencePaths = [path.join(assetsDir, "exact-match")];
sha1 = IModelHost.computeSchemaChecksum({ schemaXmlPath, referencePaths, exactMatch: true });
expect(sha1).equal("2a618664fbba1df7c05f27d7c0e8f58de250003b");
});
});
1 change: 0 additions & 1 deletion core/backend/src/test/TestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,3 @@ before(async () => {
after(async () => {
await TestUtils.shutdownBackend();
});

kabentley marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ECSchema schemaName="SchemaA" alias="a" version="1.1.1" xmlns="http://www.bentley.com/schemas/Bentley.ECXML.3.2" displayLabel="SchemaA" description="This is a test Schema.">
<ECSchemaReference name="SchemaC" version="3.3.3" alias="c"/>
<ECSchemaReference name="SchemaB" version="2.2.2" alias="b"/>
</ECSchema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ECSchema schemaName="SchemaB" alias="b" version="2.2.3" xmlns="http://www.bentley.com/schemas/Bentley.ECXML.3.2" displayLabel="SchemaB" description="This is a test Schema.">
<ECSchemaReference name="SchemaC" version="3.3.3" alias="c"/>
<ECSchemaReference name="SchemaD" version="4.4.4" alias="d"/>
</ECSchema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ECSchema schemaName="SchemaC" alias="c" version="3.3.4" xmlns="http://www.bentley.com/schemas/Bentley.ECXML.3.2" displayLabel="SchemaC" description="This is a test Schema.">
<ECSchemaReference name="SchemaD" version="4.4.4" alias="d"/>
</ECSchema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<ECSchema schemaName="SchemaD" alias="d" version="4.4.4" xmlns="http://www.bentley.com/schemas/Bentley.ECXML.3.2" displayLabel="SchemaD" description="This is a test Schema.">
</ECSchema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ECSchema schemaName="SchemaB" alias="b" version="2.2.2" xmlns="http://www.bentley.com/schemas/Bentley.ECXML.3.2" displayLabel="SchemaB" description="This is a test Schema.">
<ECSchemaReference name="SchemaC" version="3.3.3" alias="c"/>
<ECSchemaReference name="SchemaD" version="4.4.4" alias="d"/>
</ECSchema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ECSchema schemaName="SchemaC" alias="c" version="3.3.3" xmlns="http://www.bentley.com/schemas/Bentley.ECXML.3.2" displayLabel="SchemaC" description="This is a test Schema.">
<ECSchemaReference name="SchemaD" version="4.4.4" alias="d"/>
</ECSchema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<ECSchema schemaName="SchemaD" alias="d" version="4.4.4" xmlns="http://www.bentley.com/schemas/Bentley.ECXML.3.2" displayLabel="SchemaD" description="This is a test Schema.">
</ECSchema>