|
| 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 | +}); |
0 commit comments