This repository was archived by the owner on May 8, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add devspace config and e2e tests #6
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,120 @@ | ||
| import { randomUUID } from 'node:crypto'; | ||
|
|
||
| import { afterAll, afterEach, beforeAll, describe, expect, it } from 'vitest'; | ||
| import { credentials, status } from '@grpc/grpc-js'; | ||
|
|
||
| import { RunnerServiceGrpcClient, type RunnerServiceGrpcClientInstance } from '../../src/proto/grpc.js'; | ||
| import { createGrpcTestClient, type GrpcTestClient } from '../helpers/grpc-test-client'; | ||
|
|
||
| const grpcAddress = process.env.DOCKER_RUNNER_GRPC_URL ?? 'localhost:50051'; | ||
| const sharedSecret = process.env.DOCKER_RUNNER_SHARED_SECRET; | ||
|
|
||
| if (!sharedSecret) { | ||
| throw new Error('DOCKER_RUNNER_SHARED_SECRET is required for e2e tests'); | ||
| } | ||
|
|
||
| describe('docker-runner e2e', () => { | ||
| let client: RunnerServiceGrpcClientInstance; | ||
| let grpcTestClient: GrpcTestClient; | ||
| const startedContainers = new Set<string>(); | ||
|
|
||
| beforeAll(async () => { | ||
| client = new RunnerServiceGrpcClient(grpcAddress, credentials.createInsecure()); | ||
| grpcTestClient = createGrpcTestClient({ client, secret: sharedSecret }); | ||
| await grpcTestClient.ready(); | ||
| }, 30_000); | ||
|
|
||
| afterAll(() => { | ||
| client.close(); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| for (const containerId of startedContainers) { | ||
| try { | ||
| await grpcTestClient.stopContainer(containerId); | ||
| } catch (error) { | ||
| console.warn(`cleanup stop failed for ${containerId}`, error); | ||
| } | ||
| try { | ||
| await grpcTestClient.removeContainer(containerId, { force: true, removeVolumes: true }); | ||
| } catch (error) { | ||
| console.warn(`cleanup remove failed for ${containerId}`, error); | ||
| } | ||
| } | ||
| startedContainers.clear(); | ||
| }); | ||
|
|
||
| it('ready health check', async () => { | ||
| const response = await grpcTestClient.ready(); | ||
| expect(response).toBeDefined(); | ||
| }); | ||
|
|
||
| it('starts a container', async () => { | ||
| const containerId = await startAlpineContainer('start-only'); | ||
| expect(containerId).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('inspects after start', async () => { | ||
| const containerId = await startAlpineContainer('inspect'); | ||
| const inspect = await grpcTestClient.inspectContainer(containerId); | ||
| expect(inspect.id).toBe(containerId); | ||
| expect(inspect.configImage).toContain('alpine'); | ||
| }); | ||
|
|
||
| it('stops a running container', async () => { | ||
| const containerId = await startAlpineContainer('stop'); | ||
| await grpcTestClient.stopContainer(containerId); | ||
| const inspect = await grpcTestClient.inspectContainer(containerId); | ||
| expect(inspect.id).toBe(containerId); | ||
| expect(inspect.stateRunning).toBe(false); | ||
| expect(inspect.stateStatus).not.toBe('running'); | ||
| }); | ||
|
|
||
| it('removes a stopped container', async () => { | ||
| const containerId = await startAlpineContainer('remove'); | ||
| await grpcTestClient.stopContainer(containerId); | ||
| await grpcTestClient.removeContainer(containerId, { force: true, removeVolumes: true }); | ||
| await expect(grpcTestClient.inspectContainer(containerId)).rejects.toMatchObject({ code: status.NOT_FOUND }); | ||
| }); | ||
|
|
||
| it('runs the full lifecycle', async () => { | ||
| const containerId = await startAlpineContainer('lifecycle'); | ||
| const inspect = await grpcTestClient.inspectContainer(containerId); | ||
| expect(inspect.id).toBe(containerId); | ||
| expect(inspect.configImage).toContain('alpine'); | ||
| await grpcTestClient.stopContainer(containerId); | ||
| await grpcTestClient.removeContainer(containerId, { force: true, removeVolumes: true }); | ||
| await expect(grpcTestClient.inspectContainer(containerId)).rejects.toMatchObject({ code: status.NOT_FOUND }); | ||
| }); | ||
|
|
||
| it('allows idempotent stop', async () => { | ||
| const containerId = await startAlpineContainer('stop-twice'); | ||
| await grpcTestClient.stopContainer(containerId); | ||
| await expect(grpcTestClient.stopContainer(containerId)).resolves.toBeUndefined(); | ||
| }); | ||
|
|
||
| it('allows idempotent remove', async () => { | ||
| const containerId = await startAlpineContainer('remove-twice'); | ||
| await grpcTestClient.stopContainer(containerId); | ||
| await grpcTestClient.removeContainer(containerId, { force: true, removeVolumes: true }); | ||
| await expect( | ||
| grpcTestClient.removeContainer(containerId, { force: true, removeVolumes: true }), | ||
| ).resolves.toBeUndefined(); | ||
| }); | ||
|
|
||
| async function startAlpineContainer(prefix: string): Promise<string> { | ||
| const name = `${prefix}-${randomUUID().slice(0, 8)}`; | ||
| const response = await grpcTestClient.startWorkload({ | ||
| image: 'alpine:3.19', | ||
| cmd: ['sleep', '30'], | ||
| name, | ||
| autoRemove: false, | ||
| }); | ||
| if (!response?.id) { | ||
| throw new Error('runner start did not return containerId'); | ||
| } | ||
| const containerId = response.id; | ||
| startedContainers.add(containerId); | ||
| return containerId; | ||
| } | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.