Skip to content

Commit 0c63051

Browse files
committed
fix: clean + test
Signed-off-by: lstocchi <[email protected]>
1 parent f1777b6 commit 0c63051

File tree

6 files changed

+50
-9
lines changed

6 files changed

+50
-9
lines changed

src/crc-setup.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ export async function needSetup(): Promise<boolean> {
2525
await execPromise(getCrcCli(), ['setup', '--check-only']);
2626
return false;
2727
} catch (e) {
28-
console.log(e)
28+
console.log(e);
2929
return true;
3030
}
3131
}
3232

33-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
3433
export async function setUpCrc(askForPreset = false): Promise<boolean> {
3534
if (askForPreset) {
3635
const preset = await extensionApi.window.showInformationMessage(

src/crc-start.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { startCrc } from './crc-start';
2424
import * as logProvider from './log-provider';
2525
import * as daemon from './daemon-commander';
2626
import type { StartInfo } from './types';
27+
import { getLoggerCallback } from './util';
2728

2829
vi.mock('@podman-desktop/api', async () => {
2930
return {
@@ -44,7 +45,7 @@ test('setUpCRC is skipped if already setup, it just perform the daemon start com
4445
{
4546
updateStatus: vi.fn(),
4647
} as unknown as extensionApi.Provider,
47-
{} as extensionApi.Logger,
48+
getLoggerCallback(),
4849
{ logUsage: vi.fn() } as unknown as extensionApi.TelemetryLogger,
4950
);
5051
expect(setUpMock).not.toBeCalled();
@@ -65,7 +66,7 @@ test('set up CRC and then start the daemon', async () => {
6566
{
6667
updateStatus: vi.fn(),
6768
} as unknown as extensionApi.Provider,
68-
{} as extensionApi.Logger,
69+
getLoggerCallback(),
6970
{ logUsage: vi.fn() } as unknown as extensionApi.TelemetryLogger,
7071
);
7172
expect(setUpMock).toBeCalled();

src/extension.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import { CrcInstall } from './install/crc-install';
3030

3131
import { crcStatus } from './crc-status';
3232
import { startCrc } from './crc-start';
33-
import { needSetup, setUpCrc } from './crc-setup';
3433
import { deleteCrc, registerDeleteCommand } from './crc-delete';
3534
import { presetChangedEvent, saveConfig, syncPreferences } from './preferences';
3635
import { stopCrc } from './crc-stop';
@@ -332,9 +331,9 @@ function registerOpenShiftLocalCluster(
332331
start: async (ctx, logger) => {
333332
provider.updateStatus('starting');
334333
try {
335-
await startCrc(provider, getLoggerCallback(ctx, logger,), telemetryLogger);
334+
await startCrc(provider, getLoggerCallback(ctx, logger), telemetryLogger);
336335
} catch (e) {
337-
logger?.error(e);
336+
logger.error(e);
338337
throw e;
339338
}
340339
},

src/log-provider.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* SPDX-License-Identifier: Apache-2.0
1717
***********************************************************************/
1818

19-
import type { Logger } from '@podman-desktop/api';
2019
import type { DaemonCommander } from './daemon-commander';
2120
import { commander } from './daemon-commander';
2221

src/util.spec.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**********************************************************************
2+
* Copyright (C) 2024 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
***********************************************************************/
18+
19+
import type * as extensionApi from '@podman-desktop/api';
20+
import { expect, test, vi } from 'vitest';
21+
import { getLoggerCallback } from './util';
22+
23+
test('check logger passed to getLoggerCallback is actually called with data', async () => {
24+
const logMock = vi.fn();
25+
const logger = {
26+
log: logMock,
27+
} as unknown as extensionApi.Logger;
28+
const callback = getLoggerCallback(undefined, logger);
29+
callback('data');
30+
expect(logMock).toBeCalledWith('data');
31+
});
32+
33+
test('check logger passed to getLoggerCallback is actually called with data', async () => {
34+
const logMock = vi.fn();
35+
const context = {
36+
log: {
37+
log: logMock,
38+
},
39+
} as unknown as extensionApi.LifecycleContext;
40+
const callback = getLoggerCallback(context);
41+
callback('data2');
42+
expect(logMock).toBeCalledWith('data2');
43+
});

src/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import * as os from 'node:os';
2020
import { spawn } from 'node:child_process';
2121
import * as fs from 'node:fs/promises';
2222
import type { Preset } from './types';
23-
import { LifecycleContext, Logger } from '@podman-desktop/api';
23+
import type { LifecycleContext, Logger } from '@podman-desktop/api';
2424

2525
export const productName = 'OpenShift Local';
2626
export const defaultPreset: Preset = 'openshift';

0 commit comments

Comments
 (0)