mirror of
https://github.com/opentofu/setup-opentofu.git
synced 2025-12-31 15:02:19 +00:00
Fix stream test
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
This commit is contained in:
parent
04ba7507e2
commit
6951ef3b10
4 changed files with 17 additions and 19 deletions
15
dist/index1.js
vendored
15
dist/index1.js
vendored
|
|
@ -25899,7 +25899,8 @@ module.exports = {
|
|||
*
|
||||
* @example
|
||||
* // Instantiate a new listener
|
||||
* const listener = new OutputListener();
|
||||
* // stream is used to write the data before waiting for the listener to complete
|
||||
* const listener = new OutputListener(stream);
|
||||
* // Register listener against STDOUT stream
|
||||
* await exec.exec('ls', ['-ltr'], {
|
||||
* listeners: {
|
||||
|
|
@ -25910,12 +25911,14 @@ module.exports = {
|
|||
* console.log(listener.contents);
|
||||
*/
|
||||
class OutputListener {
|
||||
constructor () {
|
||||
constructor (stream) {
|
||||
this._buff = [];
|
||||
this._stream = stream;
|
||||
}
|
||||
|
||||
get listener () {
|
||||
const listen = function listen (data) {
|
||||
this._stream.write(data);
|
||||
this._buff.push(data);
|
||||
};
|
||||
return listen.bind(this);
|
||||
|
|
@ -27889,8 +27892,8 @@ async function checkTofu () {
|
|||
await checkTofu();
|
||||
|
||||
// Create listeners to receive output (in memory) as well
|
||||
const stdout = new OutputListener();
|
||||
const stderr = new OutputListener();
|
||||
const stdout = new OutputListener(process.stdout);
|
||||
const stderr = new OutputListener(process.stderr);
|
||||
const listeners = {
|
||||
stdout: stdout.listener,
|
||||
stderr: stderr.listener
|
||||
|
|
@ -27905,10 +27908,6 @@ async function checkTofu () {
|
|||
};
|
||||
const exitCode = await exec(pathToCLI, args, options);
|
||||
|
||||
// Pass-through stdout/err as `exec` won't due to `silent: true` option
|
||||
process.stdout.write(stdout.contents);
|
||||
process.stderr.write(stderr.contents);
|
||||
|
||||
// Set outputs, result, exitcode, and stderr
|
||||
core.setOutput('stdout', stdout.contents);
|
||||
core.setOutput('stderr', stderr.contents);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@
|
|||
*
|
||||
* @example
|
||||
* // Instantiate a new listener
|
||||
* const listener = new OutputListener();
|
||||
* // stream is used to write the data before waiting for the listener to complete
|
||||
* const listener = new OutputListener(stream);
|
||||
* // Register listener against STDOUT stream
|
||||
* await exec.exec('ls', ['-ltr'], {
|
||||
* listeners: {
|
||||
|
|
@ -20,12 +21,14 @@
|
|||
* console.log(listener.contents);
|
||||
*/
|
||||
class OutputListener {
|
||||
constructor () {
|
||||
constructor (stream) {
|
||||
this._buff = [];
|
||||
this._stream = stream;
|
||||
}
|
||||
|
||||
get listener () {
|
||||
const listen = function listen (data) {
|
||||
this._stream.write(data);
|
||||
this._buff.push(data);
|
||||
};
|
||||
return listen.bind(this);
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@
|
|||
*/
|
||||
|
||||
const OutputListener = require('../lib/output-listener');
|
||||
|
||||
const { PassThrough } = require('stream');
|
||||
describe('output-listener', () => {
|
||||
it('receives and exposes data', () => {
|
||||
const listener = new OutputListener();
|
||||
it('receives and exposes data', () => {
|
||||
const listener = new OutputListener(new PassThrough());
|
||||
const listen = listener.listener;
|
||||
listen(Buffer.from('foo'));
|
||||
listen(Buffer.from('bar'));
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ async function checkTofu () {
|
|||
await checkTofu();
|
||||
|
||||
// Create listeners to receive output (in memory) as well
|
||||
const stdout = new OutputListener();
|
||||
const stderr = new OutputListener();
|
||||
const stdout = new OutputListener(process.stdout);
|
||||
const stderr = new OutputListener(process.stderr);
|
||||
const listeners = {
|
||||
stdout: stdout.listener,
|
||||
stderr: stderr.listener
|
||||
|
|
@ -38,10 +38,6 @@ async function checkTofu () {
|
|||
};
|
||||
const exitCode = await exec(pathToCLI, args, options);
|
||||
|
||||
// Pass-through stdout/err as `exec` won't due to `silent: true` option
|
||||
process.stdout.write(stdout.contents);
|
||||
process.stderr.write(stderr.contents);
|
||||
|
||||
// Set outputs, result, exitcode, and stderr
|
||||
core.setOutput('stdout', stdout.contents);
|
||||
core.setOutput('stderr', stderr.contents);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue