|
| 1 | +import { toBeDockerPackageInstallCommand } from "../matchers/dockerPackageInstallCommand"; |
| 2 | + |
| 3 | +// Test all of the combinations of package install commands for the regex in test/matchers/dockerPackageInstallCommand.ts:11 |
| 4 | +describe("valid package install commands", () => { |
| 5 | + const testCases = [ |
| 6 | + { command: "rpm -i nginx", pkg: "nginx" }, |
| 7 | + { command: "rpm --install nginx", pkg: "nginx" }, |
| 8 | + { command: "apk add curl", pkg: "curl" }, |
| 9 | + { command: "apk --update add curl", pkg: "curl" }, |
| 10 | + { command: "apk -u add curl", pkg: "curl" }, |
| 11 | + { command: "apk --no-cache add curl", pkg: "curl" }, |
| 12 | + { command: "apt-get install curl", pkg: "curl" }, |
| 13 | + { command: "apt-get --yes install curl", pkg: "curl" }, |
| 14 | + { command: "apt-get -y install curl", pkg: "curl" }, |
| 15 | + { command: "apt install curl", pkg: "curl" }, |
| 16 | + { command: "yum install curl", pkg: "curl" }, |
| 17 | + { command: "aptitude install curl", pkg: "curl" }, |
| 18 | + ]; |
| 19 | + |
| 20 | + testCases.forEach(({ command, pkg }) => { |
| 21 | + it(`recognizes "${command}" as valid`, () => { |
| 22 | + const result = toBeDockerPackageInstallCommand(command, pkg); |
| 23 | + expect(result.pass).toBe(true); |
| 24 | + |
| 25 | + // Verify success message |
| 26 | + expect(result.message()).toContain("not to be a package installCommand"); |
| 27 | + }); |
| 28 | + }); |
| 29 | +}); |
| 30 | + |
| 31 | +describe("invalid package install commands", () => { |
| 32 | + const testCases = [ |
| 33 | + { |
| 34 | + command: "not a command", |
| 35 | + pkg: "curl", |
| 36 | + reason: "not a package manager command", |
| 37 | + }, |
| 38 | + { |
| 39 | + command: "apt-get install vim", |
| 40 | + pkg: "curl", |
| 41 | + reason: "wrong package name", |
| 42 | + }, |
| 43 | + { |
| 44 | + command: "RUN apt-get install curl", |
| 45 | + pkg: "curl", |
| 46 | + reason: "prefixed with RUN", |
| 47 | + }, |
| 48 | + { |
| 49 | + command: "RUN /bin/sh -c apt-get install curl", |
| 50 | + pkg: "curl", |
| 51 | + reason: "RUN with shell", |
| 52 | + }, |
| 53 | + ]; |
| 54 | + |
| 55 | + testCases.forEach(({ command, pkg, reason }) => { |
| 56 | + it(`rejects "${command}" - ${reason}`, () => { |
| 57 | + const result = toBeDockerPackageInstallCommand(command, pkg); |
| 58 | + expect(result.pass).toBe(false); |
| 59 | + |
| 60 | + // Verify failure message |
| 61 | + expect(result.message()).toContain("to be a package installCommand"); |
| 62 | + }); |
| 63 | + }); |
| 64 | +}); |
0 commit comments