Skip to content

Commit

Permalink
Move search tests
Browse files Browse the repository at this point in the history
Signed-off-by: worksofliam <[email protected]>
  • Loading branch information
worksofliam committed Jan 17, 2025
1 parent 4dc7e3a commit 1c2bbc6
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 110 deletions.
16 changes: 15 additions & 1 deletion src/api/tests/globalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { JsonConfig, JsonStorage } from "./testConfigSetup";
const testConfig = new JsonConfig();
const testStorage = new JsonStorage();

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

IBMi.GlobalStorage = new CodeForIStorage(virtualStorage);
Expand Down Expand Up @@ -68,6 +68,20 @@ beforeAll(async () => {
expect(result).toBeDefined();
expect(result.success).toBeTruthy();

return conn;
}

beforeAll(async () => {
const virtualStorage = testStorage;

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

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

const conn = await newConnection();

setConnection(conn);
}, 10000000);

Expand Down
88 changes: 45 additions & 43 deletions src/api/tests/suites/components.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,48 @@ import { GetNewLibl } from '../../components/getNewLibl';
import { Tools } from '../../Tools';
import { getConnection } from '../state';

describe('Component Tests', () => {
it('Get new libl', async () => {
const connection = getConnection();
const component = connection.getComponent<GetNewLibl>(GetNewLibl.ID);

if (component) {
const newLibl = await component.getLibraryListFromCommand(connection, `CHGLIBL CURLIB(SYSTOOLS)`);
expect(newLibl?.currentLibrary).toBe(`SYSTOOLS`);
} else {
throw new Error(`Component not installed`);
}
});

it('Check getMemberInfo', async () => {
const connection = getConnection();
const component = connection?.getComponent<GetMemberInfo>(GetMemberInfo.ID)!;

expect(component).toBeTruthy();

const memberInfoA = await component.getMemberInfo(connection, `QSYSINC`, `H`, `MATH`);
expect(memberInfoA).toBeTruthy();
expect(memberInfoA?.library).toBe(`QSYSINC`);
expect(memberInfoA?.file).toBe(`H`);
expect(memberInfoA?.name).toBe(`MATH`);
expect(memberInfoA?.extension).toBe(`C`);
expect(memberInfoA?.text).toBe(`STANDARD HEADER FILE MATH`);

const memberInfoB = await component.getMemberInfo(connection, `QSYSINC`, `H`, `MEMORY`);
expect(memberInfoB).toBeTruthy();
expect(memberInfoB?.library).toBe(`QSYSINC`);
expect(memberInfoB?.file).toBe(`H`);
expect(memberInfoB?.name).toBe(`MEMORY`);
expect(memberInfoB?.extension).toBe(`CPP`);
expect(memberInfoB?.text).toBe(`C++ HEADER`);

try {
await component.getMemberInfo(connection, `QSYSINC`, `H`, `OH_NONO`);
} catch (error: any) {
expect(error).toBeInstanceOf(Tools.SqlError);
expect(error.sqlstate).toBe("38501");
}
});
});
describe('Component Tests', () => {


it('Get new libl', async () => {
const connection = getConnection();
const component = connection.getComponent<GetNewLibl>(GetNewLibl.ID);

if (component) {
const newLibl = await component.getLibraryListFromCommand(connection, `CHGLIBL CURLIB(SYSTOOLS)`);
expect(newLibl?.currentLibrary).toBe(`SYSTOOLS`);
} else {
throw new Error(`Component not installed`);
}
});

it('Check getMemberInfo', async () => {
const connection = getConnection();
const component = connection?.getComponent<GetMemberInfo>(GetMemberInfo.ID)!;

expect(component).toBeTruthy();

const memberInfoA = await component.getMemberInfo(connection, `QSYSINC`, `H`, `MATH`);
expect(memberInfoA).toBeTruthy();
expect(memberInfoA?.library).toBe(`QSYSINC`);
expect(memberInfoA?.file).toBe(`H`);
expect(memberInfoA?.name).toBe(`MATH`);
expect(memberInfoA?.extension).toBe(`C`);
expect(memberInfoA?.text).toBe(`STANDARD HEADER FILE MATH`);

const memberInfoB = await component.getMemberInfo(connection, `QSYSINC`, `H`, `MEMORY`);
expect(memberInfoB).toBeTruthy();
expect(memberInfoB?.library).toBe(`QSYSINC`);
expect(memberInfoB?.file).toBe(`H`);
expect(memberInfoB?.name).toBe(`MEMORY`);
expect(memberInfoB?.extension).toBe(`CPP`);
expect(memberInfoB?.text).toBe(`C++ HEADER`);

try {
await component.getMemberInfo(connection, `QSYSINC`, `H`, `OH_NONO`);
} catch (error: any) {
expect(error).toBeInstanceOf(Tools.SqlError);
expect(error.sqlstate).toBe("38501");
}
});
});
2 changes: 1 addition & 1 deletion src/api/tests/suites/debug.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getJavaHome } from '../../configuration/DebugConfiguration';
describe('Debug engine tests', () => {
it('Check Java versions', async () => {
const connection = getConnection();

if (connection.remoteFeatures.jdk80) {
const jdk8 = getJavaHome(connection, '8');
expect(jdk8).toBe(connection.remoteFeatures.jdk80);
Expand Down
47 changes: 47 additions & 0 deletions src/api/tests/suites/search.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { describe, it, expect } from 'vitest';
import { parseFilter } from '../../Filter';
import { Search } from '../../Search';
import { getConnection } from '../state';

describe('Search Tests', {concurrent: true}, () => {
it('Single member search', async () => {
const result = await Search.searchMembers(getConnection(), "QSYSINC", "QRPGLESRC", "IBM", "CMRPG");
expect(result.term).toBe("IBM");
expect(result.hits.length).toBe(1);
const [hit] = result.hits;
expect(hit.lines.length).toBe(3);

const checkLine = (index: number, expectedNumber: number) => {
expect(hit.lines[index].number).toBe(expectedNumber);
expect(hit.lines[index].content).toContain(result.term);
}

checkLine(0, 7);
checkLine(1, 11);
checkLine(2, 13);
});

it('Generic name search', async () => {
const memberFilter = "E*";
const filter = parseFilter(memberFilter);
const result = await Search.searchMembers(getConnection(), "QSYSINC", "QRPGLESRC", "IBM", memberFilter);
expect(result.hits.every(hit => filter.test(hit.path.split("/").at(-1)!))).toBe(true);
expect(result.hits.every(hit => !hit.path.endsWith(`MBR`))).toBe(true);
});

it('Filtered members list search', async () => {
const library = "QSYSINC";
const sourceFile = "QRPGLESRC";
const memberFilter = "S*,T*";
const filter = parseFilter(memberFilter);
const checkNames = (names: string[]) => names.every(filter.test);

const members = await getConnection().getContent().getMemberList({ library, sourceFile, members: memberFilter });
expect(checkNames(members.map(member => member.name))).toBe(true);

const result = await Search.searchMembers(getConnection(), "QSYSINC", "QRPGLESRC", "SQL", members);
expect(result.hits.length).toBe(6);
expect(checkNames(result.hits.map(hit => hit.path.split("/").at(-1)!))).toBe(true);
expect(result.hits.every(hit => !hit.path.endsWith(`MBR`))).toBe(true);
});
});
2 changes: 0 additions & 2 deletions src/testing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { ActionSuite } from "./action";
import { ContentSuite } from "./content";
import { DeployToolsSuite } from "./deployTools";
import { EncodingSuite } from "./encoding";
import { SearchSuite } from "./search";
import { StorageSuite } from "./storage";
import { TestSuitesTreeProvider } from "./testCasesTree";
import { ToolsSuite } from "./tools";
Expand All @@ -16,7 +15,6 @@ const suites: TestSuite[] = [
ContentSuite,
DeployToolsSuite,
ToolsSuite,
SearchSuite,
StorageSuite,
EncodingSuite
]
Expand Down
63 changes: 0 additions & 63 deletions src/testing/search.ts

This file was deleted.

0 comments on commit 1c2bbc6

Please sign in to comment.