feat(tests): Add comprehensive tests for Docker image export and streaming functionality
This commit is contained in:
40
test-stream.js
Normal file
40
test-stream.js
Normal file
@@ -0,0 +1,40 @@
|
||||
const { SmartRequest } = require('@push.rocks/smartrequest');
|
||||
|
||||
async function test() {
|
||||
try {
|
||||
const response = await SmartRequest.create()
|
||||
.url('http://unix:/run/user/1000/docker.sock:/images/hello-world:latest/get')
|
||||
.header('Host', 'docker.sock')
|
||||
.get();
|
||||
|
||||
console.log('Response status:', response.status);
|
||||
console.log('Response type:', typeof response);
|
||||
|
||||
const stream = response.streamNode();
|
||||
console.log('Stream type:', typeof stream);
|
||||
console.log('Has on method:', typeof stream.on);
|
||||
|
||||
if (stream) {
|
||||
let chunks = 0;
|
||||
stream.on('data', (chunk) => {
|
||||
chunks++;
|
||||
if (chunks <= 3) console.log('Got chunk', chunks, chunk.length);
|
||||
});
|
||||
stream.on('end', () => {
|
||||
console.log('Stream ended, total chunks:', chunks);
|
||||
process.exit(0);
|
||||
});
|
||||
stream.on('error', (err) => {
|
||||
console.error('Stream error:', err);
|
||||
process.exit(1);
|
||||
});
|
||||
} else {
|
||||
console.log('No stream available');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
test();
|
Reference in New Issue
Block a user