Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/api/configuration/storage/CodeForIStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ConnectionData } from "../../types";
import { BaseStorage } from "./BaseStorage";

const SERVER_SETTINGS_CACHE_PREFIX = `serverSettingsCache_`;
const SERVER_SETTINGS_CACHE_KEY = (name: string) => SERVER_SETTINGS_CACHE_PREFIX + name;
export const SERVER_SETTINGS_CACHE_KEY = (name: string) => SERVER_SETTINGS_CACHE_PREFIX + name;
const PREVIOUS_SEARCH_TERMS_KEY = `prevSearchTerms`;
const PREVIOUS_FIND_TERMS_KEY = `prevFindTerms`;
const PREVIOUS_DOWNLOAD_LOCATION = `previousDownloadLocation`;
Expand Down
17 changes: 11 additions & 6 deletions src/api/tests/.env.sample
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# IBM i connection
VITE_SERVER=
VITE_DB_USER=
VITE_DB_PASS=
VITE_DB_PORT=22
VITE_TEMP_LIB=
#VITE_IASP=
#VITE_CONNECTION_TIMEOUT=25000
# SSH Key authentication (optional - leave VITE_DB_PASS empty if using key)
# SSH Key authentication (optional - leave VITE_DB_PASS empty if using SSH key)
#VITE_PRIVATE_KEY_PATH=~/.ssh/id_rsa
#VITE_PASSPHRASE=
# SSH Agent authentication (optional - leave VITE_DB_PASS and VITE_PRIVATE_KEY_PATH empty if using agent)
#VITE_USE_SSH_AGENT=true
# SSH Agent authentication (optional - leave VITE_DB_PASS and VITE_PRIVATE_KEY_PATH empty if using SSH agent)
#VITE_USE_SSH_AGENT=true

# IBM i connection settings
VITE_TEMP_LIB=ILEDITOR
#VITE_IASP=

# Test settings
VITE_CONNECTION_TIMEOUT=25000
144 changes: 0 additions & 144 deletions src/api/tests/connection.ts

This file was deleted.

30 changes: 0 additions & 30 deletions src/api/tests/setup.ts

This file was deleted.

98 changes: 98 additions & 0 deletions src/api/tests/setup/connection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { ConnectionData } from "../../types";
import IBMi, { ConnectionErrorCode } from "../../IBMi";
import { extensionComponentRegistry } from "../../components/manager";
import { Mapepire } from "../../components/mapepire";
import { CodeForIStorage } from "../../configuration/storage/CodeForIStorage";
import { JsonConfig, JsonStorage } from "./json";
import { TestEnv } from "./env";
import { CustomCLI } from "../components/customCli";

export const envVars = TestEnv.getEnvironmentVariables();
const testStorage = new JsonStorage();
const testConfig = new JsonConfig();

export async function newConnection(reloadSettings?: boolean) {
// Setup credentials
const credentials: ConnectionData = {
name: `${envVars.VITE_DB_USER}@${envVars.VITE_SERVER}`,
host: envVars.VITE_SERVER,
username: envVars.VITE_DB_USER,
port: envVars.VITE_DB_PORT,
password: envVars.VITE_DB_PASS,
privateKeyPath: envVars.VITE_PRIVATE_KEY_PATH,
passphrase: envVars.VITE_PASSPHRASE,
useSshAgent: envVars.VITE_USE_SSH_AGENT
};

// Setup Code4i virtual storage and config
IBMi.GlobalStorage = new CodeForIStorage(testStorage);
IBMi.connectionManager.configMethod = testConfig;

// Override temp library and IASP in Code4i config if set
const tempLib = envVars.VITE_TEMP_LIB;
const iasp = envVars.VITE_IASP;
const config = await IBMi.connectionManager.load(credentials.name);
let updateConfig = false;
if (config.tempLibrary !== tempLib) {
config.tempLibrary = tempLib;
updateConfig = true;
}
if (config.iasp !== iasp) {
config.iasp = iasp;
updateConfig = true;
}
if (updateConfig) {
await IBMi.connectionManager.update(config);
}

// Setup components
const mapepire = new Mapepire("Code for IBM i - Unit tests", async () => envVars.VITE_DB_PASS);
const testingId = `testing`;
extensionComponentRegistry.registerComponent(testingId, mapepire);
extensionComponentRegistry.registerComponent(testingId, new CustomCLI());
const componentId = `toBeDeleted`;
extensionComponentRegistry.registerComponent(testingId, new CustomCLI(componentId));
extensionComponentRegistry.disableComponent(testingId, componentId);

// Connect to IBM i
const connection = new IBMi();
connection.appendOutput = async (data: string) => { };
const result = await connection.connect(
credentials,
{
callbacks: {
message: (type: string, message: string) => {
// console.log(`${type.padEnd(10)} ${message}`);
},
progress: ({ message }: { message: string }) => {
// console.log(`PROGRESS: ${message}`);
},
inputBox: async (prompt: string, placeHolder: string, ignoreFocusOut: boolean) => {
// console.log(`PROMPT: ${prompt}`);
// console.log(`PLACEHOLDER: ${placeHolder}`);
// console.log(`IGNORE FOCUS OUT: ${ignoreFocusOut}`);
return undefined;
},
uiErrorHandler: async (connection: IBMi, error: ConnectionErrorCode, data?: any) => {
console.log(`Connection warning: ${error}: ${JSON.stringify(data)}`);
return false;
},
},
reloadServerSettings: reloadSettings,
reconnecting: false
}
);
if (!result.success) {
throw new Error(`Failed to connect to IBM i${result.error ? `: ${result.error}` : '!'}`);
}

return connection;
}

export async function disposeConnection(connection?: IBMi) {
if (connection) {
await connection.disconnect();
testStorage.save();
testConfig.save();
}
}
Loading
Loading