Skip to content

Commit

Permalink
fix: clean + test
Browse files Browse the repository at this point in the history
Signed-off-by: lstocchi <[email protected]>
  • Loading branch information
lstocchi committed Aug 20, 2024
1 parent f1777b6 commit 0c63051
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/crc-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ export async function needSetup(): Promise<boolean> {
await execPromise(getCrcCli(), ['setup', '--check-only']);
return false;
} catch (e) {
console.log(e)
console.log(e);
return true;
}
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function setUpCrc(askForPreset = false): Promise<boolean> {
if (askForPreset) {
const preset = await extensionApi.window.showInformationMessage(
Expand Down
5 changes: 3 additions & 2 deletions src/crc-start.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { startCrc } from './crc-start';
import * as logProvider from './log-provider';
import * as daemon from './daemon-commander';
import type { StartInfo } from './types';
import { getLoggerCallback } from './util';

vi.mock('@podman-desktop/api', async () => {
return {
Expand All @@ -44,7 +45,7 @@ test('setUpCRC is skipped if already setup, it just perform the daemon start com
{
updateStatus: vi.fn(),
} as unknown as extensionApi.Provider,
{} as extensionApi.Logger,
getLoggerCallback(),
{ logUsage: vi.fn() } as unknown as extensionApi.TelemetryLogger,
);
expect(setUpMock).not.toBeCalled();
Expand All @@ -65,7 +66,7 @@ test('set up CRC and then start the daemon', async () => {
{
updateStatus: vi.fn(),
} as unknown as extensionApi.Provider,
{} as extensionApi.Logger,
getLoggerCallback(),
{ logUsage: vi.fn() } as unknown as extensionApi.TelemetryLogger,
);
expect(setUpMock).toBeCalled();
Expand Down
5 changes: 2 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { CrcInstall } from './install/crc-install';

import { crcStatus } from './crc-status';
import { startCrc } from './crc-start';
import { needSetup, setUpCrc } from './crc-setup';
import { deleteCrc, registerDeleteCommand } from './crc-delete';
import { presetChangedEvent, saveConfig, syncPreferences } from './preferences';
import { stopCrc } from './crc-stop';
Expand Down Expand Up @@ -332,9 +331,9 @@ function registerOpenShiftLocalCluster(
start: async (ctx, logger) => {
provider.updateStatus('starting');
try {
await startCrc(provider, getLoggerCallback(ctx, logger,), telemetryLogger);
await startCrc(provider, getLoggerCallback(ctx, logger), telemetryLogger);
} catch (e) {
logger?.error(e);
logger.error(e);
throw e;
}
},
Expand Down
1 change: 0 additions & 1 deletion src/log-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

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

Expand Down
43 changes: 43 additions & 0 deletions src/util.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**********************************************************************
* Copyright (C) 2024 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

import type * as extensionApi from '@podman-desktop/api';
import { expect, test, vi } from 'vitest';
import { getLoggerCallback } from './util';

test('check logger passed to getLoggerCallback is actually called with data', async () => {
const logMock = vi.fn();
const logger = {
log: logMock,
} as unknown as extensionApi.Logger;
const callback = getLoggerCallback(undefined, logger);
callback('data');
expect(logMock).toBeCalledWith('data');
});

test('check logger passed to getLoggerCallback is actually called with data', async () => {
const logMock = vi.fn();
const context = {
log: {
log: logMock,
},
} as unknown as extensionApi.LifecycleContext;
const callback = getLoggerCallback(context);
callback('data2');
expect(logMock).toBeCalledWith('data2');
});
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import * as os from 'node:os';
import { spawn } from 'node:child_process';
import * as fs from 'node:fs/promises';
import type { Preset } from './types';
import { LifecycleContext, Logger } from '@podman-desktop/api';
import type { LifecycleContext, Logger } from '@podman-desktop/api';

export const productName = 'OpenShift Local';
export const defaultPreset: Preset = 'openshift';
Expand Down

0 comments on commit 0c63051

Please sign in to comment.