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

@@ -250,6 +250,12 @@ export class DockerImage {
public async exportToTarStream(): Promise<plugins.smartstream.stream.Readable> {
logger.log('info', `Exporting image ${this.RepoTags[0]} to tar stream.`);
const response = await this.dockerHost.requestStreaming('GET', `/images/${encodeURIComponent(this.RepoTags[0])}/get`);
// Check if response is a Node.js stream
if (!response || typeof response.on !== 'function') {
throw new Error('Failed to get streaming response for image export');
}
let counter = 0;
const webduplexStream = new plugins.smartstream.SmartDuplex({
writeFunction: async (chunk, tools) => {
@@ -259,17 +265,25 @@ export class DockerImage {
return chunk;
}
});
response.on('data', (chunk) => {
if (!webduplexStream.write(chunk)) {
response.pause();
webduplexStream.once('drain', () => {
response.resume();
})
};
});
}
});
response.on('end', () => {
webduplexStream.end();
})
});
response.on('error', (error) => {
logger.log('error', `Error during image export: ${error.message}`);
webduplexStream.destroy(error);
});
return webduplexStream;
}
}