14
14
15
15
using System ;
16
16
using Microsoft . Azure . Batch ;
17
+ using Microsoft . Azure . Batch . Protocol . Entities ;
17
18
using Microsoft . Azure . Commands . Batch . Models ;
18
19
using Microsoft . Azure . Test ;
19
20
using Microsoft . WindowsAzure . Commands . ScenarioTest ;
@@ -26,167 +27,176 @@ namespace Microsoft.Azure.Commands.Batch.Test.ScenarioTests
26
27
{
27
28
public class FileTests
28
29
{
30
+ // NOTE: To save time on VM allocation when recording, these tests assume the following:
31
+ // - A Batch account named 'filetests' exists under the subscription being used for recording.
32
+ // - A pool called 'testPool' exists under this account and has at least 1 VM allocated to it.
33
+
34
+ private const string accountName = "filetests" ;
35
+
29
36
[ Fact ]
30
37
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
31
- public void TestGetTaskByName ( )
38
+ public void TestGetTaskFileByName ( )
32
39
{
33
40
BatchController controller = BatchController . NewInstance ;
34
- string resourceGroupName = "test-get-task" ;
35
- string accountName = "testgettaskbyname" ;
36
- string location = "eastus" ;
37
- string workItemName = "testName" ;
41
+ string workItemName = "testGetTaskFileWI" ;
38
42
string jobName = null ;
39
43
string taskName = "testTask" ;
44
+ string taskFileName = "stdout.txt" ;
40
45
BatchAccountContext context = null ;
41
46
controller . RunPsTestWorkflow (
42
- ( ) => { return new string [ ] { string . Format ( "Test-GetTaskByName '{0}' '{1}' '{2}' '{3}'" , accountName , workItemName , jobName , taskName ) } ; } ,
47
+ ( ) => { return new string [ ] { string . Format ( "Test-GetTaskFileByName '{0}' '{1}' '{2}' '{3}' '{4}' " , accountName , workItemName , jobName , taskName , taskFileName ) } ; } ,
43
48
( ) =>
44
49
{
45
- context = ScenarioTestHelpers . CreateTestAccountAndResourceGroup ( controller , resourceGroupName , accountName , location ) ;
46
- ScenarioTestHelpers . CreateTestWorkItem ( context , workItemName ) ;
50
+ context = ScenarioTestHelpers . GetBatchAccountContextWithKeys ( controller , accountName ) ;
51
+ ScenarioTestHelpers . CreateTestWorkItem ( controller , context , workItemName ) ;
47
52
jobName = ScenarioTestHelpers . WaitForRecentJob ( controller , context , workItemName ) ;
48
- ScenarioTestHelpers . CreateTestTask ( context , workItemName , jobName , taskName ) ;
53
+ ScenarioTestHelpers . CreateTestTask ( controller , context , workItemName , jobName , taskName ) ;
54
+ ScenarioTestHelpers . WaitForTaskCompletion ( controller , context , workItemName , jobName , taskName ) ;
49
55
} ,
50
56
( ) =>
51
57
{
52
- ScenarioTestHelpers . DeleteWorkItem ( context , workItemName ) ;
53
- ScenarioTestHelpers . CleanupTestAccount ( controller , resourceGroupName , accountName ) ;
58
+ ScenarioTestHelpers . DeleteWorkItem ( controller , context , workItemName ) ;
54
59
} ,
55
60
TestUtilities . GetCallingClass ( ) ,
56
61
TestUtilities . GetCurrentMethodName ( ) ) ;
57
62
}
58
63
59
64
[ Fact ]
60
65
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
61
- public void TestListTasksByFilter ( )
66
+ public void TestListTaskFilesByFilter ( )
62
67
{
63
68
BatchController controller = BatchController . NewInstance ;
64
- string resourceGroupName = "test-list-task-filter" ;
65
- string accountName = "testlisttaskfilter" ;
66
- string location = "eastus" ;
67
- string workItemName = "testWorkItem" ;
69
+ string workItemName = "testListTaskFileFilterWI" ;
68
70
string jobName = null ;
69
- string taskName1 = "testTask1" ;
70
- string taskName2 = "testTask2" ;
71
- string taskName3 = "thirdTestTask" ;
72
- string taskPrefix = "testTask" ;
71
+ string taskName = "testTask" ;
72
+ string taskFilePrefix = "std" ;
73
73
int matches = 2 ;
74
74
BatchAccountContext context = null ;
75
75
controller . RunPsTestWorkflow (
76
- ( ) => { return new string [ ] { string . Format ( "Test-ListTasksByFilter '{0}' '{1}' '{2}' '{3}' '{4}'" , accountName , workItemName , jobName , taskPrefix , matches ) } ; } ,
76
+ ( ) => { return new string [ ] { string . Format ( "Test-ListTaskFilesByFilter '{0}' '{1}' '{2}' '{3}' '{4}' '{5}' " , accountName , workItemName , jobName , taskName , taskFilePrefix , matches ) } ; } ,
77
77
( ) =>
78
78
{
79
- context = ScenarioTestHelpers . CreateTestAccountAndResourceGroup ( controller , resourceGroupName , accountName , location ) ;
80
- ScenarioTestHelpers . CreateTestWorkItem ( context , workItemName ) ;
79
+ context = ScenarioTestHelpers . GetBatchAccountContextWithKeys ( controller , accountName ) ;
80
+ ScenarioTestHelpers . CreateTestWorkItem ( controller , context , workItemName ) ;
81
81
jobName = ScenarioTestHelpers . WaitForRecentJob ( controller , context , workItemName ) ;
82
- ScenarioTestHelpers . CreateTestTask ( context , workItemName , jobName , taskName1 ) ;
83
- ScenarioTestHelpers . CreateTestTask ( context , workItemName , jobName , taskName2 ) ;
84
- ScenarioTestHelpers . CreateTestTask ( context , workItemName , jobName , taskName3 ) ;
82
+ ScenarioTestHelpers . CreateTestTask ( controller , context , workItemName , jobName , taskName ) ;
83
+ ScenarioTestHelpers . WaitForTaskCompletion ( controller , context , workItemName , jobName , taskName ) ;
85
84
} ,
86
85
( ) =>
87
86
{
88
- ScenarioTestHelpers . DeleteWorkItem ( context , workItemName ) ;
89
- ScenarioTestHelpers . CleanupTestAccount ( controller , resourceGroupName , accountName ) ;
87
+ ScenarioTestHelpers . DeleteWorkItem ( controller , context , workItemName ) ;
90
88
} ,
91
89
TestUtilities . GetCallingClass ( ) ,
92
90
TestUtilities . GetCurrentMethodName ( ) ) ;
93
91
}
94
92
95
93
[ Fact ]
96
94
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
97
- public void TestListTasksWithMaxCount ( )
95
+ public void TestListTaskFilesWithMaxCount ( )
98
96
{
99
97
BatchController controller = BatchController . NewInstance ;
100
- string resourceGroupName = "test-list-task-maxcount" ;
101
- string accountName = "testlisttaskmaxcount" ;
102
- string location = "eastus" ;
103
- string workItemName = "testWorkItem" ;
98
+ string workItemName = "testTaskFileMaxWI" ;
104
99
string jobName = null ;
105
- string taskName1 = "testTask1" ;
106
- string taskName2 = "testTask2" ;
107
- string taskName3 = "testTask3" ;
100
+ string taskName = "testTask" ;
108
101
int maxCount = 1 ;
109
102
BatchAccountContext context = null ;
110
103
controller . RunPsTestWorkflow (
111
- ( ) => { return new string [ ] { string . Format ( "Test-ListTasksWithMaxCount '{0}' '{1}' '{2}' '{3}'" , accountName , workItemName , jobName , maxCount ) } ; } ,
104
+ ( ) => { return new string [ ] { string . Format ( "Test-ListTaskFilesWithMaxCount '{0}' '{1}' '{2}' '{3}' '{4}'" , accountName , workItemName , jobName , taskName , maxCount ) } ; } ,
105
+ ( ) =>
106
+ {
107
+ context = ScenarioTestHelpers . GetBatchAccountContextWithKeys ( controller , accountName ) ;
108
+ ScenarioTestHelpers . CreateTestWorkItem ( controller , context , workItemName ) ;
109
+ jobName = ScenarioTestHelpers . WaitForRecentJob ( controller , context , workItemName ) ;
110
+ ScenarioTestHelpers . CreateTestTask ( controller , context , workItemName , jobName , taskName ) ;
111
+ ScenarioTestHelpers . WaitForTaskCompletion ( controller , context , workItemName , jobName , taskName ) ;
112
+ } ,
113
+ ( ) =>
114
+ {
115
+ ScenarioTestHelpers . DeleteWorkItem ( controller , context , workItemName ) ;
116
+ } ,
117
+ TestUtilities . GetCallingClass ( ) ,
118
+ TestUtilities . GetCurrentMethodName ( ) ) ;
119
+ }
120
+
121
+ [ Fact ]
122
+ [ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
123
+ public void TestListAllTaskFiles ( )
124
+ {
125
+ BatchController controller = BatchController . NewInstance ;
126
+ string workItemName = "testListTaskFileWI" ;
127
+ string jobName = null ;
128
+ string taskName = "testTask" ;
129
+ int count = 4 ; // ProcessEnv, stdout, stderr, wd
130
+ BatchAccountContext context = null ;
131
+ controller . RunPsTestWorkflow (
132
+ ( ) => { return new string [ ] { string . Format ( "Test-ListAllTaskFiles '{0}' '{1}' '{2}' '{3}' '{4}'" , accountName , workItemName , jobName , taskName , count ) } ; } ,
112
133
( ) =>
113
134
{
114
- context = ScenarioTestHelpers . CreateTestAccountAndResourceGroup ( controller , resourceGroupName , accountName , location ) ;
115
- ScenarioTestHelpers . CreateTestWorkItem ( context , workItemName ) ;
135
+ context = ScenarioTestHelpers . GetBatchAccountContextWithKeys ( controller , accountName ) ;
136
+ ScenarioTestHelpers . CreateTestWorkItem ( controller , context , workItemName ) ;
116
137
jobName = ScenarioTestHelpers . WaitForRecentJob ( controller , context , workItemName ) ;
117
- ScenarioTestHelpers . CreateTestTask ( context , workItemName , jobName , taskName1 ) ;
118
- ScenarioTestHelpers . CreateTestTask ( context , workItemName , jobName , taskName2 ) ;
119
- ScenarioTestHelpers . CreateTestTask ( context , workItemName , jobName , taskName3 ) ;
138
+ ScenarioTestHelpers . CreateTestTask ( controller , context , workItemName , jobName , taskName ) ;
139
+ ScenarioTestHelpers . WaitForTaskCompletion ( controller , context , workItemName , jobName , taskName ) ;
120
140
} ,
121
141
( ) =>
122
142
{
123
- ScenarioTestHelpers . DeleteWorkItem ( context , workItemName ) ;
124
- ScenarioTestHelpers . CleanupTestAccount ( controller , resourceGroupName , accountName ) ;
143
+ ScenarioTestHelpers . DeleteWorkItem ( controller , context , workItemName ) ;
125
144
} ,
126
145
TestUtilities . GetCallingClass ( ) ,
127
146
TestUtilities . GetCurrentMethodName ( ) ) ;
128
147
}
129
148
130
149
[ Fact ]
131
150
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
132
- public void TestListAllTasks ( )
151
+ public void TestListTaskFilesRecursive ( )
133
152
{
134
153
BatchController controller = BatchController . NewInstance ;
135
- string resourceGroupName = "test-list-task" ;
136
- string accountName = "testlisttask" ;
137
- string location = "eastus" ;
138
- string workItemName = "testWorkItem" ;
154
+ string workItemName = "testListTFRecursiveWI" ;
139
155
string jobName = null ;
140
- string taskName1 = "testTask1" ;
141
- string taskName2 = "testTask2" ;
142
- string taskName3 = "testTask3" ;
143
- int count = 3 ;
156
+ string taskName = "testTask" ;
157
+ string newFile = "testFile.txt" ;
144
158
BatchAccountContext context = null ;
145
159
controller . RunPsTestWorkflow (
146
- ( ) => { return new string [ ] { string . Format ( "Test-ListAllTasks '{0}' '{1}' '{2}' '{3}'" , accountName , workItemName , jobName , count ) } ; } ,
160
+ ( ) => { return new string [ ] { string . Format ( "Test-ListTaskFilesRecursive '{0}' '{1}' '{2}' '{3}' '{4}' " , accountName , workItemName , jobName , taskName , newFile ) } ; } ,
147
161
( ) =>
148
162
{
149
- context = ScenarioTestHelpers . CreateTestAccountAndResourceGroup ( controller , resourceGroupName , accountName , location ) ;
150
- ScenarioTestHelpers . CreateTestWorkItem ( context , workItemName ) ;
163
+ context = ScenarioTestHelpers . GetBatchAccountContextWithKeys ( controller , accountName ) ;
164
+ ScenarioTestHelpers . CreateTestWorkItem ( controller , context , workItemName ) ;
151
165
jobName = ScenarioTestHelpers . WaitForRecentJob ( controller , context , workItemName ) ;
152
- ScenarioTestHelpers . CreateTestTask ( context , workItemName , jobName , taskName1 ) ;
153
- ScenarioTestHelpers . CreateTestTask ( context , workItemName , jobName , taskName2 ) ;
154
- ScenarioTestHelpers . CreateTestTask ( context , workItemName , jobName , taskName3 ) ;
166
+ ScenarioTestHelpers . CreateTestTask ( controller , context , workItemName , jobName , taskName , string . Format ( "cmd /c echo \" test file\" > {0}" , newFile ) ) ;
167
+ ScenarioTestHelpers . WaitForTaskCompletion ( controller , context , workItemName , jobName , taskName ) ;
155
168
} ,
156
169
( ) =>
157
170
{
158
- ScenarioTestHelpers . DeleteWorkItem ( context , workItemName ) ;
159
- ScenarioTestHelpers . CleanupTestAccount ( controller , resourceGroupName , accountName ) ;
171
+ ScenarioTestHelpers . DeleteWorkItem ( controller , context , workItemName ) ;
160
172
} ,
161
173
TestUtilities . GetCallingClass ( ) ,
162
174
TestUtilities . GetCurrentMethodName ( ) ) ;
163
175
}
164
176
165
177
[ Fact ]
166
178
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
167
- public void TestListTaskPipeline ( )
179
+ public void TestListTaskFilePipeline ( )
168
180
{
169
181
BatchController controller = BatchController . NewInstance ;
170
- string resourceGroupName = "test-list-task-pipe" ;
171
- string accountName = "testlisttaskpipe" ;
172
- string location = "eastus" ;
173
- string workItemName = "testWorkItem" ;
182
+ string workItemName = "testListTaskPipeWI" ;
174
183
string jobName = null ;
175
184
string taskName = "testTask" ;
185
+ int count = 4 ; // ProcessEnv, stdout, stderr, wd
176
186
BatchAccountContext context = null ;
177
187
controller . RunPsTestWorkflow (
178
- ( ) => { return new string [ ] { string . Format ( "Test-ListTaskPipeline '{0}' '{1}' '{2}' '{3}'" , accountName , workItemName , jobName , taskName ) } ; } ,
188
+ ( ) => { return new string [ ] { string . Format ( "Test-ListTaskFilePipeline '{0}' '{1}' '{2}' '{3}' '{4}' " , accountName , workItemName , jobName , taskName , count ) } ; } ,
179
189
( ) =>
180
190
{
181
- context = ScenarioTestHelpers . CreateTestAccountAndResourceGroup ( controller , resourceGroupName , accountName , location ) ;
182
- ScenarioTestHelpers . CreateTestWorkItem ( context , workItemName ) ;
191
+ context = ScenarioTestHelpers . GetBatchAccountContextWithKeys ( controller , accountName ) ;
192
+ ScenarioTestHelpers . CreateTestWorkItem ( controller , context , workItemName ) ;
183
193
jobName = ScenarioTestHelpers . WaitForRecentJob ( controller , context , workItemName ) ;
184
- ScenarioTestHelpers . CreateTestTask ( context , workItemName , jobName , taskName ) ;
194
+ ScenarioTestHelpers . CreateTestTask ( controller , context , workItemName , jobName , taskName ) ;
195
+ ScenarioTestHelpers . WaitForTaskCompletion ( controller , context , workItemName , jobName , taskName ) ;
185
196
} ,
186
197
( ) =>
187
198
{
188
- ScenarioTestHelpers . DeleteWorkItem ( context , workItemName ) ;
189
- ScenarioTestHelpers . CleanupTestAccount ( controller , resourceGroupName , accountName ) ;
199
+ ScenarioTestHelpers . DeleteWorkItem ( controller , context , workItemName ) ;
190
200
} ,
191
201
TestUtilities . GetCallingClass ( ) ,
192
202
TestUtilities . GetCurrentMethodName ( ) ) ;
0 commit comments