node-webhdfs
Advanced tools
Comparing version 0.3.0 to 0.4.0
{ | ||
"name": "node-webhdfs", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "A WebHDFS module for Node.js.", | ||
@@ -22,3 +22,3 @@ "author": "Ryan Cole <ryan@rycole.com> (http://rycole.com)", | ||
"devDependencies": { | ||
"mocha": "^1.21.5", | ||
"mocha": "^5.2.0", | ||
"should": "^4.6.5" | ||
@@ -25,0 +25,0 @@ }, |
@@ -9,2 +9,8 @@ A WebHDFS module for Node.js | ||
I use [Mocha](https://mochajs.org/) and [should.js](https://github.com/visionmedia/should.js) for unit testing. They will be required if you want to run the unit tests. To execute the tests, simply `npm test`, but install the requirements first. You will also likely need to adjust the constants in the test file first (or have a username "ryan" setup for hosts "endpoint1" and "endpoint2"). | ||
I use [Mocha](https://mochajs.org/) and [should.js](https://github.com/visionmedia/should.js) for unit testing. They will be required if you want to run the unit tests. To execute the tests, simply `npm test`, but install the requirements first. | ||
The following environment variables are used to configure the tests: | ||
- `HDFS_USERNAME` -- your username on the HDFS cluster (default: `ryan`) | ||
- `HDFS_NAMENODE_1` -- hostname of your primary namenode (default: `localhost`) | ||
- `HDFS_NAMENODE_2` -- hostname of your secondary namenode (default: `localhost`) | ||
- `HDFS_BASE_PATH` -- directory in which to conduct tests (default: `/user/$HDFS_USERNAME`) |
@@ -1,6 +0,5 @@ | ||
var querystring = require('querystring'), | ||
request = require('request'), | ||
_ = require('lodash'), | ||
RemoteException = exports.RemoteException = require('./remoteexception.js'); | ||
var _ = require('lodash'); | ||
var request = require('request'); | ||
var RemoteException = exports.RemoteException = require('./remoteexception.js'); | ||
@@ -252,3 +251,3 @@ var WebHDFSClient = exports.WebHDFSClient = function (options) { | ||
var self = this; | ||
var originalArgs = [path, hdfsoptions, requestoptions, callback]; | ||
var originalArgs = [hdfsoptions, requestoptions, callback]; | ||
var parseResponse = _parseResponse(self, 'getHomeDirectory', originalArgs, 'Path', callback); | ||
@@ -255,0 +254,0 @@ |
@@ -1,4 +0,7 @@ | ||
const username = 'ryan'; | ||
const endpoint1 = 'endpoint1'; | ||
const endpoint2 = 'endpoint2'; | ||
const username = process.env.HDFS_USERNAME || 'ryan'; | ||
const endpoint1 = process.env.HDFS_NAMENODE_1 || 'localhost'; | ||
const endpoint2 = process.env.HDFS_NAMENODE_2 || '127.0.0.1'; | ||
const homeDir = `/user/${username}`; | ||
const basePath = process.env.HDFS_BASE_PATH || homeDir; | ||
// endpoint defaults are written differently to verify switching | ||
@@ -10,9 +13,9 @@ var should = require('should'); | ||
var client = new (require('..')).WebHDFSClient({ user: username }); | ||
var client2 = new (require('..')).WebHDFSClient({ | ||
// never used for actual connection | ||
var oneNodeClient = new (require('..')).WebHDFSClient({ | ||
namenode_host: endpoint1 | ||
}); | ||
var client3 = new (require('..')).WebHDFSClient({ | ||
var twoNodeClient = new (require('..')).WebHDFSClient({ | ||
user: username, | ||
namenode_host: endpoint1, | ||
@@ -25,4 +28,4 @@ namenode_list: [endpoint1, endpoint2] | ||
it('should set high_availability to false if a list is not provided', function (done) { | ||
client2.should.have.property('base_url', 'http://' + endpoint1 + ':50070/webhdfs/v1'); | ||
client2.options.should.have.property('high_availability', false); | ||
oneNodeClient.should.have.property('base_url', 'http://' + endpoint1 + ':50070/webhdfs/v1'); | ||
oneNodeClient.options.should.have.property('high_availability', false); | ||
@@ -33,7 +36,7 @@ return done() | ||
it('should change endpoint if a list is provided', function (done) { | ||
client3.should.have.property('base_url', 'http://' + endpoint1 + ':50070/webhdfs/v1'); | ||
client3.options.should.have.property('high_availability', true); | ||
twoNodeClient.should.have.property('base_url', 'http://' + endpoint1 + ':50070/webhdfs/v1'); | ||
twoNodeClient.options.should.have.property('high_availability', true); | ||
client3._changeNameNodeHost(); | ||
client3.should.have.property('base_url', 'http://' + endpoint2 + ':50070/webhdfs/v1'); | ||
twoNodeClient._changeNameNodeHost(); | ||
twoNodeClient.should.have.property('base_url', 'http://' + endpoint2 + ':50070/webhdfs/v1'); | ||
@@ -44,4 +47,21 @@ return done() | ||
}); | ||
describe('#getHomeDirectory()', function () { | ||
it('should get the home directory', function (done) { | ||
twoNodeClient.getHomeDirectory(function (err, status) { | ||
should.not.exist(err); | ||
should.exist(status); | ||
status.should.eql(homeDir); | ||
return done(); | ||
}); | ||
}); | ||
}); | ||
describe('#mkdirs', function () { | ||
@@ -51,3 +71,3 @@ | ||
client.mkdirs('/test', function (err, success) { | ||
twoNodeClient.mkdirs(basePath + '/test', function (err, success) { | ||
@@ -71,3 +91,3 @@ should.not.exist(err); | ||
client.getFileStatus('/test', function (err, status) { | ||
twoNodeClient.getFileStatus(basePath + '/test', function (err, status) { | ||
@@ -91,3 +111,3 @@ should.not.exist(err); | ||
client.create('/test/foo.txt', '{"foo":"bar"}', function (err, path) { | ||
twoNodeClient.create(basePath + '/test/foo.txt', 'foo bar', function (err, path) { | ||
@@ -104,2 +124,19 @@ should.not.exist(err); | ||
}); | ||
describe('#append()', function () { | ||
it('should add to the file', function (done) { | ||
twoNodeClient.append(basePath + '/test/foo.txt', ' baz', function (err, path) { | ||
should.not.exist(err); | ||
should.exist(path); | ||
return done(); | ||
}); | ||
}); | ||
}); | ||
@@ -110,3 +147,3 @@ describe('#rename()', function () { | ||
client.rename('/test/foo.txt', '/test/bar.txt', function (err, success) { | ||
twoNodeClient.rename(basePath + '/test/foo.txt', basePath + '/test/bar.txt', function (err, success) { | ||
@@ -130,3 +167,3 @@ should.not.exist(err); | ||
client.getContentSummary('/test', function (err, summary) { | ||
twoNodeClient.getContentSummary(basePath + '/test', function (err, summary) { | ||
@@ -145,2 +182,20 @@ should.not.exist(err); | ||
}); | ||
describe('#listStatus()', function () { | ||
it('should list files in a directory', function (done) { | ||
twoNodeClient.listStatus(basePath + '/test', function (err, status) { | ||
should.not.exist(err); | ||
should.exist(status); | ||
status.map(f => f.pathSuffix).should.containEql('bar.txt'); | ||
return done(); | ||
}); | ||
}); | ||
}); | ||
@@ -151,3 +206,3 @@ describe('#getFileChecksum()', function () { | ||
client.getFileChecksum('/test/bar.txt', function (err, checksum) { | ||
twoNodeClient.getFileChecksum(basePath + '/test/bar.txt', function (err, checksum) { | ||
@@ -171,3 +226,3 @@ should.not.exist(err); | ||
client.open('/test/bar.txt', function (err, data) { | ||
twoNodeClient.open(basePath + '/test/bar.txt', function (err, data) { | ||
@@ -177,3 +232,3 @@ should.not.exist(err); | ||
(data).should.have.property('foo', 'bar'); | ||
data.should.eql('foo bar baz'); | ||
@@ -192,3 +247,3 @@ return done(); | ||
client.del('/test', { recursive: true }, function (err, success) { | ||
twoNodeClient.del(basePath + '/test', { recursive: true }, function (err, success) { | ||
@@ -195,0 +250,0 @@ should.not.exist(err); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26753
571
16
4