-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added task SDK token support; added a default value for the issue source property.
- Loading branch information
1 parent
6a8ea3c
commit d1d66d3
Showing
13 changed files
with
280 additions
and
11 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,180 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
import assert = require('assert'); | ||
import * as testutil from './testutil'; | ||
import * as tl from '../_build/task'; | ||
import { IssueSource, _loadData } from '../_build/internal'; | ||
|
||
|
||
describe('Task Issue command test without token', function () { | ||
|
||
before(function (done) { | ||
try { | ||
testutil.initialize(); | ||
} catch (err) { | ||
assert.fail('Failed to load task lib: ' + err.message); | ||
} | ||
|
||
done(); | ||
}); | ||
|
||
after(function (done) { | ||
done(); | ||
}); | ||
|
||
it('adds issue sources for task.issue messages', function (done) { | ||
this.timeout(1000); | ||
|
||
var stdStream = testutil.createStringStream(); | ||
tl.setStdStream(stdStream); | ||
tl.error("Test error", IssueSource.CustomerScript) | ||
tl.warning("Test warning", IssueSource.TaskInternal) | ||
|
||
var expected = testutil.buildOutput( | ||
['##vso[task.issue type=error;source=CustomerScript;]Test error', | ||
'##vso[task.issue type=warning;source=TaskInternal;]Test warning']); | ||
|
||
var output = stdStream.getContents(); | ||
|
||
assert.equal(output, expected); | ||
|
||
done(); | ||
}) | ||
|
||
it('adds the default "TaskInternal" source for task.issue command', function (done) { | ||
this.timeout(1000); | ||
|
||
var stdStream = testutil.createStringStream(); | ||
tl.setStdStream(stdStream); | ||
tl.error("Test error"); | ||
tl.warning("Test warning"); | ||
|
||
var expected = testutil.buildOutput( | ||
['##vso[task.issue type=error;source=TaskInternal;]Test error', | ||
'##vso[task.issue type=warning;source=TaskInternal;]Test warning']); | ||
|
||
var output = stdStream.getContents(); | ||
|
||
assert.equal(output, expected); | ||
|
||
done(); | ||
}) | ||
|
||
it('adds the default "TaskInternal" source for the setResult', function (done) { | ||
this.timeout(1000); | ||
|
||
var stdStream = testutil.createStringStream(); | ||
tl.setStdStream(stdStream); | ||
tl.setResult(tl.TaskResult.Failed, 'failed msg'); | ||
|
||
var expected = testutil.buildOutput( | ||
['##vso[task.debug]task result: Failed', | ||
'##vso[task.issue type=error;source=TaskInternal;]failed msg', | ||
'##vso[task.complete result=Failed;]failed msg']); | ||
|
||
var output = stdStream.getContents(); | ||
|
||
assert.equal(output, expected); | ||
|
||
done(); | ||
}) | ||
}); | ||
|
||
describe('Task Issue command test with token', function () { | ||
|
||
before(function (done) { | ||
try { | ||
testutil.initialize(); | ||
} catch (err) { | ||
assert.fail('Failed to load task lib: ' + err.message); | ||
} | ||
|
||
process.env['TASK_SDK_COMMAND_TOKEN'] = 'test_token123'; | ||
_loadData(); | ||
done(); | ||
}); | ||
|
||
after(function (done) { | ||
delete process.env['TASK_SDK_COMMAND_TOKEN']; | ||
_loadData(); | ||
done(); | ||
}); | ||
|
||
it('removes the token from env var', function (done) { | ||
this.timeout(1000); | ||
|
||
assert.equal(process.env['TASK_SDK_COMMAND_TOKEN'], undefined); | ||
|
||
done(); | ||
}) | ||
|
||
it('doesn\'t provide the token using task variables', function (done) { | ||
this.timeout(1000); | ||
|
||
process.env['AGENT_VERSION'] = '2.115.0' | ||
let variable = tl.getVariable('TASK_SDK_COMMAND_TOKEN'); | ||
let taskVariable = tl.getTaskVariable('TASK_SDK_COMMAND_TOKEN'); | ||
assert.equal(variable, undefined); | ||
assert.equal(taskVariable, undefined); | ||
|
||
done(); | ||
}) | ||
|
||
it('adds the token for task.issue messages', function (done) { | ||
this.timeout(1000); | ||
|
||
var stdStream = testutil.createStringStream(); | ||
tl.setStdStream(stdStream); | ||
tl.error("Test error", IssueSource.CustomerScript) | ||
tl.warning("Test warning", IssueSource.TaskInternal) | ||
|
||
var expected = testutil.buildOutput( | ||
['##vso[task.issue type=error;source=CustomerScript;token=test_token123;]Test error', | ||
'##vso[task.issue type=warning;source=TaskInternal;token=test_token123;]Test warning']); | ||
|
||
var output = stdStream.getContents(); | ||
|
||
assert.equal(output, expected); | ||
|
||
done(); | ||
}) | ||
|
||
it('adds the default "TaskInternal" source for task.issue command', function (done) { | ||
this.timeout(1000); | ||
|
||
var stdStream = testutil.createStringStream(); | ||
tl.setStdStream(stdStream); | ||
tl.error("Test error"); | ||
tl.warning("Test warning"); | ||
|
||
var expected = testutil.buildOutput( | ||
['##vso[task.issue type=error;source=TaskInternal;token=test_token123;]Test error', | ||
'##vso[task.issue type=warning;source=TaskInternal;token=test_token123;]Test warning']); | ||
|
||
var output = stdStream.getContents(); | ||
|
||
assert.equal(output, expected); | ||
|
||
done(); | ||
}) | ||
|
||
it('adds the default "TaskInternal" source for the setResult', function (done) { | ||
this.timeout(1000); | ||
|
||
var stdStream = testutil.createStringStream(); | ||
tl.setStdStream(stdStream); | ||
tl.setResult(tl.TaskResult.Failed, 'failed msg'); | ||
|
||
var expected = testutil.buildOutput( | ||
['##vso[task.debug]task result: Failed', | ||
'##vso[task.issue type=error;source=TaskInternal;token=test_token123;]failed msg', | ||
'##vso[task.complete result=Failed;]failed msg']); | ||
|
||
var output = stdStream.getContents(); | ||
|
||
assert.equal(output, expected); | ||
|
||
done(); | ||
}) | ||
}); |
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
28 changes: 28 additions & 0 deletions
28
powershell/Tests/L0/Write-LoggingCommand.WritesTaskIssue.ps1
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,28 @@ | ||
[CmdletBinding()] | ||
param() | ||
|
||
# Arrange. | ||
. $PSScriptRoot\..\lib\Initialize-Test.ps1 | ||
Invoke-VstsTaskScript -ScriptBlock { | ||
$vstsModule = Get-Module -Name VstsTaskSdk | ||
|
||
# 1 | ||
$actual = & $vstsModule Write-TaskError -Message "test error" -AsOutput | ||
$expected = "##vso[task.logissue source=TaskInternal;type=error]test error" | ||
Assert-TaskIssueMessagesAreEqual $expected $actual "The default 'TastInternal' source was added for errors." | ||
|
||
# 2 | ||
$actual = & $vstsModule Write-TaskWarning -Message "test warning" -AsOutput | ||
$expected = "##vso[task.logissue source=TaskInternal;type=warning]test warning" | ||
Assert-TaskIssueMessagesAreEqual $expected $actual "The default 'TastInternal' source was added for warnings." | ||
|
||
#3 | ||
$actual = & $vstsModule Write-TaskError -Message "test error" -IssueSource $IssueSources.CustomerScript -AsOutput | ||
$expected = "##vso[task.logissue source=CustomerScript;type=error]test error" | ||
Assert-TaskIssueMessagesAreEqual $expected $actual "Adds the specified issue source for errors." | ||
|
||
#4 | ||
$actual = & $vstsModule Write-TaskWarning -Message "test warning" -IssueSource $IssueSources.CustomerScript -AsOutput | ||
$expected = "##vso[task.logissue source=CustomerScript;type=warning]test warning" | ||
Assert-TaskIssueMessagesAreEqual $expected $actual "Adds the specified issue source for warnings." | ||
} |
37 changes: 37 additions & 0 deletions
37
powershell/Tests/L0/Write-LoggingCommand.WritesTaskIssueWithToken.ps1
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,37 @@ | ||
[CmdletBinding()] | ||
param() | ||
|
||
$env:TASK_SDK_COMMAND_TOKEN = "test_token123" | ||
|
||
# Arrange. | ||
. $PSScriptRoot\..\lib\Initialize-Test.ps1 | ||
Invoke-VstsTaskScript -ScriptBlock { | ||
$vstsModule = Get-Module -Name VstsTaskSdk | ||
|
||
# 1 | ||
Assert-AreEqual $null $env:TASK_SDK_COMMAND_TOKEN "SDK removes the token after loading." | ||
|
||
# 2 | ||
$actual = & $vstsModule Get-TaskVariable -Name "TASK_SDK_COMMAND_TOKEN" | ||
Assert-AreEqual $null $actual "The token is inaccessible using task variables." | ||
|
||
# 3 | ||
$actual = & $vstsModule Write-TaskError -Message "test error" -AsOutput | ||
$expected = "##vso[task.logissue source=TaskInternal;type=error;token=test_token123]test error" | ||
Assert-TaskIssueMessagesAreEqual $expected $actual "The default 'TastInternal' source and the token were added for errors." | ||
|
||
# 4 | ||
$actual = & $vstsModule Write-TaskWarning -Message "test warning" -AsOutput | ||
$expected = "##vso[task.logissue source=TaskInternal;type=warning;token=test_token123]test warning" | ||
Assert-TaskIssueMessagesAreEqual $expected $actual "The default 'TastInternal' source and the token were added for warnings." | ||
|
||
# 5 | ||
$actual = & $vstsModule Write-TaskError -Message "test error" -IssueSource $IssueSources.CustomerScript -AsOutput | ||
$expected = "##vso[task.logissue source=CustomerScript;type=error;token=test_token123]test error" | ||
Assert-TaskIssueMessagesAreEqual $expected $actual "Adds the specified issue source and token for errors." | ||
|
||
# 6 | ||
$actual = & $vstsModule Write-TaskWarning -Message "test warning" -IssueSource $IssueSources.CustomerScript -AsOutput | ||
$expected = "##vso[task.logissue source=CustomerScript;type=warning;token=test_token123]test warning" | ||
Assert-TaskIssueMessagesAreEqual $expected $actual "Adds the specified issue source and token for warnings." | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"version": "0.19.0", | ||
"version": "0.20.0", | ||
"private": true, | ||
"scripts": { | ||
"build": "node make.js build", | ||
|