Skip to content

Commit fb71d95

Browse files
authored
Merge pull request #15 from HarperFast/tests/more-and-better-unit-tests
More and better unit tests
2 parents 7089fcf + 9084d1e commit fb71d95

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+16687
-77
lines changed

.github/workflows/unit-test.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,5 @@ jobs:
4343
- name: Build
4444
run: npm run build || true # we currently have type errors so just ignore that
4545

46-
- name: Setup Harper
47-
env:
48-
DEFAULTS_MODE: 'dev'
49-
HDB_ADMIN_USERNAME: 'admin'
50-
HDB_ADMIN_PASSWORD: 'password'
51-
ROOTPATH: '/tmp/hdb'
52-
NODE_HOSTNAME: 'localhost'
53-
run: node --enable-source-maps ./dist/bin/harperdb.js install
54-
5546
- name: Run tests
5647
run: npm run test:unit:all

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,7 @@ dist/
2929
!.env.example
3030

3131
# something is generating this file :shrug:
32-
integration-test.json
32+
integration-test.json
33+
34+
# test sandboxes
35+
unitTests/testEnv/

bin/copyDb.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { join } from 'path';
44
import { move, remove } from 'fs-extra';
55
import { get } from '../utility/environment/environmentManager.js';
66
import OpenEnvironmentObject from '../utility/lmdb/OpenEnvironmentObject.js';
7-
import { OpenDBIObject } from '../utility/lmdb/OpenDBIObject.js';
7+
import { OpenDBIObject } from '../utility/lmdb/OpenDBIObject.ts';
88
import { INTERNAL_DBIS_NAME, AUDIT_STORE_NAME } from '../utility/lmdb/terms.js';
99
import { CONFIG_PARAMS, DATABASES_DIR_NAME } from '../utility/hdbTerms.ts';
1010
import { AUDIT_STORE_OPTIONS } from '../resources/auditStore.ts';

config/RootConfigWatcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import chokidar, { FSWatcher } from 'chokidar';
22
import { readFile } from 'node:fs/promises';
33
import { getConfigFilePath } from './configUtils.js';
4-
import { EventEmitter, once } from 'node:stream';
4+
import { EventEmitter, once } from 'node:events';
55
import { parse } from 'yaml';
66

77
export class RootConfigWatcher extends EventEmitter {

dataLayer/harperBridge/ResourceBridge.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ import {
1212
} from '../../utility/hdbTerms.ts';
1313
import * as signalling from '../../utility/signalling.js';
1414
import { SchemaEventMsg } from '../../server/threads/itc.js';
15-
import { asyncSetTimeout } from '../../utility/common_utils.js';
15+
import { asyncSetTimeout, errorToString } from '../../utility/common_utils.js';
1616
import { transaction } from '../../resources/transaction.ts';
1717
import type { Condition, Query, Context, Select, Id, DirectCondition } from '../../resources/ResourceInterface.ts';
1818
import { collapseData } from '../../resources/tracked.ts';
19-
import { errorToString } from '../../utility/logging/harper_logger.js';
2019

2120
const { HDB_ERROR_MSGS } = hdbErrors;
2221
const DEFAULT_DATABASE = 'data';

dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetBackup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const { Readable } = require('stream');
44
const { getDatabases } = require('../../../../resources/databases.ts');
55
const { readSync, openSync, createReadStream } = require('fs');
66
const { open } = require('lmdb');
7-
const { OpenDBIObject } = require('../../../../utility/lmdb/OpenDBIObject.js');
7+
const { OpenDBIObject } = require('../../../../utility/lmdb/OpenDBIObject.ts');
88
const OpenEnvironmentObject = require('../../../../utility/lmdb/OpenEnvironmentObject.js');
99
const { AUDIT_STORE_OPTIONS } = require('../../../../resources/auditStore.ts');
1010
const { INTERNAL_DBIS_NAME, AUDIT_STORE_NAME } = require('../../../../utility/lmdb/terms.js');

resources/RecordEncoder.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
ACTION_32_BIT,
1818
} from './auditStore.ts';
1919
import * as harperLogger from '../utility/logging/harper_logger.js';
20-
import './blob.ts';
2120
import { blobsWereEncoded, decodeFromDatabase, deleteBlobsInObject, encodeBlobsWithFilePath } from './blob.ts';
2221
import { recordAction } from './analytics/write.ts';
2322
export type Entry = {
@@ -400,7 +399,7 @@ export function recordUpdater(store, tableId, auditStore) {
400399
// we use resolveRecord outside of transaction, so must explicitly make it conditional
401400
if (resolveRecord) putOptions.ifVersion = ifVersion = existingEntry?.version ?? null;
402401
if (existingEntry && existingEntry.value && type !== 'message' && existingEntry.metadataFlags & HAS_BLOBS) {
403-
if (!auditStore.getBinaryFast(existingEntry.localTime)) {
402+
if (existingEntry.localTime && !auditStore.getBinaryFast(existingEntry.localTime)) {
404403
// if it used to have blobs, and it doesn't exist in the audit store, we need to delete the old blobs
405404
deleteBlobsInObject(existingEntry.value);
406405
}

resources/blob.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,12 @@ import { Readable, pipeline } from 'node:stream';
3434
import { ensureDirSync } from 'fs-extra';
3535
import { get as envGet, getHdbBasePath } from '../utility/environment/environmentManager.js';
3636
import { CONFIG_PARAMS } from '../utility/hdbTerms.ts';
37-
import { join, dirname } from 'path';
37+
import { join, dirname } from 'node:path';
3838
import logger from '../utility/logging/logger.js';
3939
import type { LMDBStore } from 'lmdb';
4040
import { asyncSerialization, hasAsyncSerialization } from '../server/serverHelpers/contentTypes.ts';
4141
import { HAS_BLOBS, readAuditEntry } from './auditStore.ts';
4242
import { getHeapStatistics } from 'node:v8';
43-
import * as buffer from 'node:buffer';
4443

4544
type StorageInfo = {
4645
storageIndex: number;
@@ -93,7 +92,7 @@ let warnedSaveDeprecation = false;
9392
* 1. This has the built-in functionality for reading from the file-based storage
9493
* 2. This support for streams and asynchronous access to data that may not have a known size ahead of time
9594
* 3. This also avoids the Blob constructor which is expensive due to the transferred setup
96-
* Harper still supports saving native Blobs, but when they blobs are retrieved from storage, they always use this class.
95+
* Harper still supports saving native Blobs, but when the blobs are retrieved from storage, they always use this class.
9796
*/
9897
class FileBackedBlob extends InstanceOfBlobWithNoConstructor {
9998
type = '';
@@ -492,6 +491,7 @@ export type BlobCreationOptions = {
492491
size?: number; // the size of the data, if known ahead of time
493492
saveBeforeCommit?: boolean; // save the blob before the transaction is committed
494493
};
494+
495495
/**
496496
* Create a blob from a readable stream or a buffer by creating a file in the blob storage path with a new unique internal id, that
497497
* can be saved/stored.

resources/databases.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { initSync, getHdbBasePath, get as envGet } from '../utility/environment/environmentManager.js';
22
import { INTERNAL_DBIS_NAME } from '../utility/lmdb/terms.js';
33
import { open, compareKeys, type Database } from 'lmdb';
4-
import { join, extname, basename } from 'path';
5-
import { existsSync, readdirSync } from 'fs';
4+
import { join, extname, basename } from 'node:path';
5+
import { existsSync, readdirSync } from 'node:fs';
66
import {
77
getBaseSchemaPath,
88
getTransactionAuditStoreBasePath,
@@ -15,20 +15,16 @@ import { _assignPackageExport } from '../globals.js';
1515
import { getIndexedValues } from '../utility/lmdb/commonUtility.js';
1616
import * as signalling from '../utility/signalling.js';
1717
import { SchemaEventMsg } from '../server/threads/itc.js';
18-
import { workerData } from 'worker_threads';
18+
import { workerData } from 'node:worker_threads';
1919
import harperLogger from '../utility/logging/harper_logger.js';
2020
const { forComponent } = harperLogger;
2121
import * as manageThreads from '../server/threads/manageThreads.js';
2222
import { openAuditStore } from './auditStore.ts';
2323
import { handleLocalTimeForGets } from './RecordEncoder.ts';
2424
import { deleteRootBlobPathsForDB } from './blob.ts';
2525
import { CUSTOM_INDEXES } from './indexes/customIndexes.ts';
26-
import * as OpenDBIObjectModule from '../utility/lmdb/OpenDBIObject.js';
27-
function OpenDBIObject(dupSort, isPrimary) {
28-
// what is going on with esbuild, it suddenly is randomly flip-flopping the module record for OpenDBIObject, sometimes return the correct exports object and sometimes returning the exports as the `default`.
29-
let OpenDBIObject = OpenDBIObjectModule.OpenDBIObject ?? OpenDBIObjectModule.default.OpenDBIObject;
30-
return new OpenDBIObject(dupSort, isPrimary);
31-
}
26+
import { OpenDBIObject } from '../utility/lmdb/OpenDBIObject.ts';
27+
3228
const logger = forComponent('storage');
3329

3430
const DEFAULT_DATABASE_NAME = 'data';

resources/openApi.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { packageJson } from '../utility/packageUtils.js';
22
import { Resources } from './Resources.ts';
3+
import { Resource } from './Resource.ts';
34

45
const OPENAPI_VERSION = '3.0.3';
56
// Maps graphql primitive types to open api types

0 commit comments

Comments
 (0)