@fatagnus/dink-test-utils
v2.9.1
Published
Shared test utilities for Dink examples and integration testing
Downloads
227
Maintainers
Readme
@fatagnus/dink-test-utils
Shared test utilities for Dink integration testing.
This package provides helper functions for setting up and tearing down dinkd containers in integration tests, as well as utilities for creating API keys.
Installation
npm install @fatagnus/dink-test-utils --save-devQuick Start
import { describe, beforeAll, afterAll } from 'vitest';
import {
startDinkdContainer,
stopDinkdContainer,
createTestKeys,
type DinkdTestContext,
} from '@fatagnus/dink-test-utils';
describe('My Integration Tests', () => {
let testContext: DinkdTestContext;
let edgeKeys: Map<string, string>;
let centerKey: string;
beforeAll(async () => {
// Start a dinkd container
testContext = await startDinkdContainer();
// Create API keys for testing
const keys = await createTestKeys(
testContext.serverUrl,
testContext.adminKey,
['edge-1', 'edge-2']
);
edgeKeys = keys.edgeKeys;
centerKey = keys.centerKey;
}, 180000); // Allow time for container startup
afterAll(async () => {
await stopDinkdContainer(testContext);
});
// Your tests here...
});API
Container Management
startDinkdContainer(options?)- Starts a dinkd Docker containerstopDinkdContainer(context)- Stops and cleans up the containerextractAdminKey(container, timeout?)- Extracts the admin key from container logs
Key Creation
createEdgeKey(serverUrl, adminKey, name)- Creates an edge API key (edge_id is auto-generated and embedded in the key)createCenterKey(serverUrl, adminKey, name)- Creates a center API keycreateClientKey(serverUrl, adminKey, name)- Creates a client API keycreateKeyWithScopes(serverUrl, adminKey, name, type, options)- Creates a key with custom scopescreateTestKeys(serverUrl, adminKey, edgeNames)- Creates multiple edge keys + shared center key (edge_ids are embedded in keys)createTestKeyPairs(serverUrl, adminKey, edgeNames)- Creates edge/center key pairs
App Management
createApp(serverUrl, adminKey, name, description?)- Creates a new application
Key Management
revokeKey(serverUrl, adminKey, keyId, reason?)- Revokes an API keygetKeyInfo(serverUrl, adminKey, keyId)- Gets information about a keylistKeys(serverUrl, adminKey)- Lists all keys
Requirements
- Node.js >= 18.0.0
- Docker (for running dinkd containers)
- The
dinkd:latestDocker image
License
MIT
