|
| 1 | +import td from 'testdouble' |
| 2 | +import * as providerSemaphore from '../../src/ci_providers/provider_semaphore' |
| 3 | +import { IServiceParams, UploaderInputs } from '../../src/types' |
| 4 | +import { createEmptyArgs } from '../test_helpers' |
| 5 | + |
| 6 | +describe('Semaphore Params', () => { |
| 7 | + afterEach(() => { |
| 8 | + td.reset() |
| 9 | + }) |
| 10 | + |
| 11 | + describe('detect()', () => { |
| 12 | + it('does not run without Semaphore env variable', () => { |
| 13 | + const inputs: UploaderInputs = { |
| 14 | + args: { ...createEmptyArgs() }, |
| 15 | + envs: {}, |
| 16 | + } |
| 17 | + let detected = providerSemaphore.detect(inputs.envs) |
| 18 | + expect(detected).toBeFalsy() |
| 19 | + |
| 20 | + inputs.envs['CI'] = 'true' |
| 21 | + detected = providerSemaphore.detect(inputs.envs) |
| 22 | + expect(detected).toBeFalsy() |
| 23 | + }) |
| 24 | + |
| 25 | + it('does run with Semaphore env variable', () => { |
| 26 | + const inputs: UploaderInputs = { |
| 27 | + args: { ...createEmptyArgs() }, |
| 28 | + envs: { |
| 29 | + CI: 'true', |
| 30 | + SEMAPHORE: 'true', |
| 31 | + }, |
| 32 | + } |
| 33 | + const detected = providerSemaphore.detect(inputs.envs) |
| 34 | + expect(detected).toBeTruthy() |
| 35 | + }) |
| 36 | + }) |
| 37 | + |
| 38 | + // This should test that the provider outputs proper default values |
| 39 | + it('gets the correct params on no env variables', async () => { |
| 40 | + const inputs: UploaderInputs = { |
| 41 | + args: { ...createEmptyArgs() }, |
| 42 | + envs: { |
| 43 | + CI: 'true', |
| 44 | + SEMAPHORE: 'true', |
| 45 | + }, |
| 46 | + } |
| 47 | + const expected: IServiceParams = { |
| 48 | + branch: '', |
| 49 | + build: '', |
| 50 | + buildURL: '', |
| 51 | + commit: '', |
| 52 | + job: '', |
| 53 | + pr: '', |
| 54 | + service: 'semaphore', |
| 55 | + slug: '', |
| 56 | + } |
| 57 | + const params = await providerSemaphore.getServiceParams(inputs) |
| 58 | + expect(params).toMatchObject(expected) |
| 59 | + }) |
| 60 | + |
| 61 | + // This should test that the provider outputs proper parameters when a push event is created |
| 62 | + it('gets the correct params on push', async () => { |
| 63 | + const inputs: UploaderInputs = { |
| 64 | + args: { ...createEmptyArgs() }, |
| 65 | + envs: { |
| 66 | + CI: 'true', |
| 67 | + SEMAPHORE: 'true', |
| 68 | + SEMAPHORE_GIT_BRANCH: 'master', |
| 69 | + SEMAPHORE_GIT_REPO_SLUG: 'org/user', |
| 70 | + SEMAPHORE_GIT_SHA: 'testingsha', |
| 71 | + SEMAPHORE_ORGANIZATION_URL: 'https://example.semaphoreci.com', |
| 72 | + SEMAPHORE_WORKFLOW_ID: '03d9de4c-c798-4df5-bbd5-786db9d4d309', |
| 73 | + SEMAPHORE_WORKFLOW_NUMBER: '1', |
| 74 | + }, |
| 75 | + } |
| 76 | + const expected: IServiceParams = { |
| 77 | + branch: 'master', |
| 78 | + build: '1', |
| 79 | + buildURL: 'https://example.semaphoreci.com/workflows/03d9de4c-c798-4df5-bbd5-786db9d4d309', |
| 80 | + commit: 'testingsha', |
| 81 | + job: '03d9de4c-c798-4df5-bbd5-786db9d4d309', |
| 82 | + pr: '', |
| 83 | + service: 'semaphore', |
| 84 | + slug: 'org/user', |
| 85 | + } |
| 86 | + const params = await providerSemaphore.getServiceParams(inputs) |
| 87 | + expect(params).toMatchObject(expected) |
| 88 | + }) |
| 89 | + // |
| 90 | + // This should test that the provider outputs proper parameters when a pull request event is created |
| 91 | + it('gets the correct params on pr', async () => { |
| 92 | + const inputs: UploaderInputs = { |
| 93 | + args: { ...createEmptyArgs() }, |
| 94 | + envs: { |
| 95 | + CI: 'true', |
| 96 | + SEMAPHORE: 'true', |
| 97 | + SEMAPHORE_GIT_BRANCH: 'master', |
| 98 | + SEMAPHORE_GIT_PR_BRANCH: 'feature-branch', |
| 99 | + SEMAPHORE_GIT_PR_NUMBER: '1234', |
| 100 | + SEMAPHORE_GIT_PR_SHA: 'prsha', |
| 101 | + SEMAPHORE_GIT_PR_SLUG: 'org/user', |
| 102 | + SEMAPHORE_GIT_SHA: 'testingsha', |
| 103 | + SEMAPHORE_ORGANIZATION_URL: 'https://example.semaphoreci.com', |
| 104 | + SEMAPHORE_WORKFLOW_ID: '03d9de4c-c798-4df5-bbd5-786db9d4d309', |
| 105 | + SEMAPHORE_WORKFLOW_NUMBER: '1', |
| 106 | + }, |
| 107 | + } |
| 108 | + const expected: IServiceParams = { |
| 109 | + branch: 'feature-branch', |
| 110 | + build: '1', |
| 111 | + buildURL: 'https://example.semaphoreci.com/workflows/03d9de4c-c798-4df5-bbd5-786db9d4d309', |
| 112 | + commit: 'prsha', |
| 113 | + job: '03d9de4c-c798-4df5-bbd5-786db9d4d309', |
| 114 | + pr: '1234', |
| 115 | + service: 'semaphore', |
| 116 | + slug: 'org/user', |
| 117 | + } |
| 118 | + const params = await providerSemaphore.getServiceParams(inputs) |
| 119 | + expect(expected).toBeTruthy() |
| 120 | + }) |
| 121 | + |
| 122 | + // This should test that the provider outputs proper parameters when given overrides |
| 123 | + it('gets the correct params on overrides', async () => { |
| 124 | + const inputs: UploaderInputs = { |
| 125 | + args: {...createEmptyArgs(), ...{ |
| 126 | + branch: 'overwrite-feature-branch', |
| 127 | + build: '3', |
| 128 | + pr: '4', |
| 129 | + sha: 'overwriteSha', |
| 130 | + slug: 'overwriteOwner/overwriteRepo', |
| 131 | + }}, |
| 132 | + envs: { |
| 133 | + CI: 'true', |
| 134 | + SEMAPHORE: 'true', |
| 135 | + SEMAPHORE_GIT_BRANCH: 'master', |
| 136 | + SEMAPHORE_GIT_PR_BRANCH: 'feature-branch', |
| 137 | + SEMAPHORE_GIT_PR_NUMBER: '1234', |
| 138 | + SEMAPHORE_GIT_PR_SHA: 'prsha', |
| 139 | + SEMAPHORE_GIT_PR_SLUG: 'org/user', |
| 140 | + SEMAPHORE_GIT_SHA: 'testingsha', |
| 141 | + SEMAPHORE_ORGANIZATION_URL: 'https://example.semaphoreci.com', |
| 142 | + SEMAPHORE_WORKFLOW_ID: '03d9de4c-c798-4df5-bbd5-786db9d4d309', |
| 143 | + SEMAPHORE_WORKFLOW_NUMBER: '1', |
| 144 | + }, |
| 145 | + } |
| 146 | + const expected: IServiceParams = { |
| 147 | + branch: 'overwrite-feature-branch', |
| 148 | + build: '3', |
| 149 | + buildURL: 'https://example.semaphoreci.com/workflows/03d9de4c-c798-4df5-bbd5-786db9d4d309', |
| 150 | + commit: 'overwriteSha', |
| 151 | + job: '03d9de4c-c798-4df5-bbd5-786db9d4d309', |
| 152 | + pr: '4', |
| 153 | + service: 'semaphore', |
| 154 | + slug: 'overwriteOwner/overwriteRepo', |
| 155 | + } |
| 156 | + const params = await providerSemaphore.getServiceParams(inputs) |
| 157 | + expect(params).toMatchObject(expected) |
| 158 | + }) |
| 159 | +}) |
0 commit comments