From 5a3d958c9093d5c03cab6e2f220fc9789739708b Mon Sep 17 00:00:00 2001 From: Junxiao Shi Date: Tue, 3 Dec 2024 03:05:13 +0000 Subject: [PATCH] util: asUint8Array test case with SharedArrayBuffer Change %j to $prop in test case names. --- pkg/keychain/tests/key/signing.t.ts | 8 ++++---- pkg/naming-convention1/tests/mod.t.ts | 2 +- pkg/ndncert/tests/server-client.t.ts | 2 +- pkg/packet/tests/digest-comp.t.ts | 2 +- pkg/packet/tests/signing.t.ts | 6 +++--- pkg/repo/tests/endpoint-producer.t.ts | 4 ++-- pkg/trust-schema/tests/hierarchical.t.ts | 16 ++++++++-------- pkg/util/tests/buffer.t.ts | 10 ++++++---- 8 files changed, 26 insertions(+), 24 deletions(-) diff --git a/pkg/keychain/tests/key/signing.t.ts b/pkg/keychain/tests/key/signing.t.ts index 7855ea06..145ec6b9 100644 --- a/pkg/keychain/tests/key/signing.t.ts +++ b/pkg/keychain/tests/key/signing.t.ts @@ -9,7 +9,7 @@ import { describe, expect, test } from "vitest"; import { Certificate, createVerifier, EcCurve, ECDSA, Ed25519, generateSigningKey, HMAC, KeyChain, RSA, RsaModulusLength, SigningAlgorithmListFull } from "../.."; describe.each(EcCurve.Choices)("ECDSA %s", (curve) => { - test.each(TestSignVerify.PacketTable)("sign-verify %j", async ({ Packet }) => { + test.each(TestSignVerify.PacketTable)("sign-verify $PacketType", async ({ Packet }) => { const [pvtA, pubA] = await generateSigningKey("/A/KEY/x", ECDSA, { curve }); const [pvtB, pubB] = await generateSigningKey("/B/KEY/x", ECDSA, { curve }); @@ -48,7 +48,7 @@ describe.each(EcCurve.Choices)("ECDSA %s", (curve) => { }); describe.each(RsaModulusLength.Choices)("RSA %d", (modulusLength) => { - describe.each(TestSignVerify.PacketTable)("sign-verify %j", ({ Packet }) => { + describe.each(TestSignVerify.PacketTable)("sign-verify $PacketType", ({ Packet }) => { test("", { timeout: 15000 }, async () => { const [pvtA, pubA] = await generateSigningKey("/A/KEY/x", RSA, { modulusLength }); const [pvtB, pubB] = await generateSigningKey("/B/KEY/x", RSA, { modulusLength }); @@ -77,7 +77,7 @@ describe.each(RsaModulusLength.Choices)("RSA %d", (modulusLength) => { }); describe("HMAC", () => { - test.each(TestSignVerify.PacketTable)("sign-verify %j", async ({ Packet }) => { + test.each(TestSignVerify.PacketTable)("sign-verify $PacketType", async ({ Packet }) => { const [pvtA, pubA] = await generateSigningKey("/A/KEY/x", HMAC); const [pvtB, pubB] = await generateSigningKey("/B/KEY/x", HMAC); @@ -111,7 +111,7 @@ print(pkt.hex()) */ describe("Ed25519", () => { - test.each(TestSignVerify.PacketTable)("sign-verify %j", async ({ Packet }) => { + test.each(TestSignVerify.PacketTable)("sign-verify $PacketType", async ({ Packet }) => { const [pvtA, pubA] = await generateSigningKey("/A/KEY/x", Ed25519); const [pvtB, pubB] = await generateSigningKey("/B/KEY/x", Ed25519); diff --git a/pkg/naming-convention1/tests/mod.t.ts b/pkg/naming-convention1/tests/mod.t.ts index bedcf112..05f5e345 100644 --- a/pkg/naming-convention1/tests/mod.t.ts +++ b/pkg/naming-convention1/tests/mod.t.ts @@ -33,7 +33,7 @@ const TABLE: Row[] = [ }, ]; -test.each(TABLE)("%j", ({ marker, convention }) => { +test.each(TABLE)("marker $marker", ({ marker, convention }) => { const markerHex = marker.toString(16).padStart(2, "0"); const name = new Name().append(convention, 0x00010203).append(convention, 0x0405n); expect(name.at(0)).toEqualComponent(`%${markerHex}%00%01%02%03`); diff --git a/pkg/ndncert/tests/server-client.t.ts b/pkg/ndncert/tests/server-client.t.ts index 7ed08386..d4e07dc3 100644 --- a/pkg/ndncert/tests/server-client.t.ts +++ b/pkg/ndncert/tests/server-client.t.ts @@ -423,7 +423,7 @@ test("probe entries and redirects", async () => { checkCaProfile(retrieved, subProfile, "sub_CA"); }); -test.each(TABLE)("challenge %j", async ({ +test.each(TABLE)("challenge $summary", async ({ makeChallengeLists, clientShouldFail = false, }) => { diff --git a/pkg/packet/tests/digest-comp.t.ts b/pkg/packet/tests/digest-comp.t.ts index e387fa01..5b793fcd 100644 --- a/pkg/packet/tests/digest-comp.t.ts +++ b/pkg/packet/tests/digest-comp.t.ts @@ -15,7 +15,7 @@ const TABLE = [ { CompType: ParamsDigest, tt: TT.ParametersSha256DigestComponent, altUriPrefix: "params-sha256" }, ] as Row[]; -test.each(TABLE)("DigestComp %j", ({ CompType, tt, altUriPrefix }) => { +test.each(TABLE)("DigestComp $tt", ({ CompType, tt, altUriPrefix }) => { expect(NamingConvention.isConvention(CompType)).toBeTruthy(); const digest = new Uint8Array(32); diff --git a/pkg/packet/tests/signing.t.ts b/pkg/packet/tests/signing.t.ts index 7244a123..92814099 100644 --- a/pkg/packet/tests/signing.t.ts +++ b/pkg/packet/tests/signing.t.ts @@ -98,7 +98,7 @@ const TABLE = [ }, ] as Row[]; -test.each(TABLE)("sign %j", async ({ Packet }) => { +test.each(TABLE)("sign $pkt", async ({ Packet }) => { const pkt = new Packet(new Name("/A")); pkt.sigInfo = new SigInfo(SigType.HmacWithSha256, Uint8Array.of(0xA0, 0xA1)); await expect(ALGO1.sign(pkt)).rejects.toThrow(/mock-signing-error/); @@ -107,7 +107,7 @@ test.each(TABLE)("sign %j", async ({ Packet }) => { expect(() => Encoder.encode(pkt)).not.toThrow(); }); -test.each(TABLE)("verify %j", async ({ Packet, checkWire }) => { +test.each(TABLE)("verify $pkt", async ({ Packet, checkWire }) => { const src = new Packet(new Name("/A")); src.sigInfo = new SigInfo(SigType.Sha256); await ALGO0.sign(src); @@ -136,7 +136,7 @@ test("digestSigning simple", async () => { await expect(digestSigning.verify(data)).rejects.toThrow(); }); -test.each(TestSignVerify.PacketTable)("digestSigning %j", async ({ Packet }) => { +test.each(TestSignVerify.PacketTable)("digestSigning $PacketType", async ({ Packet }) => { const record = await TestSignVerify.execute(Packet, digestSigning, digestSigning, digestSigning, digestSigning); TestSignVerify.check(record, { deterministic: true, sameAB: true }); }); diff --git a/pkg/repo/tests/endpoint-producer.t.ts b/pkg/repo/tests/endpoint-producer.t.ts index bc9af7ab..65ed1753 100644 --- a/pkg/repo/tests/endpoint-producer.t.ts +++ b/pkg/repo/tests/endpoint-producer.t.ts @@ -1,6 +1,6 @@ import "@ndn/packet/test-fixture/expect"; -import { consume, DataStoreBuffer, produce, type Producer, type ProducerHandler, type ProducerOptions } from "@ndn/endpoint"; +import { consume, DataStoreBuffer, produce, type Producer, type ProducerOptions } from "@ndn/endpoint"; import { Forwarder } from "@ndn/fw"; import { generateSigningKey } from "@ndn/keychain"; import { Data, Interest } from "@ndn/packet"; @@ -54,7 +54,7 @@ test("prefill buffer", async () => { expect(handler).toHaveBeenCalledTimes(1); }); -test.each([false, true])("autoBuffer %j", async (autoBuffer) => { +test.each([false, true])("autoBuffer %o", async (autoBuffer) => { const pOpts = await makeBufferedProducer(undefined, { autoBuffer }); const handler = vi.fn(async (interest: Interest, { dataBuffer }: Producer) => { void interest; diff --git a/pkg/trust-schema/tests/hierarchical.t.ts b/pkg/trust-schema/tests/hierarchical.t.ts index 00fc822f..f4849e74 100644 --- a/pkg/trust-schema/tests/hierarchical.t.ts +++ b/pkg/trust-schema/tests/hierarchical.t.ts @@ -176,7 +176,7 @@ const TABLE: Row[] = [ describe("success", () => { let ctx: Context; beforeAll(async () => { ctx = await Context.create({}); }); - test.each(TABLE)("%j", async (row) => { + test.each(TABLE)("$summary", async (row) => { await ctx.testSigner(row, async (signer, data) => { await signer.sign(data); if (row.signerMustLpm ?? true) { @@ -198,7 +198,7 @@ describe("success same name", () => { name2: "/root/site/group", }); }); - test.each(TABLE)("%j", async (row) => { + test.each(TABLE)("$summary", async (row) => { await ctx.testVerifier(row, async (verifier, data) => { await verifier.verify(data); }); @@ -212,7 +212,7 @@ describe("data non-hierarchical", () => { dataName: "/data", }); }); - test.each(TABLE)("%j", async (row) => { + test.each(TABLE)("$summary", async (row) => { await ctx.testSigner(row, async (signer, data) => { await expect(signer.sign(data)).rejects.toThrow(); }); @@ -229,7 +229,7 @@ describe("cert non-hierarchical", () => { name1: "/root/other-site", }); }); - test.each(TABLE)("%j", async (row) => { + test.each(TABLE)("$summary", async (row) => { await ctx.testVerifier(row, async (verifier, data) => { await expect(verifier.verify(data)).rejects.toThrow(); }); @@ -248,7 +248,7 @@ describe("bad signature", () => { }, }); }); - test.each(TABLE)("%j", async (row) => { + test.each(TABLE)("$summary", async (row) => { await ctx.testVerifier(row, async (verifier, data) => { await expect(verifier.verify(data)).rejects.toThrow(/bad/); }); @@ -265,7 +265,7 @@ describe("root expired", () => { }, }); }); - test.each(TABLE)("%j", async (row) => { + test.each(TABLE)("$summary", async (row) => { await ctx.testVerifier(row, async (verifier, data) => { await expect(verifier.verify(data)).rejects.toThrow(/expired/); }); @@ -282,7 +282,7 @@ describe("cert expired", () => { }, }); }); - test.each(TABLE)("%j", async (row) => { + test.each(TABLE)("$summary", async (row) => { await ctx.testVerifier(row, async (verifier, data) => { await expect(verifier.verify(data)).rejects.toThrow(/expired/); }); @@ -299,7 +299,7 @@ describe("no KeyLocator", () => { } }); }); - test.each(TABLE)("%j", async (row) => { + test.each(TABLE)("$summary", async (row) => { await ctx.testVerifier(row, async (verifier, data) => { await expect(verifier.verify(data)).rejects.toThrow(/KeyLocator/); }); diff --git a/pkg/util/tests/buffer.t.ts b/pkg/util/tests/buffer.t.ts index 17f58a53..a5d8a632 100644 --- a/pkg/util/tests/buffer.t.ts +++ b/pkg/util/tests/buffer.t.ts @@ -3,10 +3,12 @@ import { expect, test } from "vitest"; import { asDataView, asUint8Array } from ".."; test.each([ - { title: "asUint8Array", T: Uint8Array, f: asUint8Array }, - { title: "asDataView", T: DataView, f: asDataView }, -])("asArrayBufferView %j", ({ T, f }) => { - const ab = new ArrayBuffer(17); + { B: ArrayBuffer, T: Uint8Array, f: asUint8Array }, + { B: SharedArrayBuffer, T: Uint8Array, f: asUint8Array }, + { B: ArrayBuffer, T: DataView, f: asDataView }, + { B: SharedArrayBuffer, T: DataView, f: asDataView }, +])("$f $B", ({ B, T, f }) => { + const ab = new B(17); const u8 = new Uint8Array(ab, 4, 11); const dv = new DataView(ab, 3, 8);