Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/lambda-tiler/src/routes/__tests__/export.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,16 @@ describe('tileset.export', () => {
);
assert.equal(res.status, 404);
});

it('should not error on invalid requests', async (t) => {
t.mock.method(ConfigLoader, 'getDefaultConfig', () => Promise.resolve(config));
t.mock.method(s3Config, 'getSignedUrl', () => Promise.resolve('https://fake-s3-url.com/tileset.mbtiles'));

config.put(FakeData.tileSetRaster('aerial'));

const res = await handler.router.handle(
mockUrlRequest('/v1/export/aerial/WebMercatorQuad.mbtiles', 'get', Api.header),
);
assert.equal(res.status, 400);
});
});
7 changes: 3 additions & 4 deletions packages/linzjs-docker-command/src/command.execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { ExecutorLocal } from './execution/execute.local.js';
import { CommandExecutionResult } from './execution/execute.result.js';

export interface CommandExecutionOptions {
useDocker: boolean;
/** Should this execution use the container */
useDocker?: boolean;
}

export class CommandExecution {
Expand All @@ -15,9 +16,7 @@ export class CommandExecution {
useDocker?: boolean;
constructor(cmd: Command, opts?: CommandExecutionOptions) {
this.cmd = cmd;
if (opts) {
this.useDocker = opts.useDocker;
}
this.useDocker ??= opts?.useDocker;
}

get isRunWithDocker(): boolean {
Expand Down
15 changes: 13 additions & 2 deletions packages/linzjs-docker-command/src/command.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import { CommandExecution, CommandExecutionOptions } from './command.execution.js';

export interface CommandOptions {
container: string;
/**
* Container to use
* @example "ghcr.io/linz/basemaps/cli"
*/
container?: string;
/**
* Container tag to use
* @example "v7.0.3"
*/
tag?: string;

/** Should the container be used by default */
useDocker?: boolean;
}
export class Command {
executable: string;
Expand All @@ -24,7 +35,7 @@ export class Command {
}

static create(cmd: string, opts?: CommandOptions): CommandExecution {
return new Command(cmd, opts).create();
return new Command(cmd, opts).create({ useDocker: opts?.useDocker });
}

get containerName(): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import assert from 'node:assert';
import { describe, it } from 'node:test';

import { Command } from '../../command.js';
import { toDockerExecution } from '../execute.docker.js';
import { ExecutorDocker, toDockerExecution } from '../execute.docker.js';
import { ExecutorLocal } from '../execute.local.js';

describe('DockerExecution', () => {
it('should run hello world', () => {
Expand Down Expand Up @@ -38,4 +39,19 @@ describe('DockerExecution', () => {
cmd.env('AWS_ACCESS_KEY');
assert.equal(toDockerExecution(cmd).toCommand(), `docker run --rm --env AWS_ACCESS_KEY ubuntu echo hello world`);
});

it('should skip docker if useDocker is false', async (t) => {
const runDocker = t.mock.method(ExecutorDocker, 'run');
const runLocal = t.mock.method(ExecutorLocal, 'run');
const cmdLocal = Command.create('echo', { container: 'ubuntu', useDocker: false }).arg('hello world');
const cmdDocker = Command.create('echo', { container: 'ubuntu' }).arg('hello world');

await cmdLocal.run();
assert.equal(runLocal.mock.callCount(), 1);
assert.equal(runDocker.mock.callCount(), 0);

await cmdDocker.run();
assert.equal(runLocal.mock.callCount(), 1);
assert.equal(runDocker.mock.callCount(), 1);
});
});
Loading