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
41 changes: 40 additions & 1 deletion client/src/__tests__/unit-tests/driver/scanner-unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */

import { parseRecipesOutput } from '../../../driver/BitBakeProjectScanner'
import * as vscode from 'vscode'
import { BitBakeProjectScanner, parseRecipesOutput } from '../../../driver/BitBakeProjectScanner'
import { BitbakeDriver } from '../../../driver/BitbakeDriver'

jest.mock('vscode')

describe('BitBakeProjectScanner unit tests', () => {
afterEach(() => {
jest.clearAllMocks()
})

const layers = [
{
name: 'meta-variscite-bsp-imx',
Expand Down Expand Up @@ -68,4 +76,35 @@ systemd:
})
)
})
it('shows a non-modal error when path mapping fails', async () => {
const scanner = new BitBakeProjectScanner(new BitbakeDriver())

const scannerInternals = scanner as unknown as {
hostMountPoint: string
containerMountPoint: string
existsInContainer: (containerPath: string) => Promise<boolean>
}

scannerInternals.hostMountPoint = '/host'
scannerInternals.containerMountPoint = '/container'

jest.spyOn(scannerInternals, 'existsInContainer').mockResolvedValue(false)

const errorSpy = jest.spyOn(vscode.window, 'showErrorMessage')
.mockResolvedValue(undefined)

await scanner.resolveHostPath('/container/test.bb')

expect(errorSpy).toHaveBeenCalledWith(
expect.stringContaining('Bitbake extension couldn\'t locate a file')
)
expect(errorSpy).toHaveBeenCalledWith(
expect.stringContaining('bitbake.commandWrapper')
)
expect(errorSpy).toHaveBeenCalledWith(
expect.stringContaining('/container/test.bb')
)
expect(errorSpy.mock.calls[0]).toHaveLength(1)
})

})
13 changes: 5 additions & 8 deletions client/src/driver/BitBakeProjectScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,12 @@ export class BitBakeProjectScanner {
resolvedPath = path.resolve(destMountPoint, relativePath.replace('../', ''))
}
if (!await fileExistsFn(resolvedPath)) {
// Showing a modal here because this can only happend through the command devtool-update-recipe which is not used often
if (!quiet) {
await vscode.window.showErrorMessage(
'Bitbake extension couldn\'t locate a file.', {
modal: true,
detail: `It looks like you are using the bitbake.commandWrapper setting to use a docker container.\n
Couldn't find ${inputPath} corresponding paths inside and outside of the container.\n
You should adjust your docker volumes to use the same URIs as those present on your host machine.`
})
const message = 'Bitbake extension couldn\'t locate a file. ' +
'It looks like you are using the bitbake.commandWrapper setting to use a docker container. ' +
`Couldn't find ${inputPath} corresponding paths inside and outside of the container. ` +
'You should adjust your docker volumes to use the same URIs as those present on your host machine.'
await vscode.window.showErrorMessage(message)
}
return resolvedPath
}
Expand Down
Loading