Skip to content

Commit

Permalink
test (libpostal): try adding test to libpostal
Browse files Browse the repository at this point in the history
  • Loading branch information
AlasDiablo committed Apr 8, 2024
1 parent 12a6585 commit 2ec663b
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/install-libpostal.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

## Script base of the libpostal github action
## https://github.com/openvenues/node-postal/blob/master/.github/workflows/push.yml

# Install required dependencies to build libpostal
sudo apt-get update
sudo apt-get install build-essential curl autoconf automake libtool pkg-config

# Create working directory
sudo mkdir -p /code /data /deps
sudo chown "$USER":"$USER" /code /data /deps

# Install lib postal
cd /code || exit
git clone https://github.com/openvenues/libpostal
cd libpostal || exit
git reset --hard 8f2066b ## Reset to a fixed commit https://github.com/openvenues/libpostal/commit/8f2066b1d30f4290adf59cacc429980f139b8545
./bootstrap.sh
./configure --datadir=/data --prefix=/deps --bindir=/deps || cat config.log
make -j4
make install
7 changes: 7 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,22 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Install libpostal
run: bash ${GITHUB_WORKSPACE}/.github/workflows/install-libpostal.sh
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'

- name: Install dependencies
env:
CXXFLAGS: '-I/deps/include'
LDFLAGS: '-L/deps/lib'
run: yarn run ci:install
- name: Testing all packages
env:
LD_LIBRARY_PATH: '/deps/lib'
run: yarn run ci:test

- name: Coveralls Parallel
Expand Down
23 changes: 23 additions & 0 deletions packages/libpostal/test-utils/runEzs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import from from 'from';

/**
* Helper function used to call ezs in each test
* @param ezsRuntime {(name: string, options: any, environment?: unknown) => NodeJS.WritableStream}
* @param dataSet {Array<unknown>}
* @param functionName {string}
* @param [options] {any}
* @returns {Promise<Array<unknown>>}
*/
const runEzs = (ezsRuntime, dataSet, functionName, options) => new Promise((resolve) => {
const result = [];
from(dataSet)
.pipe(ezsRuntime(functionName, options))
.on('data', (chunk) => {
result.push(chunk);
})
.on('end', () => {
resolve(result);
});
});

export default runEzs;
41 changes: 41 additions & 0 deletions packages/libpostal/test/expand.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import ezs from '../../core/src';
import expandAddress from '../src/expand-address';
import expandAddressWith from '../src/expand-address-with';
import runEzs from '../test-utils/runEzs';

ezs.addPath(__dirname);

describe('expandAddress', () => {

beforeAll(() => {
ezs.use({ expandAddress, expandAddressWith });
});

describe('expandAddress, simple object', () => {
const simpleData = [
'Barboncino 781 Franklin Ave, Crown Heights, Brooklyn, NY 11238'
];

it('should expandAddress', async () => {
const result = await runEzs(ezs, simpleData, 'expandAddress');

expect(result[0]).not.toBeNull();

console.log(result);
});
});

describe('expandAddressWith, simple object', () => {
const simpleData = [
{value: 'Barboncino 781 Franklin Ave, Crown Heights, Brooklyn, NY 11238'}
];

it('should expandAddressWith (path = value)', async () => {
const result = await runEzs(ezs, simpleData, 'expandAddressWith', {path: 'value'});

expect(result[0]).not.toBeNull();

console.log(result);
});
});
});

0 comments on commit 2ec663b

Please sign in to comment.