|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 | 16 |
|
17 |
| -import {describe, expect, jest, it, afterEach} from '@jest/globals'; |
| 17 | +import {describe, expect, jest, it, afterEach, beforeEach, test} from '@jest/globals'; |
18 | 18 | import fs from 'fs';
|
19 | 19 | import os from 'os';
|
20 | 20 | import path from 'path';
|
@@ -44,6 +44,34 @@ describe('gitRef', () => {
|
44 | 44 | });
|
45 | 45 | });
|
46 | 46 |
|
| 47 | +describe('parseGitRef', () => { |
| 48 | + const originalEnv = process.env; |
| 49 | + beforeEach(() => { |
| 50 | + jest.resetModules(); |
| 51 | + process.env = { |
| 52 | + ...originalEnv, |
| 53 | + DOCKER_GIT_CONTEXT_PR_HEAD_REF: '' |
| 54 | + }; |
| 55 | + }); |
| 56 | + afterEach(() => { |
| 57 | + process.env = originalEnv; |
| 58 | + }); |
| 59 | + // prettier-ignore |
| 60 | + test.each([ |
| 61 | + ['refs/heads/master', '860c1904a1ce19322e91ac35af1ab07466440c37', false, '860c1904a1ce19322e91ac35af1ab07466440c37'], |
| 62 | + ['master', '860c1904a1ce19322e91ac35af1ab07466440c37', false, '860c1904a1ce19322e91ac35af1ab07466440c37'], |
| 63 | + ['refs/pull/15/merge', '860c1904a1ce19322e91ac35af1ab07466440c37', false, 'refs/pull/15/merge'], |
| 64 | + ['refs/heads/master', '', false, 'refs/heads/master'], |
| 65 | + ['master', '', false, 'master'], |
| 66 | + ['refs/tags/v1.0.0', '', false, 'refs/tags/v1.0.0'], |
| 67 | + ['refs/pull/15/merge', '', false, 'refs/pull/15/merge'], |
| 68 | + ['refs/pull/15/merge', '', true, 'refs/pull/15/head'], |
| 69 | + ])('given %p and %p, should return %p', async (ref: string, sha: string, prHeadRef: boolean, expected: string) => { |
| 70 | + process.env.DOCKER_DEFAULT_GIT_CONTEXT_PR_HEAD_REF = prHeadRef ? 'true' : ''; |
| 71 | + expect(Context.parseGitRef(ref, sha)).toEqual(expected); |
| 72 | + }); |
| 73 | +}); |
| 74 | + |
47 | 75 | describe('gitContext', () => {
|
48 | 76 | it('returns refs/heads/master', async () => {
|
49 | 77 | expect(Context.gitContext()).toEqual('https://github.com/docker/actions-toolkit.git#refs/heads/master');
|
|
0 commit comments