-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add completion for 'conditionRef' field (#337)
* #244 add completion for 'conditionRef' field Signed-off-by: Yevhen Vydolob <[email protected]> * add tests Signed-off-by: Yevhen Vydolob <[email protected]>
- Loading branch information
Showing
5 changed files
with
91 additions
and
10 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,10 @@ | ||
/*----------------------------------------------------------------------------------------------- | ||
* 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 Snippet<T> { | ||
label: string; | ||
description?: string; | ||
body: T; | ||
} |
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,24 @@ | ||
/*----------------------------------------------------------------------------------------------- | ||
* Copyright (c) Red Hat, Inc. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE file in the project root for license information. | ||
*-----------------------------------------------------------------------------------------------*/ | ||
|
||
import { tkn, Command } from '../tkn'; | ||
|
||
|
||
export async function getTknConditionsSnippets(): Promise<string[]> { | ||
const result = await tkn.execute(Command.listConditions()); | ||
let data = []; | ||
if (result.error) { | ||
return []; | ||
} | ||
try { | ||
data = JSON.parse(result.stdout).items; | ||
} catch (ignore) { | ||
//show no pipelines if output is not correct json | ||
} | ||
|
||
let condition: string[] = data.map((value) => value.metadata.name); | ||
condition = [...new Set(condition)]; | ||
return condition; | ||
} |
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,40 @@ | ||
/*----------------------------------------------------------------------------------------------- | ||
* Copyright (c) Red Hat, Inc. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE file in the project root for license information. | ||
*-----------------------------------------------------------------------------------------------*/ | ||
import * as vscode from 'vscode'; | ||
import * as chai from 'chai'; | ||
import * as sinonChai from 'sinon-chai'; | ||
import * as sinon from 'sinon'; | ||
import { tkn } from '../../src/tkn'; | ||
import { getTknConditionsSnippets } from '../../src/yaml-support/tkn-conditions-provider'; | ||
|
||
const expect = chai.expect; | ||
chai.use(sinonChai); | ||
|
||
suite('ConditionRef provider', () => { | ||
|
||
const sandbox = sinon.createSandbox(); | ||
let tknExecute: sinon.SinonStub; | ||
|
||
setup(() => { | ||
tknExecute = sandbox.stub(tkn, 'execute'); | ||
}); | ||
|
||
teardown(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
test('should return empty array if any error on getting condition list', async () => { | ||
tknExecute.resolves({ error: 'Some error' }); | ||
const result = await getTknConditionsSnippets(); | ||
expect(result).eql([]); | ||
}); | ||
|
||
test('should array with condition names', async () => { | ||
tknExecute.resolves({ stdout: '{"items": [{"metadata": {"name": "foo"}}, {"metadata": {"name": "bar"}}]}' }); | ||
const result = await getTknConditionsSnippets(); | ||
expect(result).eql(['foo', 'bar']); | ||
}); | ||
|
||
}); |