Skip to content

Commit

Permalink
fix: provides the tag names rather than id when saving images
Browse files Browse the repository at this point in the history
it allows to restore images under their proper names

fixes podman-desktop#6582
Signed-off-by: Florent Benoit <[email protected]>
  • Loading branch information
benoitf committed Apr 2, 2024
1 parent a378455 commit 21d209d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
65 changes: 65 additions & 0 deletions packages/renderer/src/lib/image/SaveImages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,71 @@ test('Expect save button to be enabled if output target is selected and saveImag
expect(goToMock).toBeCalledWith('/images/');
});

test('Expect saveImages function called with tagged images', async () => {
saveDialogMock.mockResolvedValue({ scheme: 'file', path: '/tmp/my/path' } as Uri);
saveImagesMock.mockResolvedValue('');
const goToMock = vi.spyOn(router, 'goto');

// default tag (latest)
const imageInfo1: ImageInfoUI = {
id: 'id1',
shortId: 'id1',
tag: 'latest',
name: 'quay.io/podman/hello',
engineId: 'engine',
} as ImageInfoUI;

// no tag
const imageInfo2: ImageInfoUI = {
id: 'id2',
shortId: 'id2',
tag: 'latest',
name: '<none>',
engineId: 'engine',
} as ImageInfoUI;
// custom tag (not latest)
const imageInfo3: ImageInfoUI = {
id: 'id1',
shortId: 'id1',
tag: '123',
name: 'quay.io/podman/hello',
engineId: 'engine',
} as ImageInfoUI;

saveImagesInfo.set([imageInfo1, imageInfo2, imageInfo3]);
await waitRender();

const selectOutputPathButton = screen.getByRole('button', { name: 'Select output folder' });
expect(selectOutputPathButton).toBeInTheDocument();

await userEvent.click(selectOutputPathButton);

const saveButton = screen.getByRole('button', { name: 'Save images' });
expect(saveButton).toBeInTheDocument();
expect(saveButton).toBeEnabled();

await userEvent.click(saveButton);

expect(saveImagesMock).toBeCalledWith({
images: [
{
id: 'quay.io/podman/hello:latest',
engineId: 'engine',
},
{
id: 'id2',
engineId: 'engine',
},
{
id: 'quay.io/podman/hello:123',
engineId: 'engine',
},
],
outputTarget: '/tmp/my/path',
});
expect(goToMock).toBeCalledWith('/images/');
});

test('Expect error message dispayed if saveImages fails', async () => {
saveDialogMock.mockResolvedValue({ scheme: 'file', path: '/tmp/my/path' } as Uri);
saveImagesMock.mockRejectedValue('error while saving');
Expand Down
7 changes: 6 additions & 1 deletion packages/renderer/src/lib/image/SaveImages.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,13 @@ async function saveImages() {
try {
await window.saveImages({
images: imagesToSave.map(img => {
// do we have a valid name for the image?
let imageId = `${img.name}:${img.tag}`;
if (imageId.startsWith('<none>')) {
imageId = img.shortId;
}
return {
id: img.shortId,
id: imageId,
engineId: img.engineId,
};
}),
Expand Down

0 comments on commit 21d209d

Please sign in to comment.