feat(repos): 检出相关逻辑更改为传入任务信息而不是项目信息。
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
import { Pipeline } from './../pipelines/pipeline.entity';
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { getRepositoryToken } from '@nestjs/typeorm';
|
||||
import { Project } from '../projects/project.entity';
|
||||
import { ReposService } from './repos.service';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { readFile, rm } from 'fs/promises';
|
||||
import { join } from 'path';
|
||||
import { rm } from 'fs/promises';
|
||||
import configuration from '../commons/config/configuration';
|
||||
import { NotFoundException } from '@nestjs/common';
|
||||
import { PipelineTask } from '../pipeline-tasks/pipeline-task.entity';
|
||||
import { join } from 'path';
|
||||
import { readFile } from 'fs/promises';
|
||||
|
||||
const getTest1Project = () =>
|
||||
({
|
||||
@@ -59,73 +61,79 @@ describe('ReposService', () => {
|
||||
it('getWorkspaceRoot', () => {
|
||||
expect(service.getWorkspaceRoot(getTest1Project())).toBeDefined();
|
||||
});
|
||||
describe.skip('listLogs', () => {
|
||||
describe('listLogs', () => {
|
||||
it('should be return logs', async () => {
|
||||
const result = await service.listLogs({ projectId: '1' });
|
||||
expect(result).toBeDefined();
|
||||
}, 20_000);
|
||||
});
|
||||
describe.skip('listBranch', () => {
|
||||
describe('listBranch', () => {
|
||||
it('should be return branches', async () => {
|
||||
const result = await service.listBranches({ projectId: '1' });
|
||||
expect(result).toBeDefined();
|
||||
}, 10_000);
|
||||
});
|
||||
describe.skip('checkoutBranch', () => {
|
||||
it('should be checkout', async () => {
|
||||
await service.checkoutBranch(getTest1Project(), 'master');
|
||||
const filePath = join(
|
||||
service.getWorkspaceRoot(getTest1Project(), 'master'),
|
||||
'README.md',
|
||||
);
|
||||
const text = await readFile(filePath, { encoding: 'utf-8' });
|
||||
expect(text).toMatch(/Commit 1/gi);
|
||||
}, 30_000);
|
||||
it('multiplexing workspace', async () => {
|
||||
await service.checkoutBranch(getTest1Project(), 'master');
|
||||
await service.checkoutBranch(getTest1Project(), 'branch-a');
|
||||
await service.checkoutBranch(getTest1Project(), 'branch-b');
|
||||
const filePath = join(
|
||||
service.getWorkspaceRoot(getTest1Project(), 'branch-b'),
|
||||
'branch-b.md',
|
||||
);
|
||||
const text = await readFile(filePath, { encoding: 'utf-8' });
|
||||
expect(text).toMatch(/Commit branch b/gi);
|
||||
}, 30_000);
|
||||
it('nonexistent branch', async () => {
|
||||
return expect(
|
||||
service.checkoutBranch(getTest1Project(), 'nonexistent'),
|
||||
).rejects.toBeInstanceOf(NotFoundException);
|
||||
}, 30_000);
|
||||
it('checkout the specified version', async () => {
|
||||
await service.checkoutBranch(getTest1Project(), 'master');
|
||||
const filePath = join(
|
||||
service.getWorkspaceRoot(getTest1Project(), 'master'),
|
||||
'README.md',
|
||||
);
|
||||
const text = await readFile(filePath, { encoding: 'utf-8' });
|
||||
expect(text).toMatch(/Commit 1/gi);
|
||||
}, 30_000);
|
||||
});
|
||||
|
||||
describe.skip('checkoutCommit', () => {
|
||||
describe.skip('checkout', () => {
|
||||
let task: PipelineTask;
|
||||
let workspaceRoot: string;
|
||||
beforeEach(() => {
|
||||
const project = new Project();
|
||||
const pipeline = new Pipeline();
|
||||
task = new PipelineTask();
|
||||
pipeline.project = project;
|
||||
task.pipeline = pipeline;
|
||||
project.id = 'pid';
|
||||
project.name = 'pname';
|
||||
pipeline.id = 'lid';
|
||||
pipeline.name = 'pipeline';
|
||||
task.id = 'tid';
|
||||
task.commit = '123123hash';
|
||||
workspaceRoot = service.getWorkspaceRootByTask(task);
|
||||
});
|
||||
|
||||
it('should be checkout', async () => {
|
||||
await service.checkoutCommit(getTest1Project(), '498c782685');
|
||||
const filePath = join(
|
||||
service.getWorkspaceRoot(getTest1Project(), '498c782685'),
|
||||
'README.md',
|
||||
);
|
||||
task.commit = '498c782685';
|
||||
await service.checkout(task, workspaceRoot);
|
||||
const filePath = join(workspaceRoot, 'README.md');
|
||||
const text = await readFile(filePath, { encoding: 'utf-8' });
|
||||
expect(text).toMatch(/Commit 1/gi);
|
||||
}, 20_000);
|
||||
it('should be checkout right commit', async () => {
|
||||
await service.checkoutCommit(getTest1Project(), '7f7123fe5b');
|
||||
const filePath = join(
|
||||
service.getWorkspaceRoot(getTest1Project(), '7f7123fe5b'),
|
||||
'README.md',
|
||||
);
|
||||
task.commit = '7f7123fe5b';
|
||||
await service.checkout(task, workspaceRoot);
|
||||
const filePath = join(workspaceRoot, 'README.md');
|
||||
const text = await readFile(filePath, { encoding: 'utf-8' });
|
||||
expect(text).toMatch(/(?!Commit 1)/gi);
|
||||
}, 20_000);
|
||||
it('should be checkout right commit (复用)', async () => {
|
||||
task.commit = '498c782685';
|
||||
await service.checkout(task, workspaceRoot);
|
||||
task.commit = '7f7123fe5b';
|
||||
await service.checkout(task, workspaceRoot);
|
||||
const filePath = join(workspaceRoot, 'README.md');
|
||||
const text = await readFile(filePath, { encoding: 'utf-8' });
|
||||
expect(text).toMatch(/(?!Commit 1)/gi);
|
||||
}, 30_000);
|
||||
});
|
||||
|
||||
describe('getWorkspaceRootByTask', () => {
|
||||
it('should be return right path', () => {
|
||||
const project = new Project();
|
||||
const pipeline = new Pipeline();
|
||||
const task = new PipelineTask();
|
||||
pipeline.project = project;
|
||||
task.pipeline = pipeline;
|
||||
project.id = 'pid';
|
||||
project.name = 'pname';
|
||||
pipeline.id = 'lid';
|
||||
pipeline.name = 'pipeline/\\-名称';
|
||||
task.id = 'tid';
|
||||
task.commit = '123123hash';
|
||||
|
||||
expect(service.getWorkspaceRootByTask(task)).toMatch(
|
||||
/\/pname\/pipeline%2F%5C-%E5%90%8D%E7%A7%B0-123123hash$/,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user