-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chaged the image path and removed (formerly Red Hat CodeReady Containers) text Signed-off-by: msivasubramaniaan <[email protected]> * removed odo analyze command Signed-off-by: msivasubramaniaan <[email protected]> * addressed review comments Signed-off-by: msivasubramaniaan <[email protected]> * added alizer test Signed-off-by: msivasubramaniaan <[email protected]> * fixed no-unused-vars error Signed-off-by: msivasubramaniaan <[email protected]> * fixed no-unused-vars error Signed-off-by: msivasubramaniaan <[email protected]> * fixed no-unused-vars error Signed-off-by: msivasubramaniaan <[email protected]> * fixed no-unused-vars error Signed-off-by: msivasubramaniaan <[email protected]> * fixed no-unused-vars error Signed-off-by: msivasubramaniaan <[email protected]> * fixed no-unused-vars error Signed-off-by: msivasubramaniaan <[email protected]> * fixed test case fails Signed-off-by: msivasubramaniaan <[email protected]> * added deleteComponentConfiguration Signed-off-by: msivasubramaniaan <[email protected]> * fixed mapping component description Signed-off-by: msivasubramaniaan <[email protected]> * addressed review comments Signed-off-by: msivasubramaniaan <[email protected]> * addressed review comments Signed-off-by: msivasubramaniaan <[email protected]> --------- Signed-off-by: msivasubramaniaan <[email protected]>
- Loading branch information
1 parent
4ff8310
commit 44ebc51
Showing
9 changed files
with
256 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/*----------------------------------------------------------------------------------------------- | ||
* Copyright (c) Red Hat, Inc. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE file in the project root for license information. | ||
*-----------------------------------------------------------------------------------------------*/ | ||
|
||
import { CommandText } from '../base/command'; | ||
import { CliChannel } from '../cli'; | ||
import { Uri } from 'vscode'; | ||
import { CliExitData } from '../util/childProcessUtil'; | ||
import { AlizerAnalyzeResponse } from './types'; | ||
|
||
/** | ||
* A wrapper around the `alizer` CLI tool. | ||
* | ||
* This class is a stateless singleton. | ||
* This makes it easier to stub its methods than if it were a bunch of directly exported functions. | ||
*/ | ||
export class Alizer { | ||
private static INSTANCE = new Alizer(); | ||
|
||
static get Instance() { | ||
return Alizer.INSTANCE; | ||
} | ||
|
||
public async alizerAnalyze(currentFolderPath: Uri): Promise<AlizerAnalyzeResponse> { | ||
const cliData: CliExitData = await CliChannel.getInstance().executeTool( | ||
new CommandText('alizer', `devfile ${currentFolderPath.fsPath}`), undefined, false | ||
); | ||
if (cliData.error || cliData.stderr.length > 0) { | ||
return undefined; | ||
} | ||
const parse = JSON.parse(cliData.stdout) as AlizerAnalyzeResponse[]; | ||
return parse[0]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/*----------------------------------------------------------------------------------------------- | ||
* Copyright (c) Red Hat, Inc. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE file in the project root for license information. | ||
*-----------------------------------------------------------------------------------------------*/ | ||
|
||
export interface Version { | ||
SchemaVersion: number; | ||
Default: boolean; | ||
Version: string; | ||
} | ||
|
||
export interface AlizerAnalyzeResponse { | ||
Name: string; | ||
Language: string; | ||
ProjectType: string; | ||
Tags: string[]; | ||
Versions: Version[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/*----------------------------------------------------------------------------------------------- | ||
* Copyright (c) Red Hat, Inc. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE file in the project root for license information. | ||
*-----------------------------------------------------------------------------------------------*/ | ||
import { fail } from 'assert'; | ||
import { expect } from 'chai'; | ||
import * as fs from 'fs/promises'; | ||
import { suite, suiteSetup } from 'mocha'; | ||
import * as tmp from 'tmp'; | ||
import * as path from 'path'; | ||
import { promisify } from 'util'; | ||
import { Uri, workspace } from 'vscode'; | ||
import { Oc } from '../../src/oc/ocWrapper'; | ||
import { Odo } from '../../src/odo/odoWrapper'; | ||
import { LoginUtil } from '../../src/util/loginUtil'; | ||
import { Alizer } from '../../src/alizer/alizerWrapper'; | ||
|
||
suite('./alizer/alizerWrapper.ts', function () { | ||
const isOpenShift: boolean = Boolean(parseInt(process.env.IS_OPENSHIFT, 10)) || false; | ||
const clusterUrl = process.env.CLUSTER_URL || 'https://api.crc.testing:6443'; | ||
const username = process.env.CLUSTER_USER || 'developer'; | ||
const password = process.env.CLUSTER_PASSWORD || 'developer'; | ||
|
||
suiteSetup(async function () { | ||
if (isOpenShift) { | ||
try { | ||
await LoginUtil.Instance.logout(); | ||
} catch { | ||
// do nothing | ||
} | ||
await Oc.Instance.loginWithUsernamePassword(clusterUrl, username, password); | ||
} | ||
}); | ||
|
||
suiteTeardown(async function () { | ||
// ensure projects are cleaned up | ||
try { | ||
await Oc.Instance.deleteProject('my-test-project-1'); | ||
} catch { | ||
// do nothing | ||
} | ||
try { | ||
await Oc.Instance.deleteProject('my-test-project-2'); | ||
} catch { | ||
// do nothing | ||
} | ||
|
||
if (isOpenShift) { | ||
await LoginUtil.Instance.logout(); | ||
} | ||
}); | ||
|
||
suite('analyse folder', function () { | ||
const project1 = 'my-test-project-1'; | ||
|
||
let tmpFolder1: Uri; | ||
let tmpFolder2: Uri; | ||
|
||
suiteSetup(async function () { | ||
await Oc.Instance.createProject(project1); | ||
tmpFolder1 = Uri.parse(await promisify(tmp.dir)()); | ||
tmpFolder2 = Uri.parse(await promisify(tmp.dir)()); | ||
await Odo.Instance.createComponentFromFolder( | ||
'nodejs', | ||
undefined, | ||
'component1', | ||
tmpFolder1, | ||
'nodejs-starter', | ||
); | ||
await Odo.Instance.createComponentFromFolder( | ||
'go', | ||
undefined, | ||
'component2', | ||
tmpFolder2, | ||
'go-starter', | ||
); | ||
}); | ||
|
||
suiteTeardown(async function () { | ||
if (isOpenShift) { | ||
await Oc.Instance.loginWithUsernamePassword(clusterUrl, username, password); | ||
} | ||
const newWorkspaceFolders = workspace.workspaceFolders.filter((workspaceFolder) => { | ||
const fsPath = workspaceFolder.uri.fsPath; | ||
return (fsPath !== tmpFolder1.fsPath && fsPath !== tmpFolder2.fsPath); | ||
}); | ||
workspace.updateWorkspaceFolders(0, workspace.workspaceFolders.length, ...newWorkspaceFolders); | ||
await fs.rm(tmpFolder1.fsPath, { force: true, recursive: true }); | ||
await fs.rm(tmpFolder2.fsPath, { force: true, recursive: true }); | ||
await Oc.Instance.deleteProject(project1); | ||
}); | ||
|
||
test('analyze()', async function () { | ||
const analysis1 = await Alizer.Instance.alizerAnalyze(tmpFolder1); | ||
expect(analysis1).to.exist; | ||
expect(analysis1.Name).to.equal('nodejs'); | ||
const analysis2 = await Alizer.Instance.alizerAnalyze(tmpFolder2); | ||
expect(analysis2).to.exist; | ||
expect(analysis2.Name).to.equal('go'); | ||
}); | ||
}); | ||
|
||
suite('create component', function() { | ||
|
||
const COMPONENT_TYPE = 'dotnet50'; | ||
|
||
let tmpFolder: string; | ||
|
||
suiteSetup(async function() { | ||
tmpFolder = await promisify(tmp.dir)(); | ||
}); | ||
|
||
suiteTeardown(async function() { | ||
await fs.rm(tmpFolder, { recursive: true, force: true }); | ||
}); | ||
|
||
test('createComponentFromTemplateProject()', async function() { | ||
await Odo.Instance.createComponentFromTemplateProject(tmpFolder, 'my-component', 8080, COMPONENT_TYPE, 'DefaultDevfileRegistry', 'dotnet50-example'); | ||
try { | ||
await fs.access(path.join(tmpFolder, 'devfile.yaml')); | ||
} catch { | ||
fail('Expected devfile to be created'); | ||
} | ||
}); | ||
|
||
test('analyze()', async function() { | ||
const analysis = await Alizer.Instance.alizerAnalyze(Uri.file(tmpFolder)); | ||
expect(analysis.Name).to.equal(COMPONENT_TYPE); | ||
}); | ||
|
||
}); | ||
|
||
test('deleteComponentConfiguration'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters