Skip to content

Commit

Permalink
Merge branch 'codefori:master' into fix/object_filter_issue_2269
Browse files Browse the repository at this point in the history
  • Loading branch information
janfh authored Jan 22, 2025
2 parents a9c2a69 + a626a77 commit a3c3f42
Show file tree
Hide file tree
Showing 29 changed files with 2,078 additions and 2,157 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
on:
pull_request:
paths:
- 'src/api/**'

jobs:
tester:
environment: testing_environment
name: Test runner
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm ci
- run: npm run test
env:
VITE_SERVER: ${{ secrets.VITE_SERVER }}
VITE_DB_USER: ${{ secrets.VITE_DB_USER }}
VITE_DB_PASS: ${{ secrets.VITE_DB_PASS }}
VITE_DB_PORT: ${{ secrets.VITE_DB_PORT }}
3 changes: 2 additions & 1 deletion src/api/.env.sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
VITE_SERVER=
VITE_DB_USER=
VITE_DB_PASS=
VITE_DB_PORT=22
VITE_DB_PORT=22
#VITE_CONNECTION_TIMEOUT=25000
4 changes: 2 additions & 2 deletions src/api/IBMi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1098,12 +1098,12 @@ export default class IBMi {
*/
getTempRemote(key: string) {
if (this.tempRemoteFiles[key] !== undefined) {
console.log(`Using existing temp: ${this.tempRemoteFiles[key]}`);
// console.log(`Using existing temp: ${this.tempRemoteFiles[key]}`);
return this.tempRemoteFiles[key];
} else
if (this.config) {
let value = path.posix.join(this.config.tempDir, `vscodetemp-${Tools.makeid()}`);
console.log(`Using new temp: ${value}`);
// console.log(`Using new temp: ${value}`);
this.tempRemoteFiles[key] = value;
return value;
}
Expand Down
2 changes: 2 additions & 0 deletions src/api/tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
config.json
storage.json
10 changes: 0 additions & 10 deletions src/api/tests/a.test.ts

This file was deleted.

51 changes: 0 additions & 51 deletions src/api/tests/config.json

This file was deleted.

86 changes: 86 additions & 0 deletions src/api/tests/connection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import IBMi from "../IBMi";
import { CodeForIStorage } from "../configuration/storage/CodeForIStorage";
import { CustomQSh } from "../components/cqsh";
import path from "path";
import { CopyToImport } from "../components/copyToImport";
import { GetMemberInfo } from "../components/getMemberInfo";
import { GetNewLibl } from "../components/getNewLibl";
import { extensionComponentRegistry } from "../components/manager";
import { JsonConfig, JsonStorage } from "./testConfigSetup";

export const testStorage = new JsonStorage();
const testConfig = new JsonConfig();

export const CONNECTION_TIMEOUT = process.env.VITE_CONNECTION_TIMEOUT ? parseInt(process.env.VITE_CONNECTION_TIMEOUT) : 25000;

const ENV_CREDS = {
host: process.env.VITE_SERVER || `localhost`,
user: process.env.VITE_DB_USER,
password: process.env.VITE_DB_PASS,
port: parseInt(process.env.VITE_DB_PORT || `22`)
}

export async function newConnection() {
const virtualStorage = testStorage;

IBMi.GlobalStorage = new CodeForIStorage(virtualStorage);
IBMi.connectionManager.configMethod = testConfig;

await testStorage.load();
await testConfig.load();

const conn = new IBMi();

const customQsh = new CustomQSh();
const cqshPath = path.join(__dirname, `..`, `components`, `cqsh`, `cqsh`);
customQsh.setLocalAssetPath(cqshPath);

const testingId = `testing`;
extensionComponentRegistry.registerComponent(testingId, customQsh);
extensionComponentRegistry.registerComponent(testingId, new GetNewLibl());
extensionComponentRegistry.registerComponent(testingId, new GetMemberInfo());
extensionComponentRegistry.registerComponent(testingId, new CopyToImport());

const creds = {
host: ENV_CREDS.host!,
name: `testsystem`,
username: ENV_CREDS.user!,
password: ENV_CREDS.password!,
port: ENV_CREDS.port
};

// Override this so not to spam the console.
conn.appendOutput = (data) => {};

const result = await conn.connect(
creds,
{
message: (type: string, message: string) => {
// console.log(`${type.padEnd(10)} ${message}`);
},
progress: ({message}) => {
// console.log(`PROGRESS: ${message}`);
},
uiErrorHandler: async (connection, code, data) => {
console.log(`Connection warning: ${code}: ${JSON.stringify(data)}`);
return false;
},
}
);

if (!result.success) {
throw new Error(`Failed to connect to IBMi`);
}

return conn;
}

export function disposeConnection(conn?: IBMi) {
if (!conn) {
return;
}

conn.dispose();
testStorage.save();
testConfig.save();
}
11 changes: 0 additions & 11 deletions src/api/tests/env.ts

This file was deleted.

59 changes: 0 additions & 59 deletions src/api/tests/globalSetup.ts

This file was deleted.

18 changes: 18 additions & 0 deletions src/api/tests/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { TestProject } from "vitest/node";
import { disposeConnection, newConnection, testStorage } from "./connection";

export async function setup(project: TestProject) {
// You might pre-connect to simply create the configuration files.
// When the config files exist, it makes future connections just slightly faster.
// Mostly useful during the CI stage.
if (!testStorage.exists()) {
console.log(``);
console.log(`Testing connection before tests run since configs do not exist.`);

const conn = await newConnection();
disposeConnection(conn);

console.log(`Testing connection complete. Configs written.`);
console.log(``);
}
}
11 changes: 0 additions & 11 deletions src/api/tests/state.ts

This file was deleted.

38 changes: 0 additions & 38 deletions src/api/tests/storage.json

This file was deleted.

Loading

0 comments on commit a3c3f42

Please sign in to comment.