2018-10-24 21:42:33 +08:00
|
|
|
'use strict';
|
|
|
|
|
2018-05-22 01:13:44 +08:00
|
|
|
const assert = require('assert');
|
2019-10-04 00:24:39 +08:00
|
|
|
const queryInfo = require('../../lib/utils/query-info');
|
2018-05-22 01:13:44 +08:00
|
|
|
|
|
|
|
describe('query info', function () {
|
2018-05-22 20:16:22 +08:00
|
|
|
describe('copy format', function () {
|
|
|
|
describe('csv', function () {
|
2018-05-22 18:05:16 +08:00
|
|
|
const validQueries = [
|
2018-05-22 01:13:44 +08:00
|
|
|
"COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT CSV, DELIMITER ',', HEADER true)",
|
|
|
|
"COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT CSV, DELIMITER ',', HEADER true)",
|
|
|
|
"COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT CSV , DELIMITER ',', HEADER true)",
|
2019-12-24 01:19:08 +08:00
|
|
|
'COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT CSV)',
|
|
|
|
'COPY copy_endpoints_test FROM STDIN WITH(FORMAT csv,HEADER true)'
|
2018-05-22 01:13:44 +08:00
|
|
|
];
|
|
|
|
|
2018-05-22 18:05:16 +08:00
|
|
|
validQueries.forEach(query => {
|
2019-12-24 01:19:08 +08:00
|
|
|
it(query, function () {
|
2018-05-22 01:13:44 +08:00
|
|
|
const result = queryInfo.getFormatFromCopyQuery(query);
|
2019-12-26 21:01:18 +08:00
|
|
|
assert.strictEqual(result, 'CSV');
|
2018-05-22 01:13:44 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
describe('text', function () {
|
2018-05-22 18:05:16 +08:00
|
|
|
const validQueries = [
|
2019-12-24 01:19:08 +08:00
|
|
|
'COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT TEXT)',
|
|
|
|
'COPY copy_endpoints_test (id, name) FROM STDIN'
|
2018-05-22 01:13:44 +08:00
|
|
|
];
|
|
|
|
|
2018-05-22 18:05:16 +08:00
|
|
|
validQueries.forEach(query => {
|
2019-12-24 01:19:08 +08:00
|
|
|
it(query, function () {
|
2018-05-22 01:13:44 +08:00
|
|
|
const result = queryInfo.getFormatFromCopyQuery(query);
|
2019-12-26 21:01:18 +08:00
|
|
|
assert.strictEqual(result, 'TEXT');
|
2018-05-22 01:13:44 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
describe('binary', function () {
|
2018-05-22 18:05:16 +08:00
|
|
|
const validQueries = [
|
2019-12-24 01:19:08 +08:00
|
|
|
'COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT BINARY)'
|
2018-05-22 01:13:44 +08:00
|
|
|
];
|
|
|
|
|
2018-05-22 18:05:16 +08:00
|
|
|
validQueries.forEach(query => {
|
2019-12-24 01:19:08 +08:00
|
|
|
it(query, function () {
|
2018-05-22 01:13:44 +08:00
|
|
|
const result = queryInfo.getFormatFromCopyQuery(query);
|
2019-12-26 21:01:18 +08:00
|
|
|
assert.strictEqual(result, 'BINARY');
|
2018-05-22 01:13:44 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-05-22 20:16:22 +08:00
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
describe('should fail', function () {
|
2018-05-22 20:16:22 +08:00
|
|
|
const validQueries = [
|
2019-12-24 01:19:08 +08:00
|
|
|
'COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT ERROR)',
|
|
|
|
'SELECT * from copy_endpoints_test'
|
2018-05-22 20:16:22 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
validQueries.forEach(query => {
|
2019-12-24 01:19:08 +08:00
|
|
|
it(query, function () {
|
2018-05-22 20:16:22 +08:00
|
|
|
const result = queryInfo.getFormatFromCopyQuery(query);
|
|
|
|
assert.strictEqual(result, false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-05-22 01:13:44 +08:00
|
|
|
});
|
|
|
|
});
|