Skip to content

Commit

Permalink
Add integration tests for Oracle (#124)
Browse files Browse the repository at this point in the history
* Try adding oracle

* Fix for format

* Fix pull request yaml format

* Try with setting random password

* Always append semicolon

* Only run oracle with go

* Reset tests

* Add comments about oracle

* Bump http timeout, fix oracle query

* Try no semicolon

* Only run db test

* Debugging oracle results

* Format

* More error handling when converting

* More debugging

* More debugging

* Start setting up oracle client lib

* More debugging

* Add oracle test script

* Add from

* Just skip float tests for now

* Fix syntax

* Only test oracle with go runner
  • Loading branch information
eatonphil committed Dec 21, 2021
1 parent 61c4bfb commit e200d3a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pull_requests.yml
Expand Up @@ -28,6 +28,8 @@ jobs:
# Start up sqlserver
- run: docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=1StrongPwd!!" -p 1433:1433 -d mcr.microsoft.com/mssql/server:2019-latest
# Start up oracle database
- run: docker run -e ORACLE_RANDOM_PASSWORD="y" -e "APP_USER=test" -e "APP_USER_PASSWORD=test" -p 1521:1521 -d gvenzl/oracle-xe:latest

- run: ./scripts/ci/prepare_linux.sh --integration-tests
- run: yarn format
Expand Down
21 changes: 20 additions & 1 deletion desktop/panel/database.test.js
Expand Up @@ -30,6 +30,13 @@ const DATABASES = [
query:
'SELECT 1 AS `1`, 2.2 AS `2`, true AS `true`, "string" AS `string`, CAST("2021-01-01" AS DATE) AS `date`',
},
{
type: 'oracle',
query:
// Oracle does not have true/false literals
// Oracle doesn't support no-FROM. But the dual table is a dummy table.
`SELECT 1 AS "1", 2.2 AS "2", 1 AS "true", 'string' AS "string", TO_DATE('2021-01-01','YYYY-MM-DD') AS "date" FROM dual`,
},
{
type: 'postgres',
query: 'SELECT name, CAST(age AS INT) - 10 AS age FROM DM_getPanel(0)',
Expand All @@ -50,6 +57,9 @@ const vendorOverride = {
postgres: {
address: 'localhost?sslmode=disable',
},
oracle: {
database: 'XEPDB1',
},
sqlserver: {
address: 'localhost',
username: 'sa',
Expand All @@ -60,6 +70,11 @@ const vendorOverride = {

for (const subprocess of RUNNERS) {
for (const t of DATABASES) {
// Only test Oracle with the Go runner for now
if (t.type === 'oracle' && !subprocess?.go) {
continue;
}

describe(
t.type +
' running via ' +
Expand Down Expand Up @@ -107,7 +122,11 @@ for (const subprocess of RUNNERS) {
// These database drivers are all over the place between Node and Go.
// Close enough is fine I guess.
expect(v[0]['1']).toBe(1);
expect(String(v[0]['2'])).toBe('2.2');
// TODO: fix the Oracle driver reading floats as zero
// https://github.com/sijms/go-ora/issues/135
if (t.type !== 'oracle') {
expect(String(v[0]['2'])).toBe('2.2');
}
expect(v[0]['true'] == '1').toBe(true);
expect(v[0].string).toBe('string');
expect(new Date(v[0].date)).toStrictEqual(
Expand Down
6 changes: 3 additions & 3 deletions desktop/panel/http.test.js
Expand Up @@ -66,7 +66,7 @@ for (const subprocessName of RUNNERS) {
},
{ evalPanels: true, subprocessName }
);
}, 10_000);
}, 30_000);
}
);

Expand Down Expand Up @@ -121,7 +121,7 @@ for (const subprocessName of RUNNERS) {
},
{ evalPanels: true, subprocessName }
);
}, 10_000);
}, 30_000);
}
);
}
Expand Down Expand Up @@ -201,7 +201,7 @@ for (const subprocessName of RUNNERS) {
},
{ evalPanels: true, subprocessName, servers }
);
}, 10_000);
}, 30_000);
}
);
}
Expand Down
21 changes: 18 additions & 3 deletions runner/database.go
Expand Up @@ -215,11 +215,17 @@ func writeRowFromDatabase(dbInfo DatabaseConnectorInfoDatabase, w *JSONArrayWrit
// Do conversion for ints, floats, and bools
case "INT", "BIGINT", "INT1", "INT2", "INT4", "INT8":
if dbInfo.Type == "mysql" {
row[col], _ = strconv.Atoi(string(row[col].([]uint8)))
row[col], err = strconv.Atoi(string(row[col].([]uint8)))
if err != nil {
return edsef("Failed to convert int (%s): %s", t, err)
}
}
case "REAL", "BIGREAL", "NUMERIC", "DECIMAL":
case "REAL", "BIGREAL", "NUMERIC", "DECIMAL", "FLOAT", "NUMBER":
if bs, ok := row[col].([]uint8); ok {
row[col], _ = strconv.ParseFloat(string(bs), 64)
row[col], err = strconv.ParseFloat(string(bs), 64)
if err != nil {
return edsef("Failed to convert float (%s): %s", t, err)
}
}
case "BOOLEAN", "BOOL":
row[col] = string(bs) == "true" || string(bs) == "TRUE" || string(bs) == "1"
Expand Down Expand Up @@ -293,6 +299,15 @@ func evalDatabasePanel(project *ProjectState, pageIndex int, panel *PanelInfo) e
return err
}

// Require queries end with semicolon primarily for Oracle
// that blows up without this. This will still blow up if
// there's no semicolon and there are comments.
// e.g. `SELECT 1 -- flubber` -> `SELECT 1 -- flubber;`
//qWithoutWs := strings.TrimSpace(query)
//if qWithoutWs[len(qWithoutWs)-1] != ';' {
// query += ";"
//}

server, err := getServer(project, panel.ServerId)
if err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions scripts/ci/prepare_linux_integration_test_setup_only.sh
Expand Up @@ -19,6 +19,10 @@ ssh-keygen -q -t rsa -N '' -f ~/.ssh/id_rsa <<<y >/dev/null 2>&1
cp ~/.ssh/id_rsa.pub ~/.ssh/known_hosts
cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys

# Install Oracle client library, instructions here: https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html#ic_x64_inst
curl -LO https://download.oracle.com/otn_software/linux/instantclient/instantclient-basic-linuxx64.zip
unzip instantclient-basic-linuxx64.zip

# Install xvfb for headless gui
sudo apt-get install -y xvfb

Expand Down

0 comments on commit e200d3a

Please sign in to comment.