|
3 | 3 | import * as fs from 'fs' |
4 | 4 | import * as os from 'os' |
5 | 5 | import * as path from 'path' |
| 6 | +import * as core from '@actions/core' |
6 | 7 | import * as exec from '@actions/exec' |
7 | 8 | import * as tools from '../src/tools' |
8 | 9 |
|
@@ -317,3 +318,105 @@ test('ensureSnapcraft refreshes if Snapcraft is installed', async () => { |
317 | 318 | 'snapcraft' |
318 | 319 | ]) |
319 | 320 | }) |
| 321 | + |
| 322 | +test('ensureLXDNetwork sets up iptables and warns about Docker', async () => { |
| 323 | + expect.assertions(8) |
| 324 | + |
| 325 | + const infoMock = jest |
| 326 | + .spyOn(core, 'info') |
| 327 | + .mockImplementation((info: string) => {}) |
| 328 | + |
| 329 | + const execMock = jest |
| 330 | + .spyOn(exec, 'exec') |
| 331 | + .mockImplementation( |
| 332 | + async (program: string, args?: string[]): Promise<number> => { |
| 333 | + if (args != undefined && args[1] == 'moby-runc') { |
| 334 | + return 0 |
| 335 | + } else { |
| 336 | + return 1 |
| 337 | + } |
| 338 | + } |
| 339 | + ) |
| 340 | + |
| 341 | + await tools.ensureLXDNetwork() |
| 342 | + |
| 343 | + expect(infoMock).toHaveBeenCalledWith( |
| 344 | + 'Installed docker related packages might interfere with LXD networking: moby-runc' |
| 345 | + ) |
| 346 | + expect(execMock).toHaveBeenNthCalledWith(1, 'dpkg', ['-l', 'moby-buildx'], { |
| 347 | + silent: true |
| 348 | + }) |
| 349 | + expect(execMock).toHaveBeenNthCalledWith(2, 'dpkg', ['-l', 'moby-engine'], { |
| 350 | + silent: true |
| 351 | + }) |
| 352 | + expect(execMock).toHaveBeenNthCalledWith(3, 'dpkg', ['-l', 'moby-cli'], { |
| 353 | + silent: true |
| 354 | + }) |
| 355 | + expect(execMock).toHaveBeenNthCalledWith(4, 'dpkg', ['-l', 'moby-compose'], { |
| 356 | + silent: true |
| 357 | + }) |
| 358 | + expect(execMock).toHaveBeenNthCalledWith( |
| 359 | + 5, |
| 360 | + 'dpkg', |
| 361 | + ['-l', 'moby-containerd'], |
| 362 | + {silent: true} |
| 363 | + ) |
| 364 | + expect(execMock).toHaveBeenNthCalledWith(6, 'dpkg', ['-l', 'moby-runc'], { |
| 365 | + silent: true |
| 366 | + }) |
| 367 | + expect(execMock).toHaveBeenNthCalledWith(7, 'sudo', [ |
| 368 | + 'iptables', |
| 369 | + '-P', |
| 370 | + 'FORWARD', |
| 371 | + 'ACCEPT' |
| 372 | + ]) |
| 373 | +}) |
| 374 | + |
| 375 | +test('ensureLXDNetwork sets up iptables and warns only about installed packages', async () => { |
| 376 | + expect.assertions(8) |
| 377 | + |
| 378 | + const infoMock = jest |
| 379 | + .spyOn(core, 'info') |
| 380 | + .mockImplementation((info: string) => {}) |
| 381 | + const execMock = jest |
| 382 | + .spyOn(exec, 'exec') |
| 383 | + .mockImplementation( |
| 384 | + async (program: string, args?: string[]): Promise<number> => { |
| 385 | + return 0 |
| 386 | + } |
| 387 | + ) |
| 388 | + |
| 389 | + await tools.ensureLXDNetwork() |
| 390 | + |
| 391 | + expect(infoMock).toHaveBeenCalledWith( |
| 392 | + 'Installed docker related packages might interfere with LXD networking: ' + |
| 393 | + 'moby-buildx,moby-engine,moby-cli,moby-compose,moby-containerd,moby-runc' |
| 394 | + ) |
| 395 | + expect(execMock).toHaveBeenNthCalledWith(1, 'dpkg', ['-l', 'moby-buildx'], { |
| 396 | + silent: true |
| 397 | + }) |
| 398 | + expect(execMock).toHaveBeenNthCalledWith(2, 'dpkg', ['-l', 'moby-engine'], { |
| 399 | + silent: true |
| 400 | + }) |
| 401 | + expect(execMock).toHaveBeenNthCalledWith(3, 'dpkg', ['-l', 'moby-cli'], { |
| 402 | + silent: true |
| 403 | + }) |
| 404 | + expect(execMock).toHaveBeenNthCalledWith(4, 'dpkg', ['-l', 'moby-compose'], { |
| 405 | + silent: true |
| 406 | + }) |
| 407 | + expect(execMock).toHaveBeenNthCalledWith( |
| 408 | + 5, |
| 409 | + 'dpkg', |
| 410 | + ['-l', 'moby-containerd'], |
| 411 | + {silent: true} |
| 412 | + ) |
| 413 | + expect(execMock).toHaveBeenNthCalledWith(6, 'dpkg', ['-l', 'moby-runc'], { |
| 414 | + silent: true |
| 415 | + }) |
| 416 | + expect(execMock).toHaveBeenNthCalledWith(7, 'sudo', [ |
| 417 | + 'iptables', |
| 418 | + '-P', |
| 419 | + 'FORWARD', |
| 420 | + 'ACCEPT' |
| 421 | + ]) |
| 422 | +}) |
0 commit comments