-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: test InstructLab in a container
Signed-off-by: Jeff MAURY <[email protected]>
- Loading branch information
Showing
15 changed files
with
598 additions
and
19 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,3 @@ | ||
{ | ||
"default": "docker.io/redhat/instructlab@sha256:c6b2ecb4547b1f43b5539ee99bdbf5c9ae40599fabe1c740622295d9721b91c4" | ||
} |
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
77 changes: 77 additions & 0 deletions
77
packages/backend/src/managers/instructlab/instructlabManager.spec.ts
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,77 @@ | ||
/********************************************************************** | ||
* 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 { TaskRegistry } from '../../registries/TaskRegistry'; | ||
import { beforeAll, beforeEach, expect, test, vi } from 'vitest'; | ||
import type { ContainerInfo, Webview } from '@podman-desktop/api'; | ||
import { containerEngine, EventEmitter } from '@podman-desktop/api'; | ||
import type { PodmanConnection } from '../podmanConnection'; | ||
import { INSTRUCTLAB_CONTAINER_LABEL, InstructlabManager } from './instructlabManager'; | ||
import { ContainerRegistry } from '../../registries/ContainerRegistry'; | ||
import { TestEventEmitter } from '../../tests/utils'; | ||
|
||
vi.mock('@podman-desktop/api', () => { | ||
return { | ||
EventEmitter: vi.fn(), | ||
containerEngine: { | ||
listContainers: vi.fn(), | ||
onEvent: vi.fn(), | ||
}, | ||
}; | ||
}); | ||
|
||
const taskRegistry = new TaskRegistry({ postMessage: vi.fn().mockReturnValue(undefined) } as unknown as Webview); | ||
|
||
const podmanConnection: PodmanConnection = { | ||
onPodmanConnectionEvent: vi.fn(), | ||
} as unknown as PodmanConnection; | ||
|
||
let instructlabManager: InstructlabManager; | ||
|
||
beforeAll(() => { | ||
vi.mocked(EventEmitter).mockImplementation(() => new TestEventEmitter() as unknown as EventEmitter<unknown>); | ||
}); | ||
|
||
beforeEach(() => { | ||
const containerRegistry = new ContainerRegistry(); | ||
containerRegistry.init(); | ||
instructlabManager = new InstructlabManager('', taskRegistry, podmanConnection, containerRegistry); | ||
}); | ||
|
||
test('getInstructLabContainer should return undefined if no containers', async () => { | ||
vi.mocked(containerEngine.listContainers).mockResolvedValue([]); | ||
const containerId = await instructlabManager.getInstructLabContainer(); | ||
expect(containerId).toBeUndefined(); | ||
}); | ||
|
||
test('getInstructLabContainer should return undefined if no instructlab container', async () => { | ||
vi.mocked(containerEngine.listContainers).mockResolvedValue([{ Id: 'dummyId' } as unknown as ContainerInfo]); | ||
const containerId = await instructlabManager.getInstructLabContainer(); | ||
expect(containerId).toBeUndefined(); | ||
}); | ||
|
||
test('getInstructLabContainer should return id if instructlab container', async () => { | ||
vi.mocked(containerEngine.listContainers).mockResolvedValue([ | ||
{ | ||
Id: 'dummyId', | ||
State: 'running', | ||
Labels: { [`${INSTRUCTLAB_CONTAINER_LABEL}`]: 'dummyLabel' }, | ||
} as unknown as ContainerInfo, | ||
]); | ||
const containerId = await instructlabManager.getInstructLabContainer(); | ||
expect(containerId).toBe('dummyId'); | ||
}); |
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
Oops, something went wrong.