Skip to content
Merged
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
20 changes: 15 additions & 5 deletions src/actions/configure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Configure, configure } from './configure';

describe('Configure', () => {
const composeFileUri = vscode.Uri.file(
path.join(os.tmpdir(), 'demo', 'compose.yml'),
path.join(os.tmpdir(), 'demo', 'compose.yaml'),
);
const projectPath = path.dirname(composeFileUri.fsPath);
let taskExecutor: MockProxy<TaskExecutor>;
Expand All @@ -18,7 +18,7 @@ describe('Configure', () => {
expect(task.name).toBe('Configure demo');
expect(task.execution).toMatchObject({
process: 'topo',
args: ['configure', '--file', 'compose.yml'],
args: ['configure', '--file', 'compose.yaml'],
options: { cwd: projectPath },
});
}
Expand Down Expand Up @@ -51,9 +51,7 @@ describe('Configure', () => {
it('throws when the context command has no compose file', async () => {
await expect(
configureAction.configureContextCommandHandler(),
).rejects.toThrow(
'No compose.yaml or compose.yml selected for configuration',
);
).rejects.toThrow('No compose.yaml selected for configuration');

expect(taskExecutor.run).not.toHaveBeenCalled();
});
Expand All @@ -74,6 +72,18 @@ describe('Configure', () => {
);
});

it('rejects compose.yml without invoking topo', async () => {
const unsupportedComposeFile = path.join(projectPath, 'compose.yml');

await expect(
configure(taskExecutor, unsupportedComposeFile),
).rejects.toThrow(
'Unsupported compose file "compose.yml". Only compose.yaml is supported.',
);

expect(taskExecutor.run).not.toHaveBeenCalled();
});
Comment thread
awphi marked this conversation as resolved.

it('reports task failure', async () => {
taskExecutor.run.mockRejectedValueOnce(new Error('configure failed'));

Expand Down
9 changes: 4 additions & 5 deletions src/actions/configure.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'node:path';
import * as vscode from 'vscode';
import { getErrorMessage } from '../util/getErrorMessage';
import { assertComposeFilePath, COMPOSE_FILE_NAME } from '../util/composeFile';
import { createProcessTask } from '../util/task';
import { TaskExecutor } from '../util/taskExecutor';
import { assertProjectTreeItem } from '../views/treeItems/assertProjectTreeItem';
Expand All @@ -16,9 +17,7 @@ export class Configure {
resource?: vscode.Uri,
): Promise<void> {
if (!resource) {
throw new Error(
'No compose.yaml or compose.yml selected for configuration',
);
throw new Error('No compose.yaml selected for configuration');
}

await configure(this.taskExecutor, resource.fsPath);
Expand All @@ -36,12 +35,12 @@ export async function configure(
taskExecutor: TaskExecutor,
composeFilePath: string,
): Promise<void> {
assertComposeFilePath(composeFilePath);
const composeFileDir = path.dirname(composeFilePath);
const composeFileName = path.basename(composeFilePath);
const projectName = path.basename(composeFileDir);
const task = createProcessTask(
`Configure ${projectName}`,
['topo', 'configure', '--file', composeFileName],
['topo', 'configure', '--file', COMPOSE_FILE_NAME],
{
cwd: composeFileDir,
},
Expand Down