test: support algorithm contract in linked worktrees
This commit is contained in:
@@ -40,7 +40,7 @@ class JsAlgorithmContractTest {
|
|||||||
assertThat(stream).as("run tools/export-js-contracts.js first").isNotNull();
|
assertThat(stream).as("run tools/export-js-contracts.js first").isNotNull();
|
||||||
JsonNode root = mapper.readTree(stream);
|
JsonNode root = mapper.readTree(stream);
|
||||||
assertThat(root.path("sourceAlgorithmVersion").asText()).isEqualTo("1.2.0");
|
assertThat(root.path("sourceAlgorithmVersion").asText()).isEqualTo("1.2.0");
|
||||||
Path source = Path.of("..", "..", "..", "ft546-storage-scheduling-algorithm.js");
|
Path source = findSourceAlgorithm();
|
||||||
assertThat(root.path("sourceSha256").asText()).isEqualTo(sha256(Files.readAllBytes(source)));
|
assertThat(root.path("sourceSha256").asText()).isEqualTo(sha256(Files.readAllBytes(source)));
|
||||||
assertThat(root.path("fixtures")).hasSize(4);
|
assertThat(root.path("fixtures")).hasSize(4);
|
||||||
for (JsonNode fixture : root.path("fixtures")) {
|
for (JsonNode fixture : root.path("fixtures")) {
|
||||||
@@ -134,4 +134,17 @@ class JsAlgorithmContractTest {
|
|||||||
private String sha256(byte[] value) throws Exception {
|
private String sha256(byte[] value) throws Exception {
|
||||||
return HexFormat.of().formatHex(MessageDigest.getInstance("SHA-256").digest(value));
|
return HexFormat.of().formatHex(MessageDigest.getInstance("SHA-256").digest(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Path findSourceAlgorithm() {
|
||||||
|
Path directory = Path.of("").toAbsolutePath();
|
||||||
|
while (directory != null) {
|
||||||
|
Path candidate = directory.resolve("ft546-storage-scheduling-algorithm.js");
|
||||||
|
if (Files.isRegularFile(candidate)) {
|
||||||
|
return candidate;
|
||||||
|
}
|
||||||
|
directory = directory.getParent();
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("Cannot find ft546-storage-scheduling-algorithm.js above "
|
||||||
|
+ Path.of("").toAbsolutePath());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user