Skip to content

Commit

Permalink
[FABN-599] Added unit tests
Browse files Browse the repository at this point in the history
- Added tests to User using mocha at 100%
- Added tests to ChannelHelper using mocha at 100%
- Added tests to BasePackager using mocha at 100%
- Fixed licensing issues

Change-Id: I57063f89251d75f5f3d0603f1183c96d8a2c6a49
Signed-off-by: Liam Grace <[email protected]>
  • Loading branch information
liam-grace committed Oct 3, 2018
1 parent ed043c3 commit 49b73f2
Show file tree
Hide file tree
Showing 6 changed files with 1,371 additions and 33 deletions.
17 changes: 12 additions & 5 deletions fabric-client/lib/User.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
/*
Copyright 2016, 2018 IBM All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

Expand Down
52 changes: 31 additions & 21 deletions fabric-client/lib/packager/BasePackager.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
/*
Copyright 2017, 2018 IBM All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

SPDX-License-Identifier: Apache-2.0
*/

'use strict';

Expand Down Expand Up @@ -69,17 +77,18 @@ const BasePackager = class {
return new Promise((resolve, reject) => {
logger.debug('findMetadataDescriptors : start');
const descriptors = [];
klaw(filePath).on('data', (entry) => {
if (entry.stats.isFile() && this.isMetadata(entry.path)) {

const desc = {
name: path.join('META-INF', path.relative(filePath, entry.path).split('\\').join('/')), // for windows style paths
fqp: entry.path
};
logger.debug(' findMetadataDescriptors :: %j', desc);
descriptors.push(desc);
}
})
klaw(filePath)
.on('data', (entry) => {
if (entry.stats.isFile() && this.isMetadata(entry.path)) {

const desc = {
name: path.join('META-INF', path.relative(filePath, entry.path).split('\\').join('/')), // for windows style paths
fqp: entry.path
};
logger.debug(' findMetadataDescriptors :: %j', desc);
descriptors.push(desc);
}
})
.on('error', (error, item) => {
logger.error('error while packaging item %j :: %s', item, error);
reject(error);
Expand Down Expand Up @@ -160,13 +169,14 @@ const BasePackager = class {
generateTarGz (descriptors, dest) {
return new Promise((resolve, reject) => {
const pack = tar.pack();

// Setup the pipeline to compress on the fly and resolve/reject the promise
pack.pipe(zlib.createGzip()).pipe(dest).on('finish', () => {
resolve(true);
}).on('error', (err) => {
reject(err);
});
pack.pipe(zlib.createGzip()).pipe(dest)
.on('finish', () => {
resolve(true);
})
.on('error', (err) => {
reject(err);
});

// Iterate through each descriptor in the order it was provided and resolve
// the entry asynchronously. We will gather results below before
Expand Down
19 changes: 12 additions & 7 deletions fabric-client/lib/utils/ChannelHelper.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
/*
Copyright 2018 IBM All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

This helper is used for Channel util functions, most channel
util function should be removed here so that we can reduce the
file size of Channel.js
*/

const grpc = require('grpc');
const path = require('path');
Expand Down
Loading

0 comments on commit 49b73f2

Please sign in to comment.