-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: lstocchi <[email protected]>
- Loading branch information
Showing
6 changed files
with
1,208 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/********************************************************************** | ||
* Copyright (C) 2022 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 | ||
***********************************************************************/ | ||
|
||
/** | ||
* Mock the extension API for vitest. | ||
* This file is referenced from vitest.config.js file. | ||
*/ | ||
const plugin = {}; | ||
module.exports = plugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/********************************************************************** | ||
* 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 { expect, test, vi } from 'vitest'; | ||
import * as crcCli from './crc-cli'; | ||
import { needSetup } from './crc-setup'; | ||
|
||
test('needSetup should return true if setup --check-only command fails', async () => { | ||
vi.spyOn(crcCli, 'execPromise').mockRejectedValue('daemon not running'); | ||
const isNeeded = await needSetup(); | ||
expect(isNeeded).toBeTruthy(); | ||
}); | ||
|
||
test('needSetup should return false if setup --check-only command succeed', async () => { | ||
vi.spyOn(crcCli, 'execPromise').mockResolvedValue(''); | ||
const isNeeded = await needSetup(); | ||
expect(isNeeded).toBeFalsy(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/********************************************************************** | ||
* 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 * as extensionApi from '@podman-desktop/api'; | ||
import { expect, test, vi } from 'vitest'; | ||
import * as crcCli from './crc-cli'; | ||
import * as crcSetup from './crc-setup'; | ||
import { startCrc } from './crc-start'; | ||
import * as logProvider from './log-provider'; | ||
import * as daemon from './daemon-commander'; | ||
import { StartInfo } from './types'; | ||
|
||
vi.mock('@podman-desktop/api', async () => { | ||
return { | ||
EventEmitter: vi.fn(), | ||
}; | ||
}); | ||
|
||
test('setUpCRC is skipped if already setup, it just perform the daemon start command', async () => { | ||
vi.spyOn(crcCli, 'execPromise').mockResolvedValue(''); | ||
vi.spyOn(logProvider.crcLogProvider, 'startSendingLogs').mockImplementation((logger: extensionApi.Logger) => { | ||
return Promise.resolve(); | ||
}); | ||
const startDaemon = vi.spyOn(daemon.commander, 'start').mockResolvedValue({ | ||
Status: 'Running', | ||
} as unknown as StartInfo); | ||
const setUpMock = vi.spyOn(crcSetup, 'setUpCrc'); | ||
await startCrc( | ||
{ | ||
updateStatus: (status: extensionApi.ProviderStatus) => {}, | ||
Check failure on line 45 in src/crc-start.spec.ts GitHub Actions / linter, formatters and unit tests
|
||
} as unknown as extensionApi.Provider, | ||
{} as extensionApi.Logger, | ||
{ logUsage: vi.fn() } as unknown as extensionApi.TelemetryLogger, | ||
); | ||
expect(setUpMock).not.toBeCalled(); | ||
expect(startDaemon).toBeCalled(); | ||
}); | ||
|
||
test('set up CRC and then start the daemon', async () => { | ||
vi.spyOn(crcCli, 'execPromise').mockRejectedValue('daemon not running'); | ||
|
||
vi.spyOn(logProvider.crcLogProvider, 'startSendingLogs').mockImplementation((logger: extensionApi.Logger) => { | ||
return Promise.resolve(); | ||
}); | ||
const startDaemon = vi.spyOn(daemon.commander, 'start').mockResolvedValue({ | ||
Status: 'Running', | ||
} as unknown as StartInfo); | ||
const setUpMock = vi | ||
.spyOn(crcSetup, 'setUpCrc') | ||
.mockImplementation((logger: extensionApi.Logger) => Promise.resolve(true)); | ||
await startCrc( | ||
{ | ||
updateStatus: (status: extensionApi.ProviderStatus) => {}, | ||
Check failure on line 68 in src/crc-start.spec.ts GitHub Actions / linter, formatters and unit tests
|
||
} as unknown as extensionApi.Provider, | ||
{} as extensionApi.Logger, | ||
{ logUsage: vi.fn() } as unknown as extensionApi.TelemetryLogger, | ||
); | ||
expect(setUpMock).toBeCalled(); | ||
expect(startDaemon).toBeCalled(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/********************************************************************** | ||
* 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 path from 'node:path'; | ||
|
||
const config = { | ||
test: { | ||
include: ['**/*.{test,spec}.?(c|m)[jt]s?(x)'], | ||
coverage: { | ||
provider: 'v8', | ||
reporter: ['lcov', 'text'], | ||
extension: '.ts', | ||
}, | ||
}, | ||
resolve: { | ||
alias: { | ||
'@podman-desktop/api': path.resolve(__dirname, '__mocks__/@podman-desktop/api.js'), | ||
}, | ||
}, | ||
}; | ||
|
||
export default config; |
Oops, something went wrong.