Skip to content

Commit c7ab3a9

Browse files
authored
Users/jikuma/dockerl0 (#4795)
* added container registry windows test case * docker test case complete * Docker compose force delete * removing log * docker compose fix * added linux docker compose test * added linux docker compose test debug * docker compose fix * added linux docker compose test debug * linux test fix * added linux docker compose test debug
1 parent 06491ec commit c7ab3a9

File tree

12 files changed

+724
-9
lines changed

12 files changed

+724
-9
lines changed

Tasks/Docker/Tests/L0.ts

Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
import * as path from 'path';
2+
import * as assert from 'assert';
3+
import * as ttm from 'vsts-task-lib/mock-test';
4+
import tl = require('vsts-task-lib');
5+
6+
describe('Docker Suite', function() {
7+
this.timeout(30000);
8+
before((done) => {
9+
done();
10+
});
11+
after(function () {
12+
});
13+
14+
if(tl.osType().match(/^Win/)) {
15+
it('Runs successfully for windows docker build', (done:MochaDone) => {
16+
let tp = path.join(__dirname, 'L0Windows.js');
17+
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
18+
process.env["__command__"] = "Build an image";
19+
tr.run();
20+
21+
assert(tr.invokedToolCount == 1, 'should have invoked tool one times. actual: ' + tr.invokedToolCount);
22+
assert(tr.stderr.length == 0 || tr.errorIssues.length, 'should not have written to stderr');
23+
assert(tr.succeeded, 'task should have succeeded');
24+
assert(tr.stdout.indexOf("[command]docker build -f F:\\dir1\\DockerFile -t test/test:2") != -1, "docker build should run");
25+
console.log(tr.stderr);
26+
done();
27+
});
28+
29+
it('Runs successfully for windows docker build with latest tag', (done:MochaDone) => {
30+
let tp = path.join(__dirname, 'L0Windows.js');
31+
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
32+
process.env["__command__"] = "Build an image";
33+
process.env["__includeLatestTag__"] = "true";
34+
tr.run();
35+
process.env["__includeLatestTag__"] = "false";
36+
37+
assert(tr.invokedToolCount == 1, 'should have invoked tool one times. actual: ' + tr.invokedToolCount);
38+
assert(tr.stderr.length == 0 || tr.errorIssues.length, 'should not have written to stderr');
39+
assert(tr.succeeded, 'task should have succeeded');
40+
assert(tr.stdout.indexOf("[command]docker build -f F:\\dir1\\DockerFile -t test/test:2 -t test/test") != -1, "docker build should run");
41+
console.log(tr.stderr);
42+
done();
43+
});
44+
45+
it('Runs successfully for windows docker run image', (done:MochaDone) => {
46+
let tp = path.join(__dirname, 'L0Windows.js');
47+
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
48+
process.env["__command__"] = "Run an image";
49+
tr.run();
50+
process.env["__command__"] = "Build an image";
51+
52+
assert(tr.invokedToolCount == 1, 'should have invoked tool one times. actual: ' + tr.invokedToolCount);
53+
assert(tr.stderr.length == 0 || tr.errorIssues.length, 'should not have written to stderr');
54+
assert(tr.succeeded, 'task should have succeeded');
55+
assert(tr.stdout.indexOf("[command]docker run --rm test/test:2") != -1, "docker run should run");
56+
console.log(tr.stderr);
57+
done();
58+
});
59+
60+
it('Runs successfully for windows docker push image', (done:MochaDone) => {
61+
let tp = path.join(__dirname, 'L0Windows.js');
62+
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
63+
process.env["__command__"] = "Push an image";
64+
tr.run();
65+
process.env["__command__"] = "Build an image";
66+
67+
assert(tr.invokedToolCount == 1, 'should have invoked tool one times. actual: ' + tr.invokedToolCount);
68+
assert(tr.stderr.length == 0 || tr.errorIssues.length, 'should not have written to stderr');
69+
assert(tr.succeeded, 'task should have succeeded');
70+
assert(tr.stdout.indexOf("[command]docker push test/test:2") != -1, "docker push should run");
71+
console.log(tr.stderr);
72+
done();
73+
});
74+
75+
it('Runs successfully for windows docker pull image', (done:MochaDone) => {
76+
let tp = path.join(__dirname, 'L0Windows.js');
77+
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
78+
process.env["__command__"] = "Run a Docker command";
79+
tr.run();
80+
process.env["__command__"] = "Build an image";
81+
82+
assert(tr.invokedToolCount == 1, 'should have invoked tool one times. actual: ' + tr.invokedToolCount);
83+
assert(tr.stderr.length == 0 || tr.errorIssues.length, 'should not have written to stderr');
84+
assert(tr.succeeded, 'task should have succeeded');
85+
assert(tr.stdout.indexOf("[command]docker pull test/test:2") != -1, "docker pull should run");
86+
console.log(tr.stderr);
87+
done();
88+
});
89+
90+
it('Runs successfully for windows docker build with ACR', (done:MochaDone) => {
91+
let tp = path.join(__dirname, 'L0Windows.js');
92+
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
93+
process.env["__command__"] = "Build an image";
94+
process.env["__container_type__"] = "Azure Container Registry";
95+
tr.run();
96+
process.env["__container_type__"] = "Container Registry";
97+
98+
assert(tr.invokedToolCount == 1, 'should have invoked tool one times. actual: ' + tr.invokedToolCount);
99+
assert(tr.stderr.length == 0 || tr.errorIssues.length, 'should not have written to stderr');
100+
assert(tr.succeeded, 'task should have succeeded');
101+
assert(tr.stdout.indexOf("[command]docker build -f F:\\dir1\\DockerFile -t test/test:2") != -1, "docker build should run");
102+
console.log(tr.stderr);
103+
done();
104+
});
105+
106+
it('Runs successfully for windows docker build with ACR and qualify image name', (done:MochaDone) => {
107+
let tp = path.join(__dirname, 'L0Windows.js');
108+
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
109+
process.env["__command__"] = "Build an image";
110+
process.env["__container_type__"] = "Azure Container Registry";
111+
process.env["__qualifyImageName__"] = "true";
112+
tr.run();
113+
process.env["__container_type__"] = "Container Registry";
114+
process.env["__qualifyImageName__"] = "false";
115+
console.log(tr.stdout);
116+
117+
assert(tr.invokedToolCount == 1, 'should have invoked tool one times. actual: ' + tr.invokedToolCount);
118+
assert(tr.stderr.length == 0 || tr.errorIssues.length, 'should not have written to stderr');
119+
assert(tr.succeeded, 'task should have succeeded');
120+
assert(tr.stdout.indexOf("[command]docker build -f F:\\dir1\\DockerFile -t ajgtestacr1.azurecr.io/test/test:2") != -1, "docker build should run");
121+
done();
122+
});
123+
124+
} else {
125+
it('Runs successfully for linux docker build', (done:MochaDone) => {
126+
let tp = path.join(__dirname, 'L0Linux.js');
127+
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
128+
process.env["__command__"] = "Build an image";
129+
tr.run();
130+
131+
assert(tr.invokedToolCount == 1, 'should have invoked tool one times. actual: ' + tr.invokedToolCount);
132+
assert(tr.stderr.length == 0 || tr.errorIssues.length, 'should not have written to stderr');
133+
assert(tr.succeeded, 'task should have succeeded');
134+
assert(tr.stdout.indexOf("[command]docker build -f /tmp/tempdir/100/DockerFile -t test/test:2") != -1, "docker build should run");
135+
console.log(tr.stderr);
136+
done();
137+
});
138+
139+
it('Runs successfully for linux docker build with latest tag', (done:MochaDone) => {
140+
let tp = path.join(__dirname, 'L0Linux.js');
141+
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
142+
process.env["__command__"] = "Build an image";
143+
process.env["__includeLatestTag__"] = "true";
144+
tr.run();
145+
process.env["__includeLatestTag__"] = "false";
146+
147+
assert(tr.invokedToolCount == 1, 'should have invoked tool one times. actual: ' + tr.invokedToolCount);
148+
assert(tr.stderr.length == 0 || tr.errorIssues.length, 'should not have written to stderr');
149+
assert(tr.succeeded, 'task should have succeeded');
150+
assert(tr.stdout.indexOf("[command]docker build -f /tmp/tempdir/100/DockerFile -t test/test:2 -t test/test") != -1, "docker build should run");
151+
console.log(tr.stderr);
152+
done();
153+
});
154+
155+
it('Runs successfully for linux docker run image', (done:MochaDone) => {
156+
let tp = path.join(__dirname, 'L0Linux.js');
157+
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
158+
process.env["__command__"] = "Run an image";
159+
tr.run();
160+
process.env["__command__"] = "Build an image";
161+
162+
assert(tr.invokedToolCount == 1, 'should have invoked tool one times. actual: ' + tr.invokedToolCount);
163+
assert(tr.stderr.length == 0 || tr.errorIssues.length, 'should not have written to stderr');
164+
assert(tr.succeeded, 'task should have succeeded');
165+
assert(tr.stdout.indexOf("[command]docker run --rm test/test:2") != -1, "docker run should run");
166+
console.log(tr.stderr);
167+
done();
168+
});
169+
170+
it('Runs successfully for linux docker push image', (done:MochaDone) => {
171+
let tp = path.join(__dirname, 'L0Linux.js');
172+
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
173+
process.env["__command__"] = "Push an image";
174+
tr.run();
175+
process.env["__command__"] = "Build an image";
176+
177+
assert(tr.invokedToolCount == 1, 'should have invoked tool one times. actual: ' + tr.invokedToolCount);
178+
assert(tr.stderr.length == 0 || tr.errorIssues.length, 'should not have written to stderr');
179+
assert(tr.succeeded, 'task should have succeeded');
180+
assert(tr.stdout.indexOf("[command]docker push test/test:2") != -1, "docker push should run");
181+
console.log(tr.stderr);
182+
done();
183+
});
184+
185+
it('Runs successfully for linux docker pull image', (done:MochaDone) => {
186+
let tp = path.join(__dirname, 'L0Linux.js');
187+
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
188+
process.env["__command__"] = "Run a Docker command";
189+
tr.run();
190+
process.env["__command__"] = "Build an image";
191+
192+
assert(tr.invokedToolCount == 1, 'should have invoked tool one times. actual: ' + tr.invokedToolCount);
193+
assert(tr.stderr.length == 0 || tr.errorIssues.length, 'should not have written to stderr');
194+
assert(tr.succeeded, 'task should have succeeded');
195+
assert(tr.stdout.indexOf("[command]docker pull test/test:2") != -1, "docker pull should run");
196+
console.log(tr.stderr);
197+
done();
198+
});
199+
200+
it('Runs successfully for linux docker build with ACR', (done:MochaDone) => {
201+
let tp = path.join(__dirname, 'L0Linux.js');
202+
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
203+
process.env["__command__"] = "Build an image";
204+
process.env["__container_type__"] = "Azure Container Registry";
205+
tr.run();
206+
process.env["__container_type__"] = "Container Registry";
207+
208+
assert(tr.invokedToolCount == 1, 'should have invoked tool one times. actual: ' + tr.invokedToolCount);
209+
assert(tr.stderr.length == 0 || tr.errorIssues.length, 'should not have written to stderr');
210+
assert(tr.succeeded, 'task should have succeeded');
211+
assert(tr.stdout.indexOf("[command]docker build -f /tmp/tempdir/100/DockerFile -t test/test:2") != -1, "docker build should run");
212+
console.log(tr.stderr);
213+
done();
214+
});
215+
216+
it('Runs successfully for linux docker build with ACR and qualify image name', (done:MochaDone) => {
217+
let tp = path.join(__dirname, 'L0Linux.js');
218+
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
219+
process.env["__command__"] = "Build an image";
220+
process.env["__container_type__"] = "Azure Container Registry";
221+
process.env["__qualifyImageName__"] = "true";
222+
tr.run();
223+
process.env["__container_type__"] = "Container Registry";
224+
process.env["__qualifyImageName__"] = "false";
225+
226+
assert(tr.invokedToolCount == 1, 'should have invoked tool one times. actual: ' + tr.invokedToolCount);
227+
assert(tr.stderr.length == 0 || tr.errorIssues.length, 'should not have written to stderr');
228+
assert(tr.succeeded, 'task should have succeeded');
229+
assert(tr.stdout.indexOf("[command]docker build -f /tmp/tempdir/100/DockerFile -t ajgtestacr1.azurecr.io/test/test:2") != -1, "docker build should run");
230+
done();
231+
});
232+
}
233+
});

Tasks/Docker/Tests/L0Linux.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import ma = require('vsts-task-lib/mock-answer');
2+
import tmrm = require('vsts-task-lib/mock-run');
3+
import path = require('path');
4+
5+
const DefaultWorkingDirectory: string = "/a/w";
6+
7+
let taskPath = path.join(__dirname, '..', 'container.js');
8+
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);
9+
10+
tr.setInput('containerregistrytype', process.env["__container_type__"] || 'Container Registry');
11+
tr.setInput('action', process.env["__command__"] || 'Build an image');
12+
tr.setInput('imageName', 'test/test:2');
13+
tr.setInput('dockerRegistryEndpoint', 'dockerhubendpoint');
14+
tr.setInput('dockerFile', '/tmp/tempdir/100/DockerFile');
15+
tr.setInput('customCommand', "pull test/test:2");
16+
tr.setInput('includeLatestTag', process.env["__includeLatestTag__"] || "false");
17+
tr.setInput('qualifyImageName', process.env["__qualifyImageName__"] || "false");
18+
tr.setInput('azureSubscriptionEndpoint', 'AzureRMSpn');
19+
tr.setInput('azureContainerRegistry', '{"loginServer":"ajgtestacr1.azurecr.io", "id" : "/subscriptions/c00d16c7-6c1f-4c03-9be1-6934a4c49682/resourcegroups/ajgtestacr1rg/providers/Microsoft.ContainerRegistry/registries/ajgtestacr1"}')
20+
21+
console.log("Inputs have been set");
22+
23+
process.env["RELEASE_RELEASENAME"] = "Release-1";
24+
process.env["SYSTEM_DEFAULTWORKINGDIRECTORY"] = DefaultWorkingDirectory;
25+
process.env["ENDPOINT_AUTH_dockerhubendpoint"] = "{\"parameters\":{\"username\":\"test\", \"password\":\"regpassword\", \"email\":\"[email protected]\",\"registry\":\"https://index.docker.io/v1/\"},\"scheme\":\"UsernamePassword\"}";
26+
process.env["ENDPOINT_AUTH_SCHEME_AzureRMSpn"] = "ServicePrincipal";
27+
process.env["ENDPOINT_AUTH_PARAMETER_AzureRMSpn_SERVICEPRINCIPALID"] = "spId";
28+
process.env["ENDPOINT_AUTH_PARAMETER_AzureRMSpn_SERVICEPRINCIPALKEY"] = "spKey";
29+
process.env["ENDPOINT_AUTH_PARAMETER_AzureRMSpn_TENANTID"] = "tenant";
30+
process.env["ENDPOINT_DATA_AzureRMSpn_SUBSCRIPTIONNAME"] = "sName";
31+
process.env["ENDPOINT_DATA_AzureRMSpn_SUBSCRIPTIONID"] = "sId";
32+
process.env["ENDPOINT_DATA_AzureRMSpn_SPNOBJECTID"] = "oId";
33+
34+
// provide answers for task mock
35+
let a: any = <any>{
36+
"which": {
37+
"docker": "docker"
38+
},
39+
"checkPath": {
40+
"docker": true
41+
},
42+
"exist": {
43+
"/tmp/tempdir/100/DockerFile": true,
44+
"docker": true
45+
},
46+
"exec": {
47+
"docker build -f /tmp/tempdir/100/DockerFile -t test/test:2" :{
48+
"code": 0,
49+
"stdout": "successfully build test/test:2 image"
50+
},
51+
"docker push test/test:2" : {
52+
"code": 0,
53+
"stdout": "successfully pushed test/test:2 image"
54+
},
55+
"docker run --rm test/test:2" : {
56+
"code": 0,
57+
"stdout": "successfully ran test/test:2 image"
58+
},
59+
"docker pull test/test:2": {
60+
"code": 0,
61+
"stdout": "successfully pulled test/test:2 image"
62+
},
63+
"docker build -f /tmp/tempdir/100/DockerFile -t test/test:2 -t test/test" :{
64+
"code": 0,
65+
"stdout": "successfully build test/test image with latest tag"
66+
},
67+
"docker build -f /tmp/tempdir/100/DockerFile -t ajgtestacr1.azurecr.io/test/test:2":{
68+
"code": 0,
69+
"stdout": "successfully build ajgtestacr1.azurecr.io/test/test image with latest tag"
70+
}
71+
}
72+
};
73+
74+
tr.setAnswers(a);
75+
tr.run();

Tasks/Docker/Tests/L0Windows.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import ma = require('vsts-task-lib/mock-answer');
2+
import tmrm = require('vsts-task-lib/mock-run');
3+
import path = require('path');
4+
5+
const DefaultWorkingDirectory: string = "C:\\a\\w\\";
6+
let taskPath = path.join(__dirname, '..\\container.js');
7+
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);
8+
9+
tr.setInput('containerregistrytype', process.env["__container_type__"] || 'Container Registry');
10+
tr.setInput('action', process.env["__command__"] || 'Build an image');
11+
tr.setInput('imageName', 'test/test:2');
12+
tr.setInput('dockerRegistryEndpoint', 'dockerhubendpoint');
13+
tr.setInput('dockerFile', 'F:\\dir1\\DockerFile');
14+
tr.setInput('customCommand', "pull test/test:2");
15+
tr.setInput('includeLatestTag', process.env["__includeLatestTag__"] || "false");
16+
tr.setInput('qualifyImageName', process.env["__qualifyImageName__"] || "false");
17+
tr.setInput('azureSubscriptionEndpoint', 'AzureRMSpn');
18+
tr.setInput('azureContainerRegistry', '{"loginServer":"ajgtestacr1.azurecr.io", "id" : "/subscriptions/c00d16c7-6c1f-4c03-9be1-6934a4c49682/resourcegroups/ajgtestacr1rg/providers/Microsoft.ContainerRegistry/registries/ajgtestacr1"}')
19+
20+
console.log("Inputs have been set");
21+
22+
process.env["RELEASE_RELEASENAME"] = "Release-1";
23+
process.env["SYSTEM_DEFAULTWORKINGDIRECTORY"] = DefaultWorkingDirectory;
24+
process.env["ENDPOINT_AUTH_dockerhubendpoint"] = "{\"parameters\":{\"username\":\"test\", \"password\":\"regpassword\", \"email\":\"[email protected]\",\"registry\":\"https://index.docker.io/v1/\"},\"scheme\":\"UsernamePassword\"}";
25+
process.env["ENDPOINT_AUTH_SCHEME_AzureRMSpn"] = "ServicePrincipal";
26+
process.env["ENDPOINT_AUTH_PARAMETER_AzureRMSpn_SERVICEPRINCIPALID"] = "spId";
27+
process.env["ENDPOINT_AUTH_PARAMETER_AzureRMSpn_SERVICEPRINCIPALKEY"] = "spKey";
28+
process.env["ENDPOINT_AUTH_PARAMETER_AzureRMSpn_TENANTID"] = "tenant";
29+
process.env["ENDPOINT_DATA_AzureRMSpn_SUBSCRIPTIONNAME"] = "sName";
30+
process.env["ENDPOINT_DATA_AzureRMSpn_SUBSCRIPTIONID"] = "sId";
31+
process.env["ENDPOINT_DATA_AzureRMSpn_SPNOBJECTID"] = "oId";
32+
33+
// provide answers for task mock
34+
let a: any = <any>{
35+
"which": {
36+
"docker": "docker"
37+
},
38+
"checkPath": {
39+
"docker": true
40+
},
41+
"exist": {
42+
"F:\\dir1\\DockerFile": true,
43+
"docker": true
44+
},
45+
"exec": {
46+
"docker build -f F:\\dir1\\DockerFile -t test/test:2" :{
47+
"code": 0,
48+
"stdout": "successfully build test/test:2 image"
49+
},
50+
"docker push test/test:2" : {
51+
"code": 0,
52+
"stdout": "successfully pushed test/test:2 image"
53+
},
54+
"docker run --rm test/test:2" : {
55+
"code": 0,
56+
"stdout": "successfully ran test/test:2 image"
57+
},
58+
"docker pull test/test:2": {
59+
"code": 0,
60+
"stdout": "successfully pulled test/test:2 image"
61+
},
62+
"docker build -f F:\\dir1\\DockerFile -t test/test:2 -t test/test" :{
63+
"code": 0,
64+
"stdout": "successfully build test/test image with latest tag"
65+
},
66+
"docker build -f F:\\dir1\\DockerFile -t ajgtestacr1.azurecr.io/test/test:2":{
67+
"code": 0,
68+
"stdout": "successfully build ajgtestacr1.azurecr.io/test/test image with latest tag"
69+
}
70+
}
71+
};
72+
73+
tr.setAnswers(a);
74+
tr.run();

0 commit comments

Comments
 (0)