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)",
|
|
|
|
"COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT CSV)",
|
2018-06-05 00:15:28 +08:00
|
|
|
"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 => {
|
2018-05-22 01:13:44 +08:00
|
|
|
it(query, function() {
|
|
|
|
const result = queryInfo.getFormatFromCopyQuery(query);
|
|
|
|
assert.equal(result, 'CSV');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('text', 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 TEXT)",
|
|
|
|
"COPY copy_endpoints_test (id, name) FROM STDIN",
|
|
|
|
];
|
|
|
|
|
2018-05-22 18:05:16 +08:00
|
|
|
validQueries.forEach(query => {
|
2018-05-22 01:13:44 +08:00
|
|
|
it(query, function() {
|
|
|
|
const result = queryInfo.getFormatFromCopyQuery(query);
|
|
|
|
assert.equal(result, 'TEXT');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-05-22 18:05:16 +08:00
|
|
|
describe('binary', function() {
|
|
|
|
const validQueries = [
|
2018-05-22 01:13:44 +08:00
|
|
|
"COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT BINARY)",
|
|
|
|
];
|
|
|
|
|
2018-05-22 18:05:16 +08:00
|
|
|
validQueries.forEach(query => {
|
2018-05-22 01:13:44 +08:00
|
|
|
it(query, function() {
|
|
|
|
const result = queryInfo.getFormatFromCopyQuery(query);
|
|
|
|
assert.equal(result, 'BINARY');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-05-22 20:16:22 +08:00
|
|
|
|
|
|
|
describe('should fail', function() {
|
|
|
|
const validQueries = [
|
|
|
|
"COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT ERROR)",
|
|
|
|
"SELECT * from copy_endpoints_test"
|
|
|
|
];
|
|
|
|
|
|
|
|
validQueries.forEach(query => {
|
|
|
|
it(query, function() {
|
|
|
|
const result = queryInfo.getFormatFromCopyQuery(query);
|
|
|
|
assert.strictEqual(result, false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-05-22 01:13:44 +08:00
|
|
|
});
|
|
|
|
});
|