1
+ // Copyright (c) Microsoft. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import assert = require( 'assert' ) ;
5
+ import * as testutil from './testutil' ;
6
+ import * as tl from '../_build/task' ;
7
+ import { IssueSource , _loadData } from '../_build/internal' ;
8
+
9
+
10
+ describe ( 'Task Issue command test without token' , function ( ) {
11
+
12
+ before ( function ( done ) {
13
+ try {
14
+ testutil . initialize ( ) ;
15
+ } catch ( err ) {
16
+ assert . fail ( 'Failed to load task lib: ' + err . message ) ;
17
+ }
18
+
19
+ done ( ) ;
20
+ } ) ;
21
+
22
+ after ( function ( done ) {
23
+ done ( ) ;
24
+ } ) ;
25
+
26
+ it ( 'adds issue sources for task.issue messages' , function ( done ) {
27
+ this . timeout ( 1000 ) ;
28
+
29
+ var stdStream = testutil . createStringStream ( ) ;
30
+ tl . setStdStream ( stdStream ) ;
31
+ tl . error ( "Test error" , IssueSource . CustomerScript )
32
+ tl . warning ( "Test warning" , IssueSource . TaskInternal )
33
+
34
+ var expected = testutil . buildOutput (
35
+ [ '##vso[task.issue type=error;source=CustomerScript;]Test error' ,
36
+ '##vso[task.issue type=warning;source=TaskInternal;]Test warning' ] ) ;
37
+
38
+ var output = stdStream . getContents ( ) ;
39
+
40
+ assert . equal ( output , expected ) ;
41
+
42
+ done ( ) ;
43
+ } )
44
+
45
+ it ( 'adds the default "TaskInternal" source for task.issue command' , function ( done ) {
46
+ this . timeout ( 1000 ) ;
47
+
48
+ var stdStream = testutil . createStringStream ( ) ;
49
+ tl . setStdStream ( stdStream ) ;
50
+ tl . error ( "Test error" ) ;
51
+ tl . warning ( "Test warning" ) ;
52
+
53
+ var expected = testutil . buildOutput (
54
+ [ '##vso[task.issue type=error;source=TaskInternal;]Test error' ,
55
+ '##vso[task.issue type=warning;source=TaskInternal;]Test warning' ] ) ;
56
+
57
+ var output = stdStream . getContents ( ) ;
58
+
59
+ assert . equal ( output , expected ) ;
60
+
61
+ done ( ) ;
62
+ } )
63
+
64
+ it ( 'adds the default "TaskInternal" source for the setResult' , function ( done ) {
65
+ this . timeout ( 1000 ) ;
66
+
67
+ var stdStream = testutil . createStringStream ( ) ;
68
+ tl . setStdStream ( stdStream ) ;
69
+ tl . setResult ( tl . TaskResult . Failed , 'failed msg' ) ;
70
+
71
+ var expected = testutil . buildOutput (
72
+ [ '##vso[task.debug]task result: Failed' ,
73
+ '##vso[task.issue type=error;source=TaskInternal;]failed msg' ,
74
+ '##vso[task.complete result=Failed;]failed msg' ] ) ;
75
+
76
+ var output = stdStream . getContents ( ) ;
77
+
78
+ assert . equal ( output , expected ) ;
79
+
80
+ done ( ) ;
81
+ } )
82
+ } ) ;
83
+
84
+ describe ( 'Task Issue command test with token' , function ( ) {
85
+
86
+ before ( function ( done ) {
87
+ try {
88
+ testutil . initialize ( ) ;
89
+ } catch ( err ) {
90
+ assert . fail ( 'Failed to load task lib: ' + err . message ) ;
91
+ }
92
+
93
+ process . env [ 'TASK_SDK_COMMAND_TOKEN' ] = 'test_token123' ;
94
+ _loadData ( ) ;
95
+ done ( ) ;
96
+ } ) ;
97
+
98
+ after ( function ( done ) {
99
+ delete process . env [ 'TASK_SDK_COMMAND_TOKEN' ] ;
100
+ _loadData ( ) ;
101
+ done ( ) ;
102
+ } ) ;
103
+
104
+ it ( 'removes the token from env var' , function ( done ) {
105
+ this . timeout ( 1000 ) ;
106
+
107
+ assert . equal ( process . env [ 'TASK_SDK_COMMAND_TOKEN' ] , undefined ) ;
108
+
109
+ done ( ) ;
110
+ } )
111
+
112
+ it ( 'doesn\'t provide the token using task variables' , function ( done ) {
113
+ this . timeout ( 1000 ) ;
114
+
115
+ process . env [ 'AGENT_VERSION' ] = '2.115.0'
116
+ let variable = tl . getVariable ( 'TASK_SDK_COMMAND_TOKEN' ) ;
117
+ let taskVariable = tl . getTaskVariable ( 'TASK_SDK_COMMAND_TOKEN' ) ;
118
+ assert . equal ( variable , undefined ) ;
119
+ assert . equal ( taskVariable , undefined ) ;
120
+
121
+ done ( ) ;
122
+ } )
123
+
124
+ it ( 'adds the token for task.issue messages' , function ( done ) {
125
+ this . timeout ( 1000 ) ;
126
+
127
+ var stdStream = testutil . createStringStream ( ) ;
128
+ tl . setStdStream ( stdStream ) ;
129
+ tl . error ( "Test error" , IssueSource . CustomerScript )
130
+ tl . warning ( "Test warning" , IssueSource . TaskInternal )
131
+
132
+ var expected = testutil . buildOutput (
133
+ [ '##vso[task.issue type=error;source=CustomerScript;token=test_token123;]Test error' ,
134
+ '##vso[task.issue type=warning;source=TaskInternal;token=test_token123;]Test warning' ] ) ;
135
+
136
+ var output = stdStream . getContents ( ) ;
137
+
138
+ assert . equal ( output , expected ) ;
139
+
140
+ done ( ) ;
141
+ } )
142
+
143
+ it ( 'adds the default "TaskInternal" source for task.issue command' , function ( done ) {
144
+ this . timeout ( 1000 ) ;
145
+
146
+ var stdStream = testutil . createStringStream ( ) ;
147
+ tl . setStdStream ( stdStream ) ;
148
+ tl . error ( "Test error" ) ;
149
+ tl . warning ( "Test warning" ) ;
150
+
151
+ var expected = testutil . buildOutput (
152
+ [ '##vso[task.issue type=error;source=TaskInternal;token=test_token123;]Test error' ,
153
+ '##vso[task.issue type=warning;source=TaskInternal;token=test_token123;]Test warning' ] ) ;
154
+
155
+ var output = stdStream . getContents ( ) ;
156
+
157
+ assert . equal ( output , expected ) ;
158
+
159
+ done ( ) ;
160
+ } )
161
+
162
+ it ( 'adds the default "TaskInternal" source for the setResult' , function ( done ) {
163
+ this . timeout ( 1000 ) ;
164
+
165
+ var stdStream = testutil . createStringStream ( ) ;
166
+ tl . setStdStream ( stdStream ) ;
167
+ tl . setResult ( tl . TaskResult . Failed , 'failed msg' ) ;
168
+
169
+ var expected = testutil . buildOutput (
170
+ [ '##vso[task.debug]task result: Failed' ,
171
+ '##vso[task.issue type=error;source=TaskInternal;token=test_token123;]failed msg' ,
172
+ '##vso[task.complete result=Failed;]failed msg' ] ) ;
173
+
174
+ var output = stdStream . getContents ( ) ;
175
+
176
+ assert . equal ( output , expected ) ;
177
+
178
+ done ( ) ;
179
+ } )
180
+ } ) ;
0 commit comments