2023-01-31 10:34:51 +08:00
|
|
|
/**
|
|
|
|
* Copyright 2023 actions-toolkit authors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2024-06-18 16:59:00 +08:00
|
|
|
import {describe, expect, jest, it, afterEach} from '@jest/globals';
|
2024-07-31 17:01:57 +08:00
|
|
|
import fs from 'fs';
|
|
|
|
import os from 'os';
|
|
|
|
import path from 'path';
|
|
|
|
import * as rimraf from 'rimraf';
|
2023-01-30 07:08:45 +08:00
|
|
|
|
2023-01-30 09:31:09 +08:00
|
|
|
import {Context} from '../src/context';
|
2023-01-30 07:08:45 +08:00
|
|
|
|
2024-07-31 17:01:57 +08:00
|
|
|
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'context-'));
|
2023-02-19 07:59:04 +08:00
|
|
|
const tmpName = path.join(tmpDir, '.tmpname-jest');
|
2023-01-30 07:08:45 +08:00
|
|
|
|
2023-02-20 14:19:57 +08:00
|
|
|
jest.spyOn(Context, 'tmpDir').mockImplementation((): string => {
|
2024-07-31 17:01:57 +08:00
|
|
|
fs.mkdirSync(tmpDir, {recursive: true});
|
2023-01-30 07:08:45 +08:00
|
|
|
return tmpDir;
|
|
|
|
});
|
2023-02-20 14:19:57 +08:00
|
|
|
|
|
|
|
jest.spyOn(Context, 'tmpName').mockImplementation((): string => {
|
2023-01-30 07:08:45 +08:00
|
|
|
return tmpName;
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
rimraf.sync(tmpDir);
|
|
|
|
});
|
|
|
|
|
2023-02-20 14:19:57 +08:00
|
|
|
describe('gitRef', () => {
|
|
|
|
it('returns refs/heads/master', async () => {
|
|
|
|
expect(Context.gitRef()).toEqual('refs/heads/master');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-01-30 07:08:45 +08:00
|
|
|
describe('gitContext', () => {
|
|
|
|
it('returns refs/heads/master', async () => {
|
2023-02-20 14:19:57 +08:00
|
|
|
expect(Context.gitContext()).toEqual('https://github.com/docker/actions-toolkit.git#refs/heads/master');
|
2023-01-30 07:08:45 +08:00
|
|
|
});
|
|
|
|
});
|