diff --git a/src/odo.ts b/src/odo.ts index a7b29fa4b..1b5f22ef6 100644 --- a/src/odo.ts +++ b/src/odo.ts @@ -96,7 +96,7 @@ export class Command { return `odo list --app ${app} --project ${project} -o json`; } static listCatalogComponents() { - return `odo catalog list components`; + return `odo catalog list components -o json`; } static listCatalogServices () { return `odo catalog list services`; @@ -706,7 +706,9 @@ export class OdoImpl implements Odo { public async getComponentTypes(): Promise { const result: cliInstance.CliExitData = await this.execute(Command.listCatalogComponents()); - return result.stdout.trim().split('\n').slice(1).map((value) => value.replace(/\*/g, '').trim().replace(/\s{1,}/g, '|').split('|')[0]); + const items = JSON.parse(result.stdout).items; + const componentTypes: Array = items.map((value: { metadata: { name: any; }; }) => value.metadata.name); + return componentTypes; } public async getComponentChildren(component: OpenShiftObject): Promise { @@ -764,11 +766,9 @@ export class OdoImpl implements Odo { public async getComponentTypeVersions(componentName: string) { const result: cliInstance.CliExitData = await this.execute(Command.listCatalogComponents()); - const versions = result.stdout.trim().split('\n').slice(1).filter((value) => { - const data = value.replace(/\*/g, '').trim().replace(/\s{1,}/g, '|').split('|'); - return data[0] === componentName; - }).map((value) => value.replace(/\*/g, '').trim().replace(/\s{1,}/g, '|').split('|')[2]); - return versions && versions.length > 0 ? versions[0].split(',') : []; + const items = JSON.parse(result.stdout).items; + const versions = items.find((value: { metadata: { name: string; }; }) => value.metadata.name === componentName); + return versions.spec.allTags; } public async getServiceTemplates(): Promise { diff --git a/test/unit/odo.test.ts b/test/unit/odo.test.ts index 89de95f55..62c9e26ad 100644 --- a/test/unit/odo.test.ts +++ b/test/unit/odo.test.ts @@ -391,17 +391,35 @@ suite("odo", () => { }); suite("catalog integration", () => { - const http = 'httpd'; const nodejs = 'nodejs'; - const python = 'python'; - const odoCatalog: string = [ - `NAME PROJECT TAGS`, - `${nodejs} openshift 1.0`, - `${python} openshift 1.0,2.0`, - `${http} openshift 2.2,2.3,latest` - ].join('\n'); - let result: string[]; + const odoCatalog = JSON.stringify({ + kind : "ComponentTypeList", + apiVersion : "odo.openshift.io/v1alpha1", + items: [ + { + kind : "ComponentType", + apiVersion : "odo.openshift.io/v1alpha1", + metadata: { + name : "nodejs", + namespace : "openshift", + creationTimestamp : null + }, + spec: { + allTags: [ + "0.10", + "10", + "4", + "6", + "8", + "8-RHOAR", + "latest", + ] + } + } + ] + }); + const catalogData: CliExitData = { error: null, stderr: '', @@ -410,32 +428,19 @@ suite("odo", () => { setup(async () => { sandbox.stub(odo.OdoImpl.prototype, 'execute').resolves(catalogData); - result = await odoCli.getComponentTypes(); }); - test("getComponentTypes returns correct number of component types", () => { - assert.equal(result.length, 3); + test("getComponentTypes returns correct component type names", async () => { + const result = await odoCli.getComponentTypes(); + expect(result.length).equals(1); + expect(result[0]).equals('nodejs'); }); - test("getComponentTypes returns correct component type names", () => { - const resultArray = result.filter((element: string) => { - return element === http || element === nodejs || element === python; - }); - assert.equal(resultArray.length, 3); - }); - - test("getComponentTypeVersions returns correct number of tags for component type", () => { - return Promise.all([ - odoCli.getComponentTypeVersions(nodejs).then((result)=> { - assert.equal(result.length, 1); - }), - odoCli.getComponentTypeVersions(python).then((result)=> { - assert.equal(result.length, 2); - }), - odoCli.getComponentTypeVersions(http).then((result)=> { - assert.equal(result.length, 3); - }) - ]); + test("getComponentTypeVersions returns correct number of tags for component type", async () => { + const result = await odoCli.getComponentTypeVersions(nodejs); + expect(result.length).equals(7); + expect(result[0]).equals("0.10"); + expect(result[6]).equals("latest"); }); });