Skip to content

Commit

Permalink
remove Bonsai ElasticSearch Provider from tests. minor re-factor see: #…
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Dec 7, 2015
1 parent b43f81b commit da3b637
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 51 deletions.
22 changes: 11 additions & 11 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,13 @@ apt-get update
apt-get -y install g++ git git-core nodejs
# nodejs - most people running esta will already have node.js installed.
# apt-get -y install g++ git git-core nodejs npm
# use https://github.com/visionmedia/n to get latest node+npm
# npm install n -g
# n stable
# node -v
# npm install nodemon -g
# see: https://gist.github.com/wingdspur/2026107
sudo apt-get install openjdk-7-jre-headless -y
### Check http://www.elasticsearch.org/download/ for latest version of ElasticSearch and replace wget link below
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.7.1.deb
sudo dpkg -i elasticsearch-1.7.1.deb
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.7.2.deb
sudo dpkg -i elasticsearch-1.7.2.deb
curl -L https://github.com/elasticsearch/elasticsearch-servicewrapper/tarball/master | tar -xz
sudo mkdir -p /usr/local/share/elasticsearch/bin/
Expand All @@ -34,7 +26,15 @@ sudo /usr/local/share/elasticsearch/bin/service/elasticsearch install
sudo ln -s `readlink -f /usr/local/share/elasticsearch/bin/service/elasticsearch` /usr/local/bin/rcelasticsearch
sudo service elasticsearch start
# curl http://localhost:9200
# wait for ElasticSearch to boot
sleep 10
# Test that the sever is working
curl http://localhost:9200
# OPTIONALLY if you want to install Node:
# https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
SCRIPT

Expand Down
4 changes: 2 additions & 2 deletions lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ module.exports = function options(record, method) {
}
};
// example url: https://myuser:[email protected]
if(process.env.SEARCHBOX_SSL_URL || process.env.BONSAI_URL) {
var u = url.parse(process.env.SEARCHBOX_SSL_URL || process.env.BONSAI_URL);
if(process.env.SEARCHBOX_SSL_URL) { // || process.env.BONSAI_URL) {
var u = url.parse(process.env.SEARCHBOX_SSL_URL); // || process.env.BONSAI_URL);
var unpw = u.auth.split(':'); // auth is everything between // and @
var username = unpw[0];
var password = unpw[1];
Expand Down
5 changes: 4 additions & 1 deletion test/_connection.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
var test = require('tape');
var chalk = require('chalk');

process.env.SEARCHBOX = process.env.SEARCHBOX_SSL_URL;
delete process.env.SEARCHBOX_SSL_URL; // ensure we load http (NOT https)!
delete process.env.BONSAI_URL; // don't use Bonsai ES for bulk tests
var ES_URL = '127.0.0.1:9200';
var ES = require('../lib/index');

test(chalk.cyan('CONNECT to ES on ' +ES_URL), function (t) {
// console.log('process.env.SEARCHBOX_SSL_URL: '+process.env.SEARCHBOX_SSL_URL)
ES.CONNECT('twitter', function (res) {

console.log(' - - - - - - - - - - - - - - - - - - - - - res:');
console.log(res);
console.log(' - - - - - - - - - - - - - - - - - - - - - - - - ');
t.equal(res.status, 200, chalk.green("✓ Status 200 - OK"));
t.end();
});
Expand Down
79 changes: 42 additions & 37 deletions test/heroku.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
var test = require('tape');
var chalk = require('chalk');
var uncache = require('./uncache').uncache;
console.log(' - - - - - - - - - - - - - - - - - - - - - - - - process.env.SEARCHBOX_SSL_URL:');
console.log(process.env.SEARCHBOX +' || ' + process.env.SEARCHBOX_SSL_URL);
process.env.SEARCHBOX = process.env.SEARCHBOX || process.env.SEARCHBOX_SSL_URL;
console.log(process.env.SEARCHBOX +' || ' + process.env.SEARCHBOX_SSL_URL);

test(chalk.cyan('Force HTTP Error with bad UN:PW'), function (t) {
// please don't spam this SearchBox ElasticSearch account with Records!
// Its JUST for Testing this module! thanks! :-)
// process.env.SEARCHBOX = process.env.SEARCHBOX_SSL_URL;
process.env.SEARCHBOX_SSL_URL = 'https://un:[email protected]'
var ES_URL = process.env.SEARCHBOX_SSL_URL || '127.0.0.1:9200';
console.log(' - - - - - - - - - - - - - - - - - - - - - res:');
console.log(process.env.SEARCHBOX_SSL_URL);
console.log(' - - - - - - - - - - - - - - - - - - - - - - - - ');
// var ES_URL = process.env.SEARCHBOX_SSL_URL || '127.0.0.1:9200';
// https://nodejs.org/docs/latest/api/globals.html#globals_require_cache
uncache('../lib/index'); // reload http_request sans SSL! (localhost)
var ES = require('../lib/index');
ES.CONNECT(function (res) {
console.log(res);
t.equal(res.status, 'error', chalk.green("✓ Error forced. (we wanted this!)"));

t.end();
});
});
Expand All @@ -36,44 +43,43 @@ test(chalk.cyan('Exercise http_request req.on("error") handler'), function (t) {
});


test(chalk.cyan('CONNECT to Bonsai on HEROKU!'), function (t) {
// please don't spam this Bonsai ElasticSearch account with Records!
// Its JUST for Testing this module! thanks! :-)
delete process.env.SEARCHBOX_SSL_URL; // unset SearchBox so we can test Bonsai
process.env.BONSAI_URL = 'https://8py6wr37:[email protected]'
// https://nodejs.org/docs/latest/api/globals.html#globals_require_cache
uncache('../lib/index'); // reload http_request sans SSL! (localhost)
var ES = require('../lib/index');
// don't specify the index
ES.CONNECT(function (res) {
console.log(res);
t.equal(res.status, 200, chalk.green("✓ Status 200 - HEROKU Bonsai works like a charm"));
t.end();
});
});

test(chalk.cyan('CREATE a record on HEROKU/Bonsai'), function (t) {
process.env.BONSAI_URL = 'https://8py6wr37:[email protected]'
var ES = require('../lib/index');
var record = require('./fake_record.js')(); // fake record
ES.CREATE(record, function (res) {
console.log(res)
t.equal(res.created, true, chalk.green("✓ Record Created on Heroku/Bonsai"));
t.end();
});
});
// test(chalk.cyan('CONNECT to Bonsai on HEROKU!'), function (t) {
// // please don't spam this Bonsai ElasticSearch account with Records!
// // Its JUST for Testing this module! thanks! :-)
// delete process.env.SEARCHBOX_SSL_URL; // unset SearchBox so we can test Bonsai
// process.env.BONSAI_URL = 'https://8py6wr37:[email protected]'
// // https://nodejs.org/docs/latest/api/globals.html#globals_require_cache
// uncache('../lib/index'); // reload http_request sans SSL! (localhost)
// var ES = require('../lib/index');
// // don't specify the index
// ES.CONNECT(function (res) {
// console.log(res);
// t.equal(res.status, 200, chalk.green("✓ Status 200 - HEROKU Bonsai works like a charm"));
// t.end();
// });
// });
//
// test(chalk.cyan('CREATE a record on HEROKU/Bonsai'), function (t) {
// process.env.BONSAI_URL = 'https://8py6wr37:[email protected]'
// var ES = require('../lib/index');
// var record = require('./fake_record.js')(); // fake record
// ES.CREATE(record, function (res) {
// console.log(res)
// t.equal(res.created, true, chalk.green("✓ Record Created on Heroku/Bonsai"));
// t.end();
// });
// });

// var searchbox_index = 'bonsai'+new Date().getTime();
test(chalk.cyan('CONNECT to SearchBox on HEROKU!'), function (t) {
// please don't spam this SearchBox ElasticSearch account with Records!
// Its JUST for Testing this module! thanks! :-)
delete process.env.BONSAI_URL; // so we can test SearchBox now
process.env.SEARCHBOX_SSL_URL = 'https://paas:[email protected]'
// https://nodejs.org/docs/latest/api/globals.html#globals_require_cache
uncache('../lib/index'); // reload http_request sans SSL! (localhost)
process.env.SEARCHBOX_SSL_URL = process.env.SEARCHBOX || process.env.SEARCHBOX_SSL_URL; // see _connection.js
console.log(process.env.SEARCHBOX_SSL_URL);
uncache('../lib/index'); // see: https://github.com/dwyl/decache
var ES = require('../lib/index');
ES.CONNECT('twitter', function (res) {
console.log(' - - - - - - - - - - - - - - - - - - - - - res:');
console.log(res);
console.log(' - - - - - - - - - - - - - - - - - - - - - - - - ');
t.equal(res.status, 200, chalk.green("✓ Status 200 - OK"));
t.end();
});
Expand All @@ -93,7 +99,6 @@ test(chalk.cyan('CREATE a record on HEROKU/SearchBox'), function (t) {
test(chalk.cyan('Ensure that we clear node require cache to resume testing on localhost'), function(t){
uncache('../lib/index');
delete process.env.SEARCHBOX_SSL_URL; // unset SearchBox URL so we can resume testing locally
delete process.env.BONSAI_URL; // same for BONSAI
t.equal(process.env.BONSAI_URL, undefined, chalk.green("✓ Continue testing Local ES."));
t.equal(process.env.SEARCHBOX_SSL_URL, undefined, chalk.green("✓ Continue testing Local ES."));
t.end();
});

0 comments on commit da3b637

Please sign in to comment.