feat(tests): Add comprehensive tests for Docker image export and streaming functionality

This commit is contained in:
2025-08-18 23:41:16 +00:00
parent ffdc61fb42
commit 87f26b7b63
7 changed files with 124 additions and 11 deletions

View File

@@ -262,12 +262,19 @@ export class DockerHost {
// Parse the response body based on content type
let body;
const contentType = response.headers['content-type'] || '';
if (contentType.includes('application/json')) {
// Docker's streaming endpoints (like /images/create) return newline-delimited JSON
// which can't be parsed as a single JSON object
const isStreamingEndpoint = routeArg.includes('/images/create') ||
routeArg.includes('/images/load') ||
routeArg.includes('/build');
if (contentType.includes('application/json') && !isStreamingEndpoint) {
body = await response.json();
} else {
body = await response.text();
// Try to parse as JSON if it looks like JSON
if (body && (body.startsWith('{') || body.startsWith('['))) {
// Try to parse as JSON if it looks like JSON and is not a streaming response
if (!isStreamingEndpoint && body && (body.startsWith('{') || body.startsWith('['))) {
try {
body = JSON.parse(body);
} catch {
@@ -299,7 +306,8 @@ export class DockerHost {
.header('Content-Type', 'application/json')
.header('X-Registry-Auth', this.registryToken)
.header('Host', 'docker.sock')
.options({ keepAlive: false });
.timeout(600000) // Set 10 minute timeout for streaming operations
.options({ keepAlive: false, autoDrain: false }); // Disable auto-drain for streaming
// If we have a readStream, use the new stream method with logging
if (readStream) {