feat(tests): db test

This commit is contained in:
Alexey Kasyanchuk 2018-02-04 00:31:24 +03:00
parent 28305250aa
commit ae6864ba55
5 changed files with 96 additions and 7 deletions

View File

@ -152,6 +152,28 @@ const writeSphinxConfig = (path) => {
} }
`; `;
// clear dir in test env
if(env.name === 'test')
{
if (fs.existsSync(`${path}/database`)) {
fs.readdirSync(`${path}/database`).forEach(function(file, index){
const curPath = `${path}/database` + "/" + file;
if (!fs.lstatSync(curPath).isDirectory()) {
fs.unlinkSync(curPath);
}
});
fs.readdirSync(path).forEach(function(file, index){
if(!file.startsWith('binlog'))
return;
const curPath = path + "/" + file;
if (!fs.lstatSync(curPath).isDirectory()) {
fs.unlinkSync(curPath);
}
});
}
}
if (!fs.existsSync(`${path}/database`)){ if (!fs.existsSync(`${path}/database`)){
fs.mkdirSync(`${path}/database`); fs.mkdirSync(`${path}/database`);
} }

View File

@ -42,10 +42,10 @@ let config = {
const fs = require('fs'); const fs = require('fs');
const debug = require('debug')('config') const debug = require('debug')('config')
let configPath = 'config.json' let configPath = 'rats.json'
if(app && app.getPath("userData") && app.getPath("userData").length > 0) if(app && app.getPath("userData") && app.getPath("userData").length > 0)
{ {
configPath = app.getPath("userData") + '/config.json' configPath = app.getPath("userData") + '/rats.json'
} }
const configProxy = new Proxy(config, { const configProxy = new Proxy(config, {

View File

@ -1,3 +0,0 @@
{
"indexer": true
}

View File

@ -2,8 +2,8 @@ import { expect } from "chai";
import testUtils from "./utils"; import testUtils from "./utils";
describe("application launch", () => { describe("application launch", () => {
beforeEach(testUtils.beforeEach); before(testUtils.beforeEach);
afterEach(testUtils.afterEach); after(testUtils.afterEach);
it("index page loaded", async function() { it("index page loaded", async function() {
const { app } = this const { app } = this

70
tests/sphinx.test.js Normal file
View File

@ -0,0 +1,70 @@
import { expect } from "chai";
import testUtils from "./utils";
const mysql = require('mysql')
const config = require('../src/background/config')
describe("sphinx", () => {
before(testUtils.beforeEach);
after(testUtils.afterEach);
it("runned", async function() {
const { app } = this
await app.client.waitForExist('#index-window')
});
let sphinx;
it("init", function() {
sphinx = mysql.createPool({
connectionLimit: config.sphinx.connectionLimit,
host : config.sphinx.host,
port : config.sphinx.port
});
expect(sphinx)
})
it("insert", function(done) {
sphinx.query("INSERT INTO files(id, hash, path, pathIndex, size) VALUES(1, 'a', 'bashaa', 'bashaa', 50)", (err) => {
if(err)
throw new Error(err)
sphinx.query("INSERT INTO files(id, hash, path, pathIndex, size) VALUES(2, 'b', 'biotu', 'biotu', 30)", (err) => {
if(err)
throw new Error(err)
done()
})
})
})
it("select", function(done) {
sphinx.query("select * from files where hash = 'a'", (err, result) => {
if(!result)
throw new Error(err)
if(result.length !== 1)
throw new Error('not one result')
if(result[0].size !== 50)
throw new Error('not 50 in field')
done()
})
})
it("search", function(done) {
sphinx.query("select * from files where MATCH('bashaa')", (err, result) => {
if(!result)
throw new Error(err)
if(result.length !== 1)
throw new Error('not one result')
if(result[0].hash !== 'a')
throw new Error('not a in hash')
if(result[0].size !== 50)
throw new Error('not 50 in field')
done()
})
})
});