Skip to content

Commit

Permalink
Testes de banco de dados
Browse files Browse the repository at this point in the history
  • Loading branch information
adrwtr committed Sep 11, 2017
1 parent 7cfea68 commit e75a3aa
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 0 deletions.
1 change: 1 addition & 0 deletions data/collection_test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"_id":"37240c0cb8ab4a7dacd91acaca5fdc5e","nome":"Adriano Waltrick"}]
16 changes: 16 additions & 0 deletions services/diskdb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// var npm_diskdb = require('diskdb');

function getDbConexoes(npm_diskdb)
{
var db = npm_diskdb.connect(
'./data/',
['conexoes']
);

return db.conexoes;
}


module.exports = {
getDbConexoesApp: getDbConexoes
};
61 changes: 61 additions & 0 deletions services/mysql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
function execQuery(
objConexao,
ds_query,
fnCallBackResult
) {
return new Promise(
function (resolve, reject) {
objConexao.connect();

objConexao.query(
ds_query,
function (error, arrColunas) {
objConexao.end();

if (error){
reject(error);
return;
}

resolve(
fnCallBackResult(
arrColunas,
resolve,
reject
)
);
}
);
}
);
}

function getDatabases(objConexao) {
var ds_query = 'SHOW DATABASES';

var fnCallBack = function(
arrValores,
resolve,
reject
) {
var arrDatabases = arrValores.map(
function(objColuna) {
return {
ds_nome : objColuna.Database
};
}
);

resolve(arrDatabases);
}

return execQuery(
objConexao,
ds_query,
fnCallBack
);
}

module.exports = {
getDatabases: getDatabases
};
60 changes: 60 additions & 0 deletions test/diskdb_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
var assert = require('assert');
var npm_db = require('diskdb');
var chai = require('chai');
var expect = chai.expect;



describe(
'Teste de diskdb',
function() {
it(
'Remove - save - count',
function (done) {
var db = npm_db.connect(
'./data/',
['collection_test']
);

db.collection_test.remove();
db = null;

db = npm_db.connect(
'./data/',
['collection_test']
);

var objRegistro = {
_id : '0ce47983623f4fb096ab3303d7bb6de7',
nome : 'Adriano Waltrick'
};

db.collection_test
.save(objRegistro);

var arrValor = db.collection_test.find();
expect(arrValor.length).to.equal(1);
expect(db.collection_test.count()).to.equal(1);


done();
}
);

it(
'find',
function (done) {
var db = npm_db.connect(
'./data/',
['collection_test']
);

var arrValor = db.collection_test.find();
expect(arrValor.length).to.equal(1);
expect(db.collection_test.count()).to.equal(1);

done();
}
);
}
);
51 changes: 51 additions & 0 deletions test/mysql_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
var assert = require('assert');
var npm_mysql = require('mysql');

// app
const objMysql = require('../services/mysql.js');

describe(
'Teste Servico Mysql',
function() {
describe(
'#getDatabases(objConexao)',
function() {
it(
'Total de databases',
function(done) {
const objConnectionBaseA = npm_mysql.createConnection({
host : "localhost",
user : "backup",
password : "UniSeguro",
database : "adriano"
});

const nr_qtd_database = 18;

objMysql.getDatabases(
objConnectionBaseA
).then(
function(arrResultadoA) {
var a = assert.equal(
arrResultadoA.length,
nr_qtd_database
);

var b = assert.equal(
arrResultadoA[0].ds_nome,
'information_schema'
);

done();
}
).catch(
function (objError) {
console.log(objError);
}
);
}
);
}
);
}
);

0 comments on commit e75a3aa

Please sign in to comment.