Skip to content

Commit

Permalink
test: Common unit testing messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ztalbot2000 committed Jul 13, 2021
1 parent 8940795 commit b214fa8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 36 deletions.
30 changes: 8 additions & 22 deletions test/Cmd4AccessoryGetValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,8 @@ describe( "Testing Cmd4Accessory", function( )
// We have to wait for the failing getValue to timeout to capture the log messages;
setTimeout(() =>
{
let expectedOutput = `getValue: Mute function for: My_Television returned an empty string ""`;

assert.include( log.errBuf, expectedOutput, ` getValue stdErr output expected: ${ expectedOutput } received: ${ log.errBuf }` );
assert.equal( log.logBuf, "", ` getValue output expected: "" received: ${ log.errBuf }` );
assert.include( log.errBuf, `getValue: Mute function for: My_Television returned an empty string ""`, ` getValue Incorrect stderr: ${ log.errBuf }` );
assert.equal( log.logBuf, "", ` getValue Unexpected stdout: ${ log.errBuf }` );

done( );

Expand All @@ -371,10 +369,7 @@ describe( "Testing Cmd4Accessory", function( )
// We have to wait for the failing getValue to timeout to capture the log messages;
setTimeout(() =>
{
let expectedOutput = `getValue: "null" returned from stdout for Mute My_Television`;


assert.include( log.errBuf, expectedOutput, ` getValue output expected: ${ expectedOutput } received: ${ log.errBuf }` );
assert.include( log.errBuf, `getValue: "null" returned from stdout for Mute My_Television`, ` getValue Incorrect stderr: ${ log.errBuf }` );

done( );

Expand All @@ -400,10 +395,8 @@ describe( "Testing Cmd4Accessory", function( )
// We have to wait for the failing getValue to timeout to capture the log messages;
setTimeout(() =>
{
// let expectedOutput = `getValue Mute function failed for My_Television cmd: ./test/echoScripts/echo_true_withRcOf1 Get 'My_Television' 'Mute' Failed. replyCount: 1 Error: 1`;

// There is no longer a failingberror message as only the first message is now sent
//assert.include( log.errBuf, expectedOutput, ` getValue stdErr output expected: ${ expectedOutput } received: ${ log.errBuf }` );
//assert.include( log.errBuf, `getValue Mute function failed for My_Television cmd: ./test/echoScripts/echo_true_withRcOf1 Get 'My_Television' 'Mute' Failed. replyCount: 1 Error: 1`, ` getValue Incorrect stderr: ${ log.errBuf }` );
assert.equal( log.logBuf, "", ` getValue output expected: "" received: ${ log.errBuf }` );

done( );
Expand Down Expand Up @@ -431,10 +424,7 @@ describe( "Testing Cmd4Accessory", function( )
// We have to wait for the failing getValue to timeout to capture the log messages;
setTimeout(() =>
{
let expectedOutput = `getValue: Mute function for My_Television returned the string ""NULL""`;


assert.include( log.errBuf, expectedOutput, ` getValue output expected: ${ expectedOutput } received: ${ log.errBuf }` );
assert.include( log.errBuf, `getValue: Mute function for My_Television returned the string ""NULL""`, ` getValue Incorrect stderr: ${ log.errBuf }` );

done( );

Expand All @@ -458,10 +448,7 @@ describe( "Testing Cmd4Accessory", function( )

setTimeout(() =>
{
let expectedOutput = `getValue: Mute function for: My_Television returned an empty string "" ""`;


assert.include( log.errBuf, expectedOutput, ` getValue output expected: ${ expectedOutput } received: ${ log.errBuf }` );
assert.include( log.errBuf, `getValue: Mute function for: My_Television returned an empty string "" ""`, ` getValue Incorrect stdout: ${ log.errBuf }` );
done( );

}, 1000 );
Expand All @@ -483,9 +470,8 @@ describe( "Testing Cmd4Accessory", function( )

setTimeout(() =>
{
let expectedOutput = "This message goes to stderr";
assert.include( log.errBuf, expectedOutput, ` getValue stdErr output expected: ${ expectedOutput } received: ${ log.errBuf }` );
assert.equal( log.logBuf, "", ` getValue output expected: "" received: ${ log.errBuf }` );
assert.include( log.errBuf, "This message goes to stderr", ` getValue Incorrect stderr: ${ log.errBuf }` );
assert.equal( log.logBuf, "", ` getValue Unexpected stdout: ${ log.errBuf }` );

done( );

Expand Down
7 changes: 2 additions & 5 deletions test/Cmd4Platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,8 @@ describe('Testing Cmd4Platform Cmd4Mode gets passed to accessories', ( ) =>

assert.equal( cmd4Platform.createdCmd4Accessories.length, 1, ` Cmd4Platform did not create the cmd4Accessory` );

let expectedOutput1 = `Adding new platformAccessory: My_Door`;
let expectedOutput2 = `35mConfiguring platformAccessory: \u001b[39mMy_Door`;

assert.include( log.logBuf, expectedOutput1, ` Cmd4Platform missing message of new platform accessory being created` );
assert.include( log.logBuf, expectedOutput2, ` Cmd4Platform missing message of Configuring platform accessory` );
assert.include( log.logBuf, `Adding new platformAccessory: My_Door`, ` Cmd4Platform Incorrect stdout: ${ log.logBuf }` );
assert.include( log.logBuf, `35mConfiguring platformAccessory: \u001b[39mMy_Door`, ` Cmd4Platform Incorrect stdout: ${ log.logBuf}` );

let cmd4Accessory = cmd4Platform.createdCmd4Accessories[0];
expect( cmd4Accessory ).to.be.a.instanceOf( Cmd4Accessory, `cmd4Platform did not create an instance of Cmd4Accessory` );
Expand Down
9 changes: 3 additions & 6 deletions test/Cmd4PlatformRestartTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,10 @@ describe( "Testing Cmd4Platform", function( )
{
assert.equal( rc, null, `setCachedValue expected: zero received: ${ rc }` );

let expectedOutput = "[34mSetting (Cached) Example TV ConfiguredName\u001b[39m NEW_TV";

assert.include( log.logBuf, expectedOutput, `setCachedValue output failed: ${ expectedOutput } received: ${ log.logBuf }` );
assert.include( log.logBuf, `[34mSetting (Cached) Example TV ConfiguredName\u001b[39m NEW_TV`, `setCachedValue Incorrect stdout: ${ log.logBuf }` );

let result = cmd4Accessory.getStoredValueForIndex( acc );
let expectedResult = newValue;
assert.equal( result, expectedResult, " setCachedValue expected: " + expectedResult + " found: " + result );
assert.equal( result, newValue, " setCachedValue Incorrect result" );

// Clear the log buffer for next time.
log.reset();
Expand All @@ -355,7 +352,7 @@ describe( "Testing Cmd4Platform", function( )

cmd4Accessory = cmd4Platform2.createdCmd4Accessories[4];
let newFoundConfiguredName = cmd4Accessory.getStoredValueForIndex( acc );
assert.equal( newFoundConfiguredName, expectedResult, `Incorrect configuredName: ${ newFoundConfiguredName }` );
assert.equal( newFoundConfiguredName, newValue, `Incorrect configuredName: ${ newFoundConfiguredName }` );

});

Expand Down
5 changes: 2 additions & 3 deletions test/initPluginTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,8 @@ describe( `Testing index.js plugin Initialized variables.`, ( ) =>
apiInstance.emit("didFinishLaunching");
let expectedOutput = `Cmd4Platform didFinishLaunching`;
assert.include( log.logBuf, expectedOutput, `didFinishLaunching not called result: ${ log.logBuf }` );
assert.equal( log.errBuf, "", ` cmd4Platform unexpected error output received: ${ log.errBuf }` );
assert.include( log.logBuf, `Cmd4Platform didFinishLaunching`, `didFinishLaunching Incorrect stdout: ${ log.logBuf }` );
assert.equal( log.errBuf, "", ` cmd4Platform Unexpected stderr: ${ log.errBuf }` );
});
*/
Expand Down

0 comments on commit b214fa8

Please sign in to comment.