Skip to content

Commit

Permalink
chore: run connect and echo on all key types, muxers and encrypters
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Jan 25, 2024
1 parent 1b29ee0 commit 3214458
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 41 deletions.
25 changes: 4 additions & 21 deletions src/connect.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,13 @@
import { expect } from 'aegir/chai'
import { keys } from './resources/keys/index.js'
import type { Daemon, NodeType, SpawnOptions, DaemonFactory, PeerIdType, Encryption } from './index.js'
import { runTests } from './utils/test-matrix.js'
import type { Daemon, SpawnOptions, DaemonFactory } from './index.js'

export function connectTests (factory: DaemonFactory): void {
const keyTypes: PeerIdType[] = ['ed25519', 'rsa', 'secp256k1']
const impls: NodeType[] = ['js', 'go']
const encrypters: Encryption[] = ['noise', 'tls']

for (const keyType of keyTypes) {
for (const implA of impls) {
for (const implB of impls) {
for (const encrypter of encrypters) {
runConnectTests(
`${encrypter}/${keyType}`,
factory,
{ type: implA, encryption: encrypter, key: keys.go[keyType] },
{ type: implB, encryption: encrypter, key: keys.js[keyType] }
)
}
}
}
}
runTests('connect', runConnectTests, factory)
}

function runConnectTests (name: string, factory: DaemonFactory, optionsA: SpawnOptions, optionsB: SpawnOptions): void {
describe(`connect using ${name}`, () => {
describe(name, () => {
let daemonA: Daemon
let daemonB: Daemon

Expand Down
21 changes: 3 additions & 18 deletions src/streams/echo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,10 @@ import all from 'it-all'
import { pipe } from 'it-pipe'
import defer from 'p-defer'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import type { Daemon, DaemonFactory, Muxer, NodeType, SpawnOptions } from '../index.js'
import type { Daemon, DaemonFactory, SpawnOptions } from '../index.js'

export function echoStreamTests (factory: DaemonFactory, muxer: Muxer): void {
const nodeTypes: NodeType[] = ['js', 'go']

for (const typeA of nodeTypes) {
for (const typeB of nodeTypes) {
runEchoStreamTests(
factory,
muxer,
{ type: typeA, muxer },
{ type: typeB, muxer }
)
}
}
}

function runEchoStreamTests (factory: DaemonFactory, muxer: Muxer, optionsA: SpawnOptions, optionsB: SpawnOptions): void {
describe(`echo streams - ${muxer}`, () => {
export function echoStreamTests (name: string, factory: DaemonFactory, optionsA: SpawnOptions, optionsB: SpawnOptions): void {
describe(name, () => {
let daemonA: Daemon
let daemonB: Daemon

Expand Down
4 changes: 2 additions & 2 deletions src/streams/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { runTests } from '../utils/test-matrix.js'
import { echoStreamTests } from './echo.js'
import type { DaemonFactory } from '../index.js'

export async function streamTests (factory: DaemonFactory): Promise<void> {
echoStreamTests(factory, 'mplex')
echoStreamTests(factory, 'yamux')
runTests('echo', echoStreamTests, factory)
}
31 changes: 31 additions & 0 deletions src/utils/test-matrix.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { keys } from '../resources/keys/index.js'
import type { DaemonFactory, Encryption, Muxer, NodeType, PeerIdType, SpawnOptions } from '../index.js'

export interface TestFunction {
(name: string, factory: DaemonFactory, optionsA: SpawnOptions, optionsB: SpawnOptions): void
}

export function runTests (name: string, fn: TestFunction, factory: DaemonFactory): void {
const keyTypes: PeerIdType[] = ['ed25519', 'rsa', 'secp256k1']
const impls: NodeType[] = ['js', 'go']
const encrypters: Encryption[] = ['noise', 'tls']
const muxers: Muxer[] = ['mplex', 'yamux']

for (const keyType of keyTypes) {
for (const implA of impls) {
for (const implB of impls) {
for (const encrypter of encrypters) {
// eslint-disable-next-line max-depth
for (const muxer of muxers) {
fn(
`${keyType}/${encrypter}/${muxer} ${name}`,
factory,
{ type: implA, encryption: encrypter, key: keys.go[keyType] },
{ type: implB, encryption: encrypter, key: keys.js[keyType] }
)
}
}
}
}
}
}

0 comments on commit 3214458

Please sign in to comment.