Skip to content

Commit

Permalink
test: add a test for parsing compliance control paths
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesRudolph committed Oct 23, 2023
1 parent 767afdb commit 807e7ab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/compliance/ComplianceControlParser.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { assertEquals } from "std/testing/assert";
import { ComplianceControlParser } from "./ComplianceControlParser.ts";

Deno.test("parsing with POSIX paths", () => {
const path = "compliance/cfmm/iam/identity-lifecycle-management.md";
const result = ComplianceControlParser.toId(path);

assertEquals(result, "cfmm/iam/identity-lifecycle-management");
});

Deno.test("parsing with windows paths", () => {
const path = "compliance\\cfmm\\iam\\identity-lifecycle-management.md";
const result = ComplianceControlParser.toId(path);

assertEquals(result, "cfmm/iam/identity-lifecycle-management");
});
4 changes: 2 additions & 2 deletions src/compliance/ComplianceControlParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class ComplianceControlParser {

private async tryParseComplianceControl(mdPath: string) {
const relativeMdPath = this.repo.relativePath(mdPath);
const id = this.toId(relativeMdPath);
const id = ComplianceControlParser.toId(relativeMdPath);

this.logger.verbose(
() => `parsing compliance control ${id} via ${relativeMdPath}`,
Expand All @@ -88,7 +88,7 @@ export class ComplianceControlParser {
};
}

private toId(relativeControlPath: string) {
static toId(relativeControlPath: string) {
const posixPath = relativeControlPath.replaceAll("\\", "/");

const components = path.parse(posixPath);
Expand Down

0 comments on commit 807e7ab

Please sign in to comment.