Skip to content

Commit

Permalink
Fixed 2 integration tests (#248)
Browse files Browse the repository at this point in the history
* Fixed 2 integration tests

- Fixed SQL input which is not available in HANA cloud in the createReadNumbersProc testing setup function.
- Also modified 'direct execute of ProcView with parameters' test to match the new change above for HANA cloud.
- When not running on HANA cloud, the behavior is the same as before.

* Fixed HANA cloud version check

- Updated tests to consider versions starting with "4." as HANA cloud rather than "4.5"
  • Loading branch information
he-is-harry authored Jan 16, 2025
1 parent e8ed441 commit f35c471
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 17 deletions.
4 changes: 2 additions & 2 deletions test/acceptance/db.Prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ describe('db', function () {
var p = metadata[0];
p.should.have.property('mode', 2);
// on HANA SP12 dataType = 9 (VARCHAR1)
// on HANA2 dataType = 29 (STRING)
p.should.have.property('dataType').which.is.oneOf(9, 29);
// on HANA2 dataType = 29 (STRING) or 30 (NSTRING)
p.should.have.property('dataType').which.is.oneOf(9, 29, 30);
p.should.have.property('ioType', 1);
callback(null, statement);
});
Expand Down
35 changes: 29 additions & 6 deletions test/acceptance/db.Query.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var Readable = stream.Readable;
var Writable = stream.Writable;
var ResultSet = lib.ResultSet;
var db = require('../db')();
var RemoteDB = require('../db/RemoteDB');

describe('db', function () {
before(db.init.bind(db));
Expand Down Expand Up @@ -120,18 +121,40 @@ describe('db', function () {
after(db.dropReadNumbersProc.bind(db));

it('should return the numbers between 3 and 5', function (done) {
var sql =
'select * from READ_NUMBERS_BETWEEN_VIEW with parameters (' +
'\'placeholder\' = (\'$$a$$\', \'3\'),' +
'\'placeholder\' = (\'$$b$$\', \'5\'))';
client.exec(sql, function (err, rows) {
function testOnPremise() {
var sql =
'select * from READ_NUMBERS_BETWEEN_VIEW with parameters (' +
'\'placeholder\' = (\'$$a$$\', \'3\'),' +
'\'placeholder\' = (\'$$b$$\', \'5\'))';
client.exec(sql, validateResult);
}

function testCloud() {
var sql = 'SELECT * FROM READ_NUMBERS_BETWEEN_FUNC (placeholder."A"=>\'3\', placeholder."B"=>\'5\')';
client.exec(sql, validateResult);
}

function validateResult(err, rows) {
if (err) {
return done(err);
}
rows.should.have.length(3);
rows.should.eql(db.numbers.slice(3, 6));
done();
});
}

if (db instanceof RemoteDB) {
db.getHanaBuildVersion(function (version) {
if (version !== undefined && version.startsWith("4.")) { // HANA Cloud
testCloud();
} else {
testOnPremise();
}
})
} else {
// Mock server models on premise
testOnPremise();
}
});
});

Expand Down
61 changes: 52 additions & 9 deletions test/db/RemoteDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ function RemoteDB(options) {
TestDB.call(this, options);
}

RemoteDB.prototype.getHanaBuildVersion = function getBuildVersion(cb) {
this.client.exec("SELECT VALUE FROM M_HOST_INFORMATION WHERE KEY='build_version'", function (err, rows) {
var version;
if (err) {
version = undefined;
} else {
version = rows[0].VALUE;
}
cb(version);
});
}

RemoteDB.prototype.createImages = function createImages(cb) {
this.images = TestDB.IMAGES.slice(0);
var values = this.images.map(function toParameters(img) {
Expand Down Expand Up @@ -112,15 +124,46 @@ RemoteDB.prototype.dropTable = function dropTable(tablename, cb) {
};

RemoteDB.prototype.createReadNumbersProc = function createReadNumbersProc(cb) {
var sql = [
'create procedure READ_NUMBERS_BETWEEN (in a int, in b int, out nums NUMBERS)',
'language sqlscript',
'reads sql data with result view READ_NUMBERS_BETWEEN_VIEW as',
'begin',
' nums = select * from NUMBERS where a between :a and :b;',
'end;'
].join('\n');
this.client.exec(sql, cb);
// Determine HANA build version
var self = this;
this.getHanaBuildVersion(function (version) {
if (version !== undefined && version.startsWith("4.")) { // Check if HANA cloud
// On HANA cloud, "create procedure with result view" is not supported, so a function is created instead
var sql = [
'create procedure READ_NUMBERS_BETWEEN (in a int, in b int, out nums TABLE (A int, B varchar(16)))',
'language sqlscript',
'reads sql data as',
'begin',
' nums = select * from NUMBERS where a between :a and :b;',
'end;'
].join('\n');

function createFunction () {
// ignore err
var sql2 = [
'create function READ_NUMBERS_BETWEEN_FUNC (IN a int, IN b int)',
' returns TABLE(A int, B varchar(16)) as',
'begin',
'call READ_NUMBERS_BETWEEN(:a, :b, tmp);',
' return :tmp;',
'end;'
].join('\n');
self.client.exec(sql2, cb);
}

self.client.exec(sql, createFunction);
} else {
var sql = [
'create procedure READ_NUMBERS_BETWEEN (in a int, in b int, out nums NUMBERS)',
'language sqlscript',
'reads sql data with result view READ_NUMBERS_BETWEEN_VIEW as',
'begin',
' nums = select * from NUMBERS where a between :a and :b;',
'end;'
].join('\n');
self.client.exec(sql, cb);
}
});
};

RemoteDB.prototype.dropReadNumbersProc = function dropReadNumbersProc(cb) {
Expand Down

0 comments on commit f35c471

Please sign in to comment.